Skip to main content

Python3 bindings for GNUBG

Project description

GNUBG

PyPI Downloads Conda Downloads GitHub issues License Stack Overflow

GNUBG Python bindings bring the powerful GNUBG backgammon engine to Python 3.

Quick Start

gnubg is a native Python extension module that wraps the GNU Backgammon engine, so you can call the same position-analysis and cube-decision routines that power the GUI from any Python 3.8–3.13 script or application. It’s ideal for batch processing, data-science workflows, or building custom tools and UIs.

Installation

pip install gnubg

Getting Started

import gnubg

# Load the engine (weights, bear-off tables, etc. are initialized)
gnubg.initnet()

# Convert a position key (20-char A–Z or 14-char Base64) to a board
board = gnubg.boardfromkey("4HPwATDgc/ABMA")

# Evaluate win/gammon/backgammon probabilities and equity at 4 plies
win, gamm, bg, equity = gnubg.probabilities(board, 4)

print(f"Win: {win:.3f}, Gammon: {gamm:.3f}, Backgammon: {bg:.3f}, Equity: {equity:.3f}")

That’s all you need to get up and running! For detailed API docs, advanced build options, and configuration, see the sections below or visit the full documentation on ReadTheDocs.

It provides:

  • Engine initialization & data loading (neural-net weights, opening-book, bear-off tables)
  • Position classification (classify) & public-evaluation best move (pub_best_move)
  • Board ↔ ID conversions (board_from_position_id, board_from_position_key, key_of_board, position_id)
  • Dice utilities (roll) & cube utilities (best_move, pub_eval_score)
  • Bear-off tools (bearoff_id_2_pos, bearoff_probabilities)
  • Legal-move enumeration (moves) & probabilistic evaluation (probabilities)
  • Monte-Carlo rollouts (rollout, cubeful_rollout)
  • Equity lookup (equities.value(xAway, oAway))
  • Runtime engine tuning via the set submodule

🧪 Platform Compatibility

Python Version Linux x86_64
(glibc ≥ 2.17)
Linux i686
(glibc ≥ 2.12)
macOS universal2 Windows x86_64
3.14 ✅ (macOS ≥ 10.14)
3.13 ✅ (macOS ≥ 10.14)
3.12 ✅ (macOS ≥ 10.14)
3.11 ✅ (macOS ≥ 10.9)
3.10 ✅ (macOS ≥ 10.9)

Notes:

  • ✅ = Built and available
  • ❌ = Not built
  • macOS universal2 = Supports both ARM64 and x86-64 architectures

Building on Windows (local)

To reproduce the Windows CI build locally and debug failures:

  1. Install MSYS2 (e.g. from msys2.org), then in an MSYS2 UCRT64 shell install dependencies:

    pacman -S mingw-w64-ucrt-x86_64-gcc mingw-w64-ucrt-x86_64-pkg-config \
      mingw-w64-ucrt-x86_64-glib2 mingw-w64-ucrt-x86_64-gmp \
      mingw-w64-ucrt-x86_64-readline mingw-w64-ucrt-x86_64-sqlite3 \
      mingw-w64-ucrt-x86_64-libpng mingw-w64-ucrt-x86_64-gettext
    
  2. In PowerShell (from the repo root), run the build script (same steps as .github/actions/build-wheel on windows-latest):

    .\scripts\build-windows-local.ps1
    

    This runs meson setup / meson compile only. To also build wheels with cibuildwheel:

    .\scripts\build-windows-local.ps1 -Wheel
    

    If MSYS2 is not in C:\msys64, set $env:MSYS2_ROOT before running (e.g. $env:MSYS2_ROOT = "D:\msys64").

Testing

The gnubg package has basic unit testing. After installation, run:

python3 -m unittest discover -s gnubg.tests

AI-Assisted Development

Parts of this project were developed with the assistance of generative AI tools.

Specifically, the following models were used:

  • GPT-4o (OpenAI ChatGPT)
  • o4-mini-high (OpenAI ChatGPT)

These models were used to assist with code generation, documentation drafting, and architectural guidance. All outputs were reviewed and curated by a human before inclusion.

