Skip to content

Monte Carlo Simulator for different board games such as Coin flips , Dice rolls , Roman Alphabet ,Card shuffle and many more.

License

Notifications You must be signed in to change notification settings

brooksideas/monte-carlo-generic-simulator

Repository files navigation

Monte Carlo Simulator

Monte Carlo Simulator for different board games such as Coin flips , Dice rolls , Roman Alphabet ,Card shuffle and many more.

Metadata

Author: Brook Tarekegn Assefa

Net UD: rnc3mm

Project name: Monte Carlo Simulator

Synopsis

Installation

pip install mcgs

Importing

from montecarlo import Die, Game, Analyzer 

Creating fair dice objects all of six sides with the faces 1 through 6

from montecarlo import Die

fair_die_faces = [1, 2, 3, 4, 5, 6]
fair_die = Die(fair_die_faces)

Create fair coin object with faces H and T

from montecarlo import Die

coin_faces = ['H', 'T']
fair_coin = Die(coin_faces)

Playing Games with two six sided dice

from montecarlo import Die, Game

fair_die_faces = [1, 2, 3, 4, 5, 6]
fair_die = Die(fair_die_faces)

# Let us Play a game of 10 rolls with 2 fair dice 
dice = []
dice.extend([fair_die, fair_die])  # Playing a Two Fair dice 
dice_game = Game(dice)
dice_game.show(dice_game.play(10), 1)  # Displaying results in Wide Dataframe format (see API List Table)

Playing Games with two coins

from montecarlo import Die, Game

coin_faces = ['H', 'T']
fair_coin = Die(coin_faces)

# Let us Play a game of 10 rolls with 2 fair coins 
coins = []
coins.extend([fair_coin, fair_coin])
coin_game = Game(coins)
coin_game.show(coin_game.play(10), 1) 

Analyzing games with two six sided dice

from montecarlo import Die, Game, Analyzer

fair_die_faces = [1, 2, 3, 4, 5, 6]
fair_die = Die(fair_die_faces)

# Let us Play a game of 10 rolls with 2 fair dice 
# This is similar for Coins as well
dice = []
dice.extend([fair_die, fair_die])
dice_game = Game(dice)
dice_game.show(dice_game.play(10), 1)

# Let us now analyze the game
dice_analyzer = Analyzer(dice_game)

# Get the face count on each roll event 
dice_analyzer.face_count()

# Get how many times the game resulted in all faces being identical (jackpot)
dice_analyzer.jackpot()

# Compute the distinct/unique combinations of faces rolled along with their counts
dice_analyzer.combo()

# Compute how may sequence types were rolled and their counts
dice_analyzer.permutation()

API description

Class Table

Class Name Method Name Attributes
Die
Methods
init
change_weight
roll_die
show_state
Attributes Description
faces Sides of the dice
weights Value of assigned to a face
faces_weights_df Dataframe of faces and weights
Game
Methods
init
play
show
Attributes Description
dice Die Object List passed from Die class
cols/columns Headers of the play result dataframe
play_df Play result dataframe shape N rolls by M dice
number_of_rolls The number of times games/rolls played
play_result_df_list List form of the play result
Analyzer
Methods
init
face_count
show
jackpot
combo
permutation
Attributes Description
game Game Object passed from Game Class
game_df_data_type Holds the primitive type of the Dataframe
game_result / game_result_df Game result Dataframe shape N rolls by M dice played
face_count_df Face Count result Dataframe shape N rolls by M die faces
face_list List form of the face count result
jackpot_results_df Jackpot result Dataframe shape N of Jackpots rolls by M die faces
jackpot_list List form of the jackpot result
jack_pot_indices Index values of where the Jackpot occurred in result Dataframe
combination_df Combination result as multi-columned Dataframe shape X of N rolls by Y die faces with Z number of occurrence.
combination_list Tuple zipped List form of the Combination result
permutation_df Permutation result as multi-columned Dataframe shape X of N rolls by Y die faces with Z number of occurrence.
permutation_list Tuple zipped List form of the Permutation result

Method Table

Method Name Description Docs Parameters Return values Snapshots
change_weight Change the weight of a single side/face
Data types Defaults
Face Value integer,string,float integer(1)
string("")
float (1.0)
New Weight integer,string,float 1.0
Assigns a dataframe (integer,string or float ) with faces and the newly assigned weights. Changed Weights
roll_die Roll the die one or more times
Data types Defaults
Number of rolls integer 1
Return a list of outcomes similar to the face types (integer,string or float ). Roll Die
show_state Show the die’s current set of faces and weights Takes no argument Returns the dataframe according to the face types (integer,string or float ). Show State
play Rolls the Dice using the inherited roll_die method from the Die class
Data types Defaults
Number of Rolls integer 1
Returns the results of the play as a dataframe of shape N rolls by M dice. Play Game
show Show the results of the most recent play
Data types Defaults
Play Result DataFrame pd.DataFrame()
DataFrame table Form
integer
Wide (1) or Narrow(2)
1
Display the result of the latest play result as a dataframe of shape N rolls by M dice. Show Game
face_count Method to compute how many times a given face is rolled in each event Takes no arguments Returns the count for each face displayed according to the initial dice face sides given as a dataframe of shape N rolls by M dice. See how the above row show dataframe is displayed by face_count dataframe. Face Count
jackpot Method to compute how many times the game resulted in all faces being identical Takes no arguments Returns the count of how many times the game resulted in all faces being identical. You can also access the Jackpot Dataframe using Analyzer Object.jackpot_results_df. Jackpot Result Jackpot Result Dataframe
combo Method to compute the distinct/unique combinations of faces rolled, along with their counts Takes no arguments Returns the count of how many times the Game could result in distinct/unique combinations of faces when dice is played/rolled. You can also access the full combination multi-columned Dataframe using Analyzer Object.combination_df. Combo Result Highlighted Dataframe Combo Result Dataframe
permutation Method to compute how may sequence types were rolled and their counts Takes no arguments Returns the count of all the possible combinations of faces present when dice is played/rolled. You can also access the permutation multi-columned Dataframe using Analyzer Object.permutation_df. Permutation Result Header Dataframe Permutation Result Dataframe

About

Monte Carlo Simulator for different board games such as Coin flips , Dice rolls , Roman Alphabet ,Card shuffle and many more.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published