PyMonteCarlo is a module that has helper function for monte carlo simulations
Project description
PyMonteCarlo
PyMonteCarlo is a module that has helper function for monte carlo simulations
Getting Started
Installing PyMonteCarlo
pip install (coming soon)
Basics
from PyMonteCarlo.mcs import MonteCarloSimulaterController as mcs
#Flip A Coin. Output between 0 - 1
mcs.flip_a_coin()
#Roll Dice. Output between 1 - 6
mcs.roll_a_dice()
QuickStart Guide
We Will Create A Monte Carlo Simulator On A Rock, Papper, Scissor Game. You Can Find This Game In Examples Folder In PyMonteCarlo Folder
Defining
from PyMonteCarlo import MonteCarloSimulaterController as mcs
controller = mcs.MonteCarloSimulaterController(actions = ["ROCK", "PAPER", "SCISSOR"], #All The Actions
results = ["PLAYER_1_WON", "PLAYER_2_WON", "TIE"]) #All The Results
Create Game Login
def play(player1_move, player2_move):
"""Takes Two Player Input And Decide The Winner"""
players = [player1_move, player2_move]
if player1_move == player2_move:
#They Both Tied
return "TIE"
moves = {"ROCK" : "SCISSOR", #Rock beats scissor
"SCISSOR" : "PAPER",
"PAPER" : "ROCK"}
for player_index in range(len(players)):
player_id = "PLAYER_1_WON" if player_index == 0 else "PLAYER_2_WON"
for move in moves:
if move == players[player_index] and moves[move] == players[1 if player_index == 0 else 0]:
return player_id
Creating Simulation
#The Main Simulations
for _ in range(1000):
player1_action = controller.take_action() #Randomly takes action between rock, paper, scissor
player2_action = controller.take_action()
"""Also You Can Do This
player2_action = controller.take_action(available_actions=["ROCK","PAPER"])
If You Want To Change The Available Outputs
"""
winner = play(player1_action, player2_action)
controller.add_result(winner) #Adds The Result To The Controller
Viewing The Results
print(controller.results_count()) #Returns How Many Times Each Result Occurs
print(controller.max_result(strength=True)) #Returns The Maximum Times Occuring Result With Its Strenght Between 0 - 1. 0 means bad and 1 means amazing.
print(controller.avg_result(strength=True)) #Returns Average Result And Its Strength
print(controller.median_result(strength=True)) #Returns Median Result With Its Strength
"""Output
{'PLAYER_1_WON': 348, 'PLAYER_2_WON': 316, 'TIE': 336}
('PLAYER_1_WON', 0.348)
('TIE', 0.336)
('TIE', 0.336)
"""
Contributing
If you have any suggestion either contact sonicroshan122@gmail or send a pull request
Authors
Roshan Jignesh Mehta - sonicroshan122@gmail
Future
This Features Will Be Added In The Future
- Monte Carlo Tree Search
- Ploting The Monte Carlo Simulation Results And Action
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file MonteCarloPy-0.1.tar.gz.
File metadata
- Download URL: MonteCarloPy-0.1.tar.gz
- Upload date:
- Size: 3.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
60933dc27b77c728e5677e099bafa3cbf69b788093ff6b9efb695815452ecb71
|
|
| MD5 |
5af0a12a6c61b44c12a4b05658aa8708
|
|
| BLAKE2b-256 |
d3841f61fcb7048085df320f6141ea6f161799c018a9cc47cb020ed7e3f5841d
|
File details
Details for the file MonteCarloPy-0.1-py3-none-any.whl.
File metadata
- Download URL: MonteCarloPy-0.1-py3-none-any.whl
- Upload date:
- Size: 3.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8a8579b10c282a144b54da97f8bee89d2d2c1bedc7484c0f741011fe050bd7cc
|
|
| MD5 |
756215d242ce5ce790a17218201e2f6c
|
|
| BLAKE2b-256 |
8428e9d5be23787ad59510605e308e5260981c7e981a2ceff2c471380ae53f9b
|