Nard Game (Backgammon)
Classic board game of Nard (Backgammon) for two players.
Common rules
- Players: the game is played by two players
- Tables board of 24 points or spaces; 2 dice; 30 pieces (15 per player)
- Both players throw a die to decide who plays first; the one with the higher die leads off
- Bearing off:
- Begins once all 15 pieces are in the home quadrant
- One piece is removed from the point corresponding to the roll of each die
- If there are no piece on the point corresponding to a die roll, the player must make a legal move with a piece further away
- If that is not possible, a piece is borne off from the furthest point that is occupied.
Usage
Playing
from nard_backgammon import (
Nard,
NardState,
Player,
get_random_move,
board_to_str)
# If the first_player is None, then the starting
# player is found on the first roll `first_roll()`
game = Nard.new(first_roll_player=Player.WHITE)
while True:
match game.state:
# If first_roll_player is None then
# NardState is will be FIRST_ROLL at the init
case NardState.FIRST_ROLL:
game.first_roll()
case NardState.PLAYING:
# get valid moves for active player
moves = game.get_valid_moves()
if not moves:
game.skip()
continue
move = get_random_move(moves)
game.play_move(move)
print(board_to_str(game))
case NardState.ENDED:
print(f'Winner: {game.outcome.winner}')
break # End game, exit the loop
Output
...
||12-11-10-9--8--7-||6--5--4--3--2--1-||
||o o x x x || ||
||2 2 7 2 || ||
|| || || White off: 0
|| || || Black off: 4
|| || || Dices: (4, 3)
|| 2 || 4 3 ||
|| o o || o o o o ||
||13-14-15-16-17-18||19-20-21-22-23-24||
...
Winner: Player.WHITE
Metadata
Release files for nard-backgammon 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| nard_backgammon-0.1.0.tar.gz | 7.9 kB | Without provenance | Details for nard_backgammon-0.1.0.tar.gz |
Release files / nard_backgammon-0.1.0.tar.gz
| Download URL | nard_backgammon-0.1.0.tar.gz |
|---|---|
| Size | 7.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
be2b7eaf64aec299fd7bad4f916891c069ec591b24469597c5b2666b2951fa8c
|
|
BLAKE2b-256 checksum How to use checksums |
200a20f34aa5162e9a620ddec2fa58c56bc0eca0c4674f52450fbd313698b710
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.1
|
Security for nard-backgammon 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.