Skip to main content

Rummikub solver library

Project description

PyPI version License Python versions supported Built with uv Checked with Ruff Checked with Pyright Built with Material for MkDocs Python checks Coverage

Rummikub Solver library

Fast and flexible Rummikub solver library, written in Python, to find the best options for placing tiles from a player's rack on to the table.

The algorithm used builds on the approach described by D. Den Hertog, P. B. Hulshof (2006), "Solving Rummikub Problems by Integer Linear Programming", The Computer Journal, 49(6), 665-669 (DOI 10.1093/comjnl/bxl033).

Features

  • Can work with different Rummikub variations, letting you adjust the number of colours, tiles, and other aspects
  • You can freely adjust what tiles are on the rack or on the table, within the limits of what tiles are available according to the current rules
  • Can be used with any of the Mixed-Integer Linear Programming (MILP) solvers supported by cvxpy.

Solver improvements

The original models described by Den Hertog and Hulshof assume that all possible sets that meet the minimum length requirements and can't be split up are desirable outcomes.

However, any group set (tiles with the same number but with different colours) containing at least one joker, but which is longer than the minimal run, in effect contains a redundant joker, something you wouldn't want to leave on the table for the next player to use. The same applies to run sets (tiles of the same colour but with consecutive numbers), that are longer than the minimal set length but start or end with a joker. In this implementation, such sets are omitted from the possible options.

The implementation also includes a solver for the initial move, where you can only use tiles from your own rack and must place a minimum amount of points before you can use tiles already on the table. This solver is a variant of the original solver that maximizes tiles placed, but is constrained by the minimal point amount and disregards jokers (which means jokers are only used for the opening meld if that is the only option available).

Documentation

See the project documentation for details.

Install

You can install this project the usual way. e.g. with pip:

$ pip install rummikub-solver

or with uv:

$ uv add rummikub-solver

Picking an alternative solver backend

This library builds on cvxpy to define the Rummikub models, which can then be solved using any of the supported MILP solver backends. By default, the SCIPY backend is used, which in turn uses a version of the HiGHS optimizer that comes bundled with SciPy.

You can also install an alternative Open Source solver backends via extras:

Extra Backend License
cbc COIN-OR Branch-and-Cut solver EPL-2.0
glpk_mi GNU Linear Programming Kit GPL-3.0-only Installs the cvxopt project
highs HiGHS MIT Arguably the best OSS MILP solver available. This installs a newer version of HiGHS than what is bundled with SciPy.
scip SCIP Apache-2.0

You can also pick from a number of commercial solvers; no extras are provided for these:

Refer to their respective documentations for installation instructions.

When HiGHS is installed, it is automatically used as the default solver.

Development

The source code for this project can be found on GitHub.

When running locally, install uv, then run:

$ uv run rsconsole

to run the console solver. A Taskfile is provided that defines specific tasks such as linting, formatting or previewing the documentation:

$ task --list
task: Available tasks for this project:
* default:                     Default task, runs linters and tests
* dev:format:                  Runs formatters      (aliases: format)
* dev:install-precommit:       Install pre-commit into local git checkout
* dev:lint:                    Runs linters      (aliases: lint)
* dev:lint:code:               Lint the source code
* dev:lint:renovate:           Lint the Renovate configuration file
* dev:test:                    Run tests                                          (aliases: test)
* dev:uv-lock:                 Updates the uv lock file                           (aliases: lock)
* dist:build:                  Build the distribution packages                    (aliases: dist)
* dist:clean:                  Remove built distribution packages                 (aliases: clean)
* dist:publish:                Publish package to PyPI                            (aliases: publish)
* docs:build:                  Build project documentation                        (aliases: docs)
* docs:serve:                  Live preview server for project documentation      (aliases: preview)

Credits

The initial version of the solver was written by Ollie Hooper.

This version is a complete rewrite by Martijn Pieters, to improve performance and address shortcomings in the original paper.

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

rummikub_solver-1.0.0.tar.gz (94.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

rummikub_solver-1.0.0-py3-none-any.whl (20.4 kB view details)

Uploaded Python 3

File details

Details for the file rummikub_solver-1.0.0.tar.gz.

File metadata

  • Download URL: rummikub_solver-1.0.0.tar.gz
  • Upload date:
  • Size: 94.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for rummikub_solver-1.0.0.tar.gz
Algorithm Hash digest
SHA256 5b35ae1b3cb1bf9da3b58eb56a5e657b7713b3a263752e3767946e4be1ff54a9
MD5 dc08176512c48430d575ffe026578668
BLAKE2b-256 3b0f0e5bf490076c45be061ce1cafd8a9b3a3529458ed252c3c1fc1458966cbc

See more details on using hashes here.

Provenance

The following attestation bundles were made for rummikub_solver-1.0.0.tar.gz:

Publisher: ci-cd.yml on mjpieters/rummikub-solver

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file rummikub_solver-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for rummikub_solver-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 27ae2bcd275c5186570d4efdc36262712a63aaa34c6609e37550b94ac6a3a6e3
MD5 66e3dadaefc377891093937d4505e8c6
BLAKE2b-256 1407b79a41f7c986f1cf12848ac38cc409e2c344c89083d18164cac6781d902c

See more details on using hashes here.

Provenance

The following attestation bundles were made for rummikub_solver-1.0.0-py3-none-any.whl:

Publisher: ci-cd.yml on mjpieters/rummikub-solver

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

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