Skip to main content
Join the official 2019 Python Developers SurveyStart the survey!

Yahtzee game engine

Project description

Build Status codecov Requirements Status PyPI version PyPI


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)

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)]

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)]


[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:


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.txtfile run the following command:

pip-compile -U --output-file requirements.txt

Pre-commit hooks

This project uses Git pre-commit hooks courtesy of pre-commit. To install run the following:

pre-commit install

Project details

Download files

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

Files for pyhtzee, version 1.2.7
Filename, size File type Python version Upload date Hashes
Filename, size pyhtzee-1.2.7-py3-none-any.whl (11.0 kB) File type Wheel Python version py3 Upload date Hashes View hashes
Filename, size pyhtzee-1.2.7.tar.gz (6.3 kB) File type Source Python version None Upload date Hashes View hashes

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page