⚠️ Disclaimer:
Although human-reviewed, some AI-generated content may contain mistakes, inaccuracies, or outdated practices. Contributors and users should critically assess all code, comments, and documentation. We welcome corrections and improvements via pull requests or issues.

Code of Conduct

Please read the Code of Conduct to learn how to interact positively.

Contributing

Your expertise and enthusiasm are welcome! You can contribute by:

  • Reviewing and testing pull requests
  • Reporting and triaging issues
  • Improving documentation, tutorials, and examples
  • Enhancing engine parameters or submodules
  • Maintaining website or branding assets
  • Translating materials
  • Assisting with outreach and onboarding
  • Writing grant proposals or helping with fundraising

For more information, see our Contributing Guide. If you’re unsure where to start, open an issue or join the discussion on our mailing list!

Acknowledgments

This project builds upon the extensive work of the GNU Backgammon (GNUBG) community. Specifically the pygnubg program developed by Joseph Heled.

We express our gratitude to all contributors who have dedicated their time and expertise to the development of GNUBG.

  • AUTHORS.md: A list of primary contributors to the gnubg project can be found here.
  • GNUBG credits.sh: For a comprehensive list of contributors to the core GNUBG project, please refer to the credits.sh file.

We also thank the broader GNUBG community, including testers, translators, and mailing list participants, for their invaluable support.

Project details


Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

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

gnubg-1.1.0a4-cp313-cp313-win_amd64.whl (11.4 MB view details)

Uploaded CPython 3.13Windows x86-64

gnubg-1.1.0a4-cp313-cp313-musllinux_1_2_x86_64.whl (10.4 MB view details)

Uploaded CPython 3.13musllinux: musl 1.2+ x86-64

