Skip to main content

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

Project description

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

Montecarlo Simulator Demonstration

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mcgs-0.0.3.tar.gz (60.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mcgs-0.0.3-py3-none-any.whl (4.9 kB view details)

Uploaded Python 3

File details

Details for the file mcgs-0.0.3.tar.gz.

File metadata

  • Download URL: mcgs-0.0.3.tar.gz
  • Upload date:
  • Size: 60.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.8.10

File hashes

Hashes for mcgs-0.0.3.tar.gz
Algorithm Hash digest
SHA256 13a90c357bfe5a74f693732029fb63ee90cb3f37c5187e649cb183dfb5ea8e1b
MD5 470c319ba33eef776fab2d6be3d0a951
BLAKE2b-256 752b7543b4f7c1cee96f6be238d7e28710b26508c484e3a57b42a079749a9be5

See more details on using hashes here.

File details

Details for the file mcgs-0.0.3-py3-none-any.whl.

File metadata

  • Download URL: mcgs-0.0.3-py3-none-any.whl
  • Upload date:
  • Size: 4.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.8.10

File hashes

Hashes for mcgs-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 1d63582dfeb98b191f37d7a51816dd419660a083592dfd2bcc1a78f8d0131998
MD5 af31f26fc9d562c1c679594b24f98836
BLAKE2b-256 aae7382b88adbf153bf5c2a8b972041df992c77f2628ab0cea88d6c2e1098caf

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page