Skip to main content

Library for running blackjack simulations

Project description

PyPI version fury.io PyPi downloads Maintenance

Blackjack

py21 is a blackjack simulator. Users can run the simulation using the default rules or specify their own. Additionally, users can test their own playing and betting strategies.

Installation

Right now py21 can be installed from source or PyPI.

To download from source, clone or download this repository, then navigate to the directory you cloned to and run pip install -e ..

To download from PyPI, use pip install py21

Using py21

To run the simulator, the user must initiate one instance of the Game class and at least one instance of the Player class.

The Player class requires one input, bankroll, and has three optional inputs: strategy_func, wager_func, and insurance_func.

bankroll should be an numerical value indicating the bankroll the player will be starting with.

strategy_func should be a function that will return what action the player will take in a given situation. This function can take as inputs a number of variables containing information about the game such as the player's hand, dealer's up card, and the count. It must return one of the following: HIT, STAND, SPLIT, DOUBLE.

wager_func should be a function that will determine how much the player will wager in a hand. Like the function used for strategy_func it can take as arguments variables on the status of the game. It must return a number that is within the minimum and maximum bets allowed, and no more than the player's bankroll.

insurance_func should be a function that will determine if a player takes insurance when the dealer is showing an ace. It must return True or False.

The Game class has one required argument and two optional ones. players is a list of instances of the Players class that will be used in the game. rules can be a dictionary containing changes to the game's default rules to run the simulation under different scenarios. An explanation of how the dictionary should be structured is below. Finally, verbose is a boolean indicator for whether or not you want information printed out as the game is played.

Running a simulation can be done in a few lines of code:

from py21 import Game, Player

# initiate Player object
player = Player(100)
# initiate Game object
game = Game([player])

# run simulation 1,000,000 times
game.simulate(1000000)

Updating Game Parameters

To update a rule in the game, use this dictionary format:

{param: new_rule}

For example, here is how to change the blackjack payout from 3:2 to 6:5:

from py21 import Game, Player

rules = {"blackjack_payout": 1.2}

player = Player(100)
game = Game([player], rules)

game.simulate(1000000)

A list of the game parameters you can update can be found here.

As of version 1.6.0, there is also a CLI for py21. To use it, run blackjack from the command line.

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

py21-1.6.0.tar.gz (20.9 kB view details)

Uploaded Source

Built Distribution

py21-1.6.0-py3-none-any.whl (22.8 kB view details)

Uploaded Python 3

File details

Details for the file py21-1.6.0.tar.gz.

File metadata

  • Download URL: py21-1.6.0.tar.gz
  • Upload date:
  • Size: 20.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.2 CPython/3.9.6

File hashes

Hashes for py21-1.6.0.tar.gz
Algorithm Hash digest
SHA256 2a4a0811af4c990bacade2e800e3551c64d153fff35603e71ec9a9bf48b2f4a1
MD5 824d591911aeff591988b73c2265bba3
BLAKE2b-256 fbf019a4d3f3e37a17d337e23df579abdeb6c7d237acc7ff226a88f602f30876

See more details on using hashes here.

File details

Details for the file py21-1.6.0-py3-none-any.whl.

File metadata

  • Download URL: py21-1.6.0-py3-none-any.whl
  • Upload date:
  • Size: 22.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.2 CPython/3.9.6

File hashes

Hashes for py21-1.6.0-py3-none-any.whl
Algorithm Hash digest
SHA256 83edea0a5275e087efb8ec0976cb7ea629e42eba5cb57aa53fc2e0acb4b4eb54
MD5 3abd95ce9adb260de6b1562d5e095bad
BLAKE2b-256 9afa20b30c63c71abb0da5e5cbd3bf1588815a9c0117b9271d529c399850c11b

See more details on using hashes here.

Supported by

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