gnubg-1.1.0a4-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl (9.3 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64manylinux: glibc 2.28+ x86-64

gnubg-1.1.0a4-cp313-cp313-macosx_14_0_arm64.whl (9.7 MB view details)

Uploaded CPython 3.13macOS 14.0+ ARM64

gnubg-1.1.0a4-cp312-cp312-win_amd64.whl (11.4 MB view details)

Uploaded CPython 3.12Windows x86-64

gnubg-1.1.0a4-cp312-cp312-musllinux_1_2_x86_64.whl (10.4 MB view details)

Uploaded CPython 3.12musllinux: musl 1.2+ x86-64

gnubg-1.1.0a4-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl (9.3 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64manylinux: glibc 2.28+ x86-64

gnubg-1.1.0a4-cp312-cp312-macosx_14_0_arm64.whl (9.7 MB view details)

Uploaded CPython 3.12macOS 14.0+ ARM64

gnubg-1.1.0a4-cp311-cp311-win_amd64.whl (11.4 MB view details)

Uploaded CPython 3.11Windows x86-64

gnubg-1.1.0a4-cp311-cp311-musllinux_1_2_x86_64.whl (10.4 MB view details)

Uploaded CPython 3.11musllinux: musl 1.2+ x86-64

gnubg-1.1.0a4-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl (9.3 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64manylinux: glibc 2.28+ x86-64

gnubg-1.1.0a4-cp311-cp311-macosx_14_0_arm64.whl (9.7 MB view details)

Uploaded CPython 3.11macOS 14.0+ ARM64

gnubg-1.1.0a4-cp310-cp310-win_amd64.whl (11.4 MB view details)

Uploaded CPython 3.10Windows x86-64

gnubg-1.1.0a4-cp310-cp310-musllinux_1_2_x86_64.whl (10.4 MB view details)

Uploaded CPython 3.10musllinux: musl 1.2+ x86-64

gnubg-1.1.0a4-cp310-cp310-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl (9.3 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64manylinux: glibc 2.28+ x86-64

gnubg-1.1.0a4-cp310-cp310-macosx_14_0_arm64.whl (9.7 MB view details)

Uploaded CPython 3.10macOS 14.0+ ARM64

File details

Details for the file gnubg-1.1.0a4-cp313-cp313-win_amd64.whl.

File metadata

  • Download URL: gnubg-1.1.0a4-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 11.4 MB
  • Tags: CPython 3.13, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.12

File hashes

Hashes for gnubg-1.1.0a4-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 a5ea3e5572cf501858556a4577b9080263fe37802d8eb5fcb770ccaaf57d7517
MD5 0f249c7754cdff6b71147065af679a09
BLAKE2b-256 ba8cc0e9ac66e83efdbf12eb8666d3bb490a0ad4cac58ce67b4320877ae30da2

See more details on using hashes here.

File details

Details for the file gnubg-1.1.0a4-cp313-cp313-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for gnubg-1.1.0a4-cp313-cp313-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 585392d33f428ead0069438bd1ac960402729b71c4902af51f11b29f126a1bc8
MD5 9e98ab1e302fc2bf3710078950c4fb73
BLAKE2b-256 91b3ee94e0949eb931cd4e937c007fb99ba1c996534be362b3a2c54aa27d7933

See more details on using hashes here.

File details

Details for the file gnubg-1.1.0a4-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for gnubg-1.1.0a4-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 5d823e9a2319f381489ce88e2a2d19f1db3648ce48e6ea04b2c5165748153f52
MD5 a7c1425c6276c873ed291e860eb7a1a5
BLAKE2b-256 8d1bc79977006ddb9c88a60cac8ab7d04fa6f4607ab6ad383856d7240189a3bb

See more details on using hashes here.

File details

Details for the file gnubg-1.1.0a4-cp313-cp313-macosx_14_0_arm64.whl.

File metadata

File hashes

Hashes for gnubg-1.1.0a4-cp313-cp313-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 46ea6d626738f7de9c4cdf6531720c3c1b76816e4dbfdaf7f49ac79cf110fdb5
MD5 523774b73cee78c269a5d0d730dcdfa3
BLAKE2b-256 9a5bc9a28528d03ea12ec914c6a50b533fa5b0b923e9d2b07285dc0987b67360

See more details on using hashes here.

File details

Details for the file gnubg-1.1.0a4-cp312-cp312-win_amd64.whl.

File metadata

  • Download URL: gnubg-1.1.0a4-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 11.4 MB
  • Tags: CPython 3.12, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.12

File hashes

Hashes for gnubg-1.1.0a4-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 46b92588a14f0279cf9fd365339cb9ca77530c01def4be7b4c23e1d20eb10b52
MD5 79f7b87d6f1dcd1bc8e7f934d7f34251
BLAKE2b-256 668e0e201585c947ee1fabb61926982422443fef16b507dd4f98a31df1db8ea7

See more details on using hashes here.

File details

Details for the file gnubg-1.1.0a4-cp312-cp312-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for gnubg-1.1.0a4-cp312-cp312-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 1df03167923dbff894c5103f2d04b2f04d9ab2d1bc5751fbceed626769f5b084
MD5 c85da75b5fc9d90559248a874f0b6a61
BLAKE2b-256 370035ec1ed54528b095485f559536a21cb0650ba1e619b83cfe2276c565f3aa

See more details on using hashes here.

File details

Details for the file gnubg-1.1.0a4-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for gnubg-1.1.0a4-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 babcbf0b54d2ff338ea318f5bc183321d3fd3455206d905706ac7f9a54211ced
MD5 3ef3493c0dcc1118670cfd0102aaf0bd
BLAKE2b-256 38ea0d6ac4c6342112a07290ace45712a8517fa3215875786cc5eeaa8b63dc9e

See more details on using hashes here.

File details

Details for the file gnubg-1.1.0a4-cp312-cp312-macosx_14_0_arm64.whl.

File metadata

File hashes

Hashes for gnubg-1.1.0a4-cp312-cp312-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 3ed955a42d28625e746b6e6aa760a82f6e43d88f9c0eb26c3bfd17069225885e
MD5 f5970d860916614989a5cf2d59ca9048
BLAKE2b-256 f7c9796108b3d3466b2148f0af06aa71a47fd94335eaf12d9adb43cc6372df7b

See more details on using hashes here.

File details

Details for the file gnubg-1.1.0a4-cp311-cp311-win_amd64.whl.

File metadata

  • Download URL: gnubg-1.1.0a4-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 11.4 MB
  • Tags: CPython 3.11, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.12

File hashes

Hashes for gnubg-1.1.0a4-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 1c041ffaf8ca3efd7e19f75bc3d5cde1174f4e1b89537e2ba4449520aa5e3e96
MD5 3b77bad91e8f6f9d3657cce948f8b434
BLAKE2b-256 a66efb37d9acca5b396590fafb67a6b13a8a26de28c3447a271464895bf0c16d

See more details on using hashes here.

File details

Details for the file gnubg-1.1.0a4-cp311-cp311-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for gnubg-1.1.0a4-cp311-cp311-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 98433a94f8c16f8e7d74b63dcd6f64e77e7474aa15e897d8e668d94f0abc85b9
MD5 fd28dd7ebddeb1c8470a28ebc75cfe2d
BLAKE2b-256 a2d809c19fcfabf5893b12b9998cc9352477f9a3c63ef7a23c1ae47718802f3d

See more details on using hashes here.

File details

Details for the file gnubg-1.1.0a4-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for gnubg-1.1.0a4-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 29851285200a483b7d73d0ec6c2794fbcb2439841796f1ed5393be9b3488fff1
MD5 a331cb887f35b7d743f1ac8d405ad790
BLAKE2b-256 db4200654f0b10933c5ad705d851fa9d3b90de3a78f4cd66cf7af938de340210

See more details on using hashes here.

File details

Details for the file gnubg-1.1.0a4-cp311-cp311-macosx_14_0_arm64.whl.

File metadata

File hashes

Hashes for gnubg-1.1.0a4-cp311-cp311-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 56cc265564d239b2d541bad2fdcd2655bc8db0482d2c2dd979d9b3bd9bc485ea
MD5 5300b90c66fd52358745bdc923de04e5
BLAKE2b-256 648781dbcc2f794989713394ec0f731f3f8a9957ec9ff2262f8405f20e93d916

See more details on using hashes here.

File details

Details for the file gnubg-1.1.0a4-cp310-cp310-win_amd64.whl.

File metadata

  • Download URL: gnubg-1.1.0a4-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 11.4 MB
  • Tags: CPython 3.10, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.12

File hashes

Hashes for gnubg-1.1.0a4-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 6e53af4254734fb7316f37dbbc81bd629deacb6528699b73fa22401db063d2ac
MD5 b4cde7578f79b767a1dc755e11acf833
BLAKE2b-256 2e5819dece80a602c0f4b072bd017b527d96c2bfd911bf97561a9c4ffd05cc5c

See more details on using hashes here.

File details

Details for the file gnubg-1.1.0a4-cp310-cp310-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for gnubg-1.1.0a4-cp310-cp310-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 b3e9bd098d4e12a8de591a1f0ab99b03f205dd66d66c5c5840a5be8c2fe66bcf
MD5 b581eb48eab528815988e89f0a217152
BLAKE2b-256 2ef96cadcc09ad4743760bf8ca601c0eaa51fa040ded715e95da680f9e5fc88b

See more details on using hashes here.

File details

Details for the file gnubg-1.1.0a4-cp310-cp310-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for gnubg-1.1.0a4-cp310-cp310-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 3c20cd30bf7574b86bbc5cd58a5eb4a428d913583679deeaf400c8c743e189d7
MD5 14bc564c4b364d260b0e76ef4898f435
BLAKE2b-256 1fc4d283f6e7315607ba0b829aea9ac2ba917deb15e05ca139d9d55b5108fbc8

See more details on using hashes here.

File details

Details for the file gnubg-1.1.0a4-cp310-cp310-macosx_14_0_arm64.whl.

File metadata

File hashes

Hashes for gnubg-1.1.0a4-cp310-cp310-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 f2f5529c0816d9dcbbd4500d2e6b9a14031b81009555405736fbddd80cb6f84d
MD5 148cf519bbaa0f583ebccf57e43e6080
BLAKE2b-256 3b89e8a37ae0ad46cbecca5736430c7a7bec55a9374f368d508fe415b56c85e7

See more details on using hashes here.

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