Skip to main content

Python3 bindings for GNUBG neural evaluation

Project description

GNUBG Neural Networks

PyPI Downloads Build & test wheels C/C++ Lint Branch naming Release to PyPI GitHub issues License Stack Overflow

GNUBG Neural Networks (this package, gnubg-nn) is a library that provides Python bindings to the GNUBG neural-network evaluation engine — the same engine used for position analysis and cube decisions in the full GNU Backgammon application, but packaged as a standalone library for use in scripts, analysis tools, and applications. It is not the full backgammon game (GUI, match play, etc.).

Quick Start

gnubg_nn is a native Python extension module that wraps the GNUBG neural-net evaluation library, so you can call the same position-analysis and cube-decision routines that power the full GNU Backgammon application from any Python 3.10+ script or application. It’s ideal for batch processing, data-science workflows, or building custom tools and UIs.

Installation

Important: The PyPI package name is gnubg-nn, not gnubg. Installing gnubg will install the unrelated full GNU Backgammon application. The correct command is:

pip install gnubg-nn

Then import it as:

import gnubg_nn

Note: The engine (neural-network weights, bear-off tables, etc.) initialises automatically on import — you do not need to call initnet().

Getting Started

import gnubg_nn

# Convert a 14-char Base64 Position ID to a 2x25 board
board = gnubg_nn.board_from_position_id("4HPwATDgc/ABMA")

# Evaluate win/gammon/backgammon probabilities at 2 plies
probs = gnubg_nn.probabilities(board, gnubg_nn.p_0plus1)
win, win_gammon, win_bg, lose_gammon, lose_bg = probs

print(f"Win: {win:.3f}, Gammon: {win_gammon:.3f}, Backgammon: {win_bg:.3f}")

# Find the best move for an opening 6-5 roll
moves = gnubg_nn.moves(board, 6, 5)
best = gnubg_nn.best_move(board, 6, 5)
print(f"Best move key: {best}")

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

Testing

gnubg-nn-pypi has some basic unit testing. After installation, run:

python3 -m unittest discover -s gnubg_nn.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. The gnubg-nn library is the neural network evaluation component; the full backgammon application (GUI, match play, etc.) is maintained separately. We specifically acknowledge 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 the GNUBG neural network library and its Python bindings.

  • AUTHORS.md: A list of primary contributors to the gnubg-nn-pypi project can be found here.
  • GNU Backgammon (full project) credits.sh: For a comprehensive list of contributors to the full GNUBG application, 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_nn-1.1.0a8-cp313-cp313-win_amd64.whl (9.3 MB view details)

Uploaded CPython 3.13Windows x86-64

gnubg_nn-1.1.0a8-cp313-cp313-musllinux_1_2_x86_64.whl (9.5 MB view details)

Uploaded CPython 3.13musllinux: musl 1.2+ x86-64

gnubg_nn-1.1.0a8-cp313-cp313-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl (8.4 MB view details)

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

