Yahtzee game engine
Project description
pyhtzee
Yahtzee game engine supporting regular Yahtzee rules (maximum 1480), Joker rules (maximum 1575) and Yatzy aka. Scandinavian Yahtzee rules (maximum 305). Example code:
from pyhtzee import Pyhtzee
from pyhtzee.classes import Category, Rule
from pyhtzee.utils import category_to_action_map, dice_roll_to_action_map
pyhtzee = Pyhtzee(rule=Rule.FREE_CHOICE_JOKER)
print(pyhtzee.dice)
This shows the dice:
[2, 5, 6, 1, 6]
Next reroll dice 1, 2 and 5:
action = dice_roll_to_action_map[(True, True, False, False, True)]
pyhtzee.take_action(action)
print(pyhtzee.dice)
Now we have two pairs:
[4, 6, 6, 1, 1]
Let's reroll just the first die to see if we can get a full house:
action = dice_roll_to_action_map[(True, False, False, False, False)]
pyhtzee.take_action(action)
print(pyhtzee.dice)
Bingo!
[6, 6, 6, 1, 1]
Now let's choose the action for full house and check the scorecard:
action = category_to_action_map[Category.FULL_HOUSE]
reward = pyhtzee.take_action(action)
print(f'Reward: {reward}, Scorecard: {pyhtzee.scores}')
This shows that we got a reward of 25, which can be confirmed in the scorecard:
Reward: 25, Scorecard: {<Category.FULL_HOUSE: 8>: 25}
Developers guide
Pipenv is recommended for setting up a development environment. Prior to installing
pipenv
, creating a .env
file with the following contents is recommended:
PYTHONPATH=.
To install pipenv and the required dependencies run the following commands:
pip install pipenv
pipenv install -r requirements.txt
pipenv shell
Updating dependencies
requirements.txt
is dynamically generated using pip-compile
. To regenerate the
requirements.txt
file run the following command:
pip-compile -U --output-file requirements.txt setup.py requirements-dev.in
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
File details
Details for the file pyhtzee-1.2.5.tar.gz
.
File metadata
- Download URL: pyhtzee-1.2.5.tar.gz
- Upload date:
- Size: 6.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.12.1 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.7.2 requests-toolbelt/0.9.1 tqdm/4.30.0 CPython/3.7.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e1e6b0461bea2d47a96253db792f25179fde99596fce31b03b0e509bcbb273e5 |
|
MD5 | b3d4e2b933997b228bd8fb621c106df8 |
|
BLAKE2b-256 | ae0e2a54357e7e4c150f7ef2b8c4edb3a375c4e456bf38d1edc973d7a9e1c415 |
File details
Details for the file pyhtzee-1.2.5-py3-none-any.whl
.
File metadata
- Download URL: pyhtzee-1.2.5-py3-none-any.whl
- Upload date:
- Size: 10.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.12.1 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.7.2 requests-toolbelt/0.9.1 tqdm/4.30.0 CPython/3.7.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0e569d2d61f8f155a91e425d0ae7a99527a6a32b8a7adc1cd5914d45e2a28b09 |
|
MD5 | c9c6a4b86ea248cea64debbfcc67e6d9 |
|
BLAKE2b-256 | b954f1ed249f59b014a7c6b097ae4e1190fb5529858be7201eb98e4420473def |