Skip to main content

🎲 generala

CI Ruff uv Publish PyPI PyPI - Python Version

generala is a probabilistic tool for the dice game of Generala.

generala helps you decide which dice to hold after each roll. Starting from the dice you have, the tool considers all possible future rolls to find which combinations of held dice give the best expected scores for the different categories.

The categories and scores in the tool correspond to the variant of the game played in my family. As there are many variants of the game—each of which assigns scores to the categories differently—you may want to check out the generala.categories module and modify it as desired.

Installation

generala is available as a Python package on PyPI. Assuming you have Python 3.9 or later, install it by running the command:

$ pip install generala

or:

$ python3 -m pip install generala

Usage

Command-line usage

Suppose we got the dice (4,4,1,2,6) on the first roll in a game. Run generala as:

$ generala 1 44126

or, alternatively:

$ python3 -m generala 1 44126

The program responds with the best expected scores for each category. The third column ("Hold dice") tells us which dice we should hold for the expected score to apply. The final row ("any") looks to maximize the overall expected score irrespective of category.

Computing. This may take a few seconds....
   Category    Expected score Hold dice
      1s             2.22     1
      2s             4.44     2
      3s             4.58     none
      4s            11.67     44
      5s             7.64     none
      6s            13.33     6
   Straight          5.52     24
  Full house        13.47     44
Four of a kind      17.18     44
   Generala          2.91     44
Double Generala      0.00     any
      any           33.15     44

Let's say we kept (4,4) and got (5,4,3) on the second roll. We run generala again:

$ generala 2 44543

The tool outputs:

   Category    Expected score Hold dice
      1s             0.83     none
      2s             1.67     none
      3s             5.00     3
      4s            13.33     444
      5s             8.33     5
      6s             5.00     none
   Straight          3.33     345
  Full house         8.33     4445 or 3444
Four of a kind      22.22     444
   Generala          2.78     444
Double Generala      0.00     any
      any           38.61     444

After the third and final roll, the tool can give the final scores. Assuming we have the dice (4,4,4,3,2):

$ generala 3 44432
   Category      Score   
      1s            0
      2s            2
      3s            3
      4s           12
      5s            0
      6s            0
   Straight         0
  Full house        0
Four of a kind      0
   Generala         0
Double Generala     0
      any          12

Closed categories

You can also specify, via options, which categories are closed (i.e., no longer available for scoring). For example, with:

$ generala -46fpg 1 44126

we tell the tool that the categories 4s, 6s, Full house, Four of a kind, and Generala are closed—which results in those categories not being considered in the computation:

   Category    Expected score Hold dice
      1s             2.22     1
      2s             4.44     2
      3s             4.58     none
      5s             7.64     none
   Straight          5.52     24
Double Generala      5.81     44
      any           12.00     44

For a list of all available options, run:

$ generala --help

As a Python library

It is also possible to call into the functionality from a Python program. Here's an example.

from generala import counts, dice
from generala.categories import STRAIGHT, ALL

c = counts((4,4,1,2,6))

score, held = STRAIGHT.expected_score(counts=c, roll=1, open_categories=ALL, return_held=True)

print(f"Hold dice {dice(held[0])}. Expected score: {score:.2f}")

When run, that snippet will print:

Hold dice (2, 4). Expected score: 5.52

That's all. Good luck!

Metadata

Release files for generala 2.0.0

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

Source distribution (sdist)

Source distribution for generala 2.0.0
File Size Uploaded
generala-2.0.0.tar.gz 6.7 kB Details

Built distribution (wheel)

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

Total release size: 14.3 kB

Release files / generala-2.0.0.tar.gz

Download URL generala-2.0.0.tar.gz
Size 6.7 kB
Tags Source
SHA-256 checksum
How to use checksums
6b1281be5dad0c289a3789bbb0775773a0467705331edd415c7b61141ebfc68d
BLAKE2b-256 checksum
How to use checksums
6a56cba19e6481adc7bfad87059505f37ddcaff2db0dc9077c2306d67bf5b23e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.5.4

Release files / generala-2.0.0-py3-none-any.whl

Download URL generala-2.0.0-py3-none-any.whl
Size 7.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
966ce0b4c5a1b84df4456c612f0cb14a469a0d1df553be75ed9e6cafa3eee08f
BLAKE2b-256 checksum
How to use checksums
57de1a4cdb96b7cf108e6f868a5bc6226a3931e1565e10c9b16eee0aface63f0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.5.4

Release history Release notifications | RSS feed

This release

2.0.0 This release

2 release files

1.1.0

2 release files

1.0.1

1 release file

1.0.0

1 release file

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