gnubg_nn-1.1.0a8-cp313-cp313-macosx_11_0_arm64.whl (8.4 MB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

gnubg_nn-1.1.0a8-cp312-cp312-win_amd64.whl (9.3 MB view details)

Uploaded CPython 3.12Windows x86-64

gnubg_nn-1.1.0a8-cp312-cp312-musllinux_1_2_x86_64.whl (9.5 MB view details)

Uploaded CPython 3.12musllinux: musl 1.2+ x86-64

gnubg_nn-1.1.0a8-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl (8.4 MB view details)

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

gnubg_nn-1.1.0a8-cp312-cp312-macosx_11_0_arm64.whl (8.4 MB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

gnubg_nn-1.1.0a8-cp311-cp311-win_amd64.whl (9.3 MB view details)

Uploaded CPython 3.11Windows x86-64

gnubg_nn-1.1.0a8-cp311-cp311-musllinux_1_2_x86_64.whl (9.5 MB view details)

Uploaded CPython 3.11musllinux: musl 1.2+ x86-64

gnubg_nn-1.1.0a8-cp311-cp311-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl (8.4 MB view details)

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

gnubg_nn-1.1.0a8-cp311-cp311-macosx_11_0_arm64.whl (8.4 MB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

gnubg_nn-1.1.0a8-cp310-cp310-win_amd64.whl (9.3 MB view details)

Uploaded CPython 3.10Windows x86-64

gnubg_nn-1.1.0a8-cp310-cp310-musllinux_1_2_x86_64.whl (9.5 MB view details)

Uploaded CPython 3.10musllinux: musl 1.2+ x86-64

gnubg_nn-1.1.0a8-cp310-cp310-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl (8.4 MB view details)

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

gnubg_nn-1.1.0a8-cp310-cp310-macosx_11_0_arm64.whl (8.4 MB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

File details

Details for the file gnubg_nn-1.1.0a8-cp313-cp313-win_amd64.whl.

File metadata

  • Download URL: gnubg_nn-1.1.0a8-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 9.3 MB
  • Tags: CPython 3.13, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.13

File hashes

Hashes for gnubg_nn-1.1.0a8-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 223c79babe82ba335701d610592f545ec2b317af4462830627e4920f56e1481c
MD5 d2b00292acd767bc1cdf5550e4d0ed34
BLAKE2b-256 491a3fba3012dfc462c04f8fd8546eb04340ae54c9f2366f8c6615d11c41a085

See more details on using hashes here.

File details

Details for the file gnubg_nn-1.1.0a8-cp313-cp313-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for gnubg_nn-1.1.0a8-cp313-cp313-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 638751216016f34ae5c6d85d557259b351964e97f48df3fa8fdbf9ab67da95f9
MD5 0eb285b79f93c956f92bc1d0f1ea9000
BLAKE2b-256 40804b15b75aad7d8f6b8cb4b1374351171ee0b86605843354447c8c464dd679

See more details on using hashes here.

File details

Details for the file gnubg_nn-1.1.0a8-cp313-cp313-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for gnubg_nn-1.1.0a8-cp313-cp313-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 e45af0c7af77fa4a8b5a450955c7e926dc58da3c5aacb81b729adc9cd530d98f
MD5 b583caedf0ee38b48b3df1da1c32f632
BLAKE2b-256 ae5fe6234fcbfd5725f01d07e0b28f12d444999d0a8be03b664b07a9e52206a3

See more details on using hashes here.

File details

Details for the file gnubg_nn-1.1.0a8-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for gnubg_nn-1.1.0a8-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 279723a1a21850e4f5a4136598dfa7de5324e33ba382a8250a13160c7ee54547
MD5 1590b799604ebc9ee3f7c94e1630456c
BLAKE2b-256 82d3b2c3780fd43c94cd19b2afb96f13b3f854e21714db63012e8ad7f2ab8448

See more details on using hashes here.

File details

Details for the file gnubg_nn-1.1.0a8-cp312-cp312-win_amd64.whl.

File metadata

  • Download URL: gnubg_nn-1.1.0a8-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 9.3 MB
  • Tags: CPython 3.12, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.13

File hashes

Hashes for gnubg_nn-1.1.0a8-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 4eea763175a8adbfcb0272b090347ff014141950ffa5c9edd62d38662fab6ddc
MD5 c3d812b598591bf3bae716e4007f0dd0
BLAKE2b-256 555e0a9a83a3403cdfefaed9927e72f70cc42514f28428bc6a204e9aede9daf1

See more details on using hashes here.

File details

Details for the file gnubg_nn-1.1.0a8-cp312-cp312-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for gnubg_nn-1.1.0a8-cp312-cp312-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 39f5570acd5456880290684f9d6c42fba5c38f74553bf228d4d5112367de4abf
MD5 2f63566da337f66c27f57f30e2097e99
BLAKE2b-256 93bfeb83ae10473a3b33af8eac7566ceaeea081ab3df3f39882f21ad8d65edde

See more details on using hashes here.

File details

Details for the file gnubg_nn-1.1.0a8-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for gnubg_nn-1.1.0a8-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 55547851cd1bad0c783d58cb1433cf53d844cfb4a7ca97b4301aacb1981a2c91
MD5 083a3004f826039eabfc7cd62b99b1f6
BLAKE2b-256 6dd12bf2e7ae96bd91dd6171469b1a8642683dff37a3008e8afe389f88729da2

See more details on using hashes here.

File details

Details for the file gnubg_nn-1.1.0a8-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for gnubg_nn-1.1.0a8-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 ecb7b0ecafd4dafb214b3b3cd02ef3313ac34b46e98c6e4e93b235e75465a798
MD5 b08d242af396c0befc453665485b25d9
BLAKE2b-256 e24b0e901ad563bbe04762f116285d06ac5ef0996c4dc4999618ef4a323a315a

See more details on using hashes here.

File details

Details for the file gnubg_nn-1.1.0a8-cp311-cp311-win_amd64.whl.

File metadata

  • Download URL: gnubg_nn-1.1.0a8-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 9.3 MB
  • Tags: CPython 3.11, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.13

File hashes

Hashes for gnubg_nn-1.1.0a8-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 17f59917c54715720297a311bc3f158ee122dd255e6a4e74054140ad7a9ec188
MD5 b60f795283b6f5933e47326b6aaa9431
BLAKE2b-256 7f14b55f4ca21dcb5b0d8eb4eaa3ae3a4484fa34c962e7d012c6562ce1ecee92

See more details on using hashes here.

File details

Details for the file gnubg_nn-1.1.0a8-cp311-cp311-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for gnubg_nn-1.1.0a8-cp311-cp311-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 e9e52df21ac89b76fd0fd5a665b30dede96c5a73c5224ca3541751eed7631027
MD5 110cfcb45ef503af03130c3587ecf22e
BLAKE2b-256 709e98a2280ae3c656c0b6bdb25cd5639732594bd4823ec5c5720fa57a161830

See more details on using hashes here.

File details

Details for the file gnubg_nn-1.1.0a8-cp311-cp311-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for gnubg_nn-1.1.0a8-cp311-cp311-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 87c32c675889acec5a03b9be36b5bde16af8ec7f1dff5d0739f13238aa929d1a
MD5 9b1cdc6225d4dc2b1858ea07e629ef2d
BLAKE2b-256 c6df55568cbd8b0aac058d5e63201e7d47f75680b1640da293771a76a72d2367

See more details on using hashes here.

File details

Details for the file gnubg_nn-1.1.0a8-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for gnubg_nn-1.1.0a8-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 339594cfc446d571ef6953c6f7b1725f1e62a4d162447a1f5ae5a80dfc5109c4
MD5 9a067ab4a44bb74637a8026e42ea2b23
BLAKE2b-256 92c7dbb0b25ad8b625c98c09c37a4e2f41a4ce000e5e99b6a5cf674376a1fd53

See more details on using hashes here.

File details

Details for the file gnubg_nn-1.1.0a8-cp310-cp310-win_amd64.whl.

File metadata

  • Download URL: gnubg_nn-1.1.0a8-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 9.3 MB
  • Tags: CPython 3.10, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.13

File hashes

Hashes for gnubg_nn-1.1.0a8-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 395f8098b126cd90d0bef0560d2b9690b1cb0e204560ba18e6e782f04060669c
MD5 10648d3327c65e3ef91faacf0aac609d
BLAKE2b-256 9eded8529b79b3bc7fc097746be5692f1340f50751f84b53cb2d1a86741d6ac1

See more details on using hashes here.

File details

Details for the file gnubg_nn-1.1.0a8-cp310-cp310-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for gnubg_nn-1.1.0a8-cp310-cp310-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 d5185a853b1c9851930f0f9120200ec4c2241cac4df1fbf7bcd6516104b96f82
MD5 a26c0cadcbe03fcf060eb0619f3f345b
BLAKE2b-256 913d9b46d9705e999895294df338452bffe695110a8c0d166c87b32880c48552

See more details on using hashes here.

File details

Details for the file gnubg_nn-1.1.0a8-cp310-cp310-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for gnubg_nn-1.1.0a8-cp310-cp310-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 a1ab8e507d51aa6e49d5d9524759d7cc50b4f17a332790ccb443b87bb7d7ad08
MD5 57192324421a736df874afa8e0e127ae
BLAKE2b-256 911948ee8d1a4ff3f95708c3c2ea915c6b88feef53ba79273f3d774c8f30e8b7

See more details on using hashes here.

File details

Details for the file gnubg_nn-1.1.0a8-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for gnubg_nn-1.1.0a8-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 994cf91ab26f75012b068db47bf1ffe999d88d2eec965c96bb5de6fadcbacad5
MD5 75d35612d3c2937cb4b3b442617fa995
BLAKE2b-256 2f07627423ce71db9da683a099e8e6bcde9d068cebcf83ccd1a5fe2d32fdef8a

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