Skip to main content

Yahtzee game engine

Project description

Build Status codecov Requirements Status PyPI version PyPI

pyhtzee

Yahtzee game engine supporting regular Yahtzee rules (maximum 1480), Joker rules (maximum 1575) and Yazty 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.txtfile run the following command:

pip-compile -U --output-file requirements.txt setup.py requirements-dev.in

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

pyhtzee-1.2.0.tar.gz (6.0 kB view details)

Uploaded Source

Built Distribution

pyhtzee-1.2.0-py3-none-any.whl (10.3 kB view details)

Uploaded Python 3

File details

Details for the file pyhtzee-1.2.0.tar.gz.

File metadata

  • Download URL: pyhtzee-1.2.0.tar.gz
  • Upload date:
  • Size: 6.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.20.0 setuptools/40.5.0 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.6.4

File hashes

Hashes for pyhtzee-1.2.0.tar.gz
Algorithm Hash digest
SHA256 e3b85d14ee79192dc1d21d5b04d9ccc7b39d27176f5e14a93dba682784150b84
MD5 755f82a8c16e6438f681fc3e2cb5deb1
BLAKE2b-256 f4751e982a64366287830cfd9c860236267d287d652b143a48daaa8dedeab155

See more details on using hashes here.

Provenance

File details

Details for the file pyhtzee-1.2.0-py3-none-any.whl.

File metadata

  • Download URL: pyhtzee-1.2.0-py3-none-any.whl
  • Upload date:
  • Size: 10.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.20.0 setuptools/40.5.0 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.6.4

File hashes

Hashes for pyhtzee-1.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8c39856d1bf291049b9dcd2b2c2b4712cd0cca1f624b259adc1794c2c13db411
MD5 9c4cca4d8c304ec1473d0de5f3d7fc0a
BLAKE2b-256 240f80a1f942cab7178e644b29020afb4bbc201075488dc35c6614fea36b1692

See more details on using hashes here.

Provenance

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