Skip to main content

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

Metadata

Release files for MonteCarloPy 0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for MonteCarloPy 0.1
File Size Uploaded
MonteCarloPy-0.1.tar.gz 3.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for MonteCarloPy 0.1
File Interpreter ABI Platform
MonteCarloPy-0.1-py3-none-any.whl Python 3 none any Details

Total release size: 7.3 kB

Release files / MonteCarloPy-0.1.tar.gz

Download URL MonteCarloPy-0.1.tar.gz
Size 3.5 kB
Tags Source
SHA-256 checksum
How to use checksums
60933dc27b77c728e5677e099bafa3cbf69b788093ff6b9efb695815452ecb71
BLAKE2b-256 checksum
How to use checksums
d3841f61fcb7048085df320f6141ea6f161799c018a9cc47cb020ed7e3f5841d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / MonteCarloPy-0.1-py3-none-any.whl

Download URL MonteCarloPy-0.1-py3-none-any.whl
Size 3.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
8a8579b10c282a144b54da97f8bee89d2d2c1bedc7484c0f741011fe050bd7cc
BLAKE2b-256 checksum
How to use checksums
8428e9d5be23787ad59510605e308e5260981c7e981a2ceff2c471380ae53f9b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

0.1 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page