Interface

pygammon.run(receive_input: Callable[[Side], Tuple[InputType, Tuple[int, int | None] | None]], send_output: SendOutputCallable, move_by_turn_rolls: bool = False) None

Start a game, using given callables for player input and output.

Parameters:
  • receive_input – Callable receiving player input

  • send_output – Callable sending player output

  • move_by_turn_rolls – Whether the starting player should move by the turn-deciding die rolls, on their first turn

class pygammon.Side(value)

Bases: IntEnum

Playing side

FIRST = 0
SECOND = 1
class pygammon.structures.Point(side: Side | None = None, count: int = 0)

Bases: object

Board point data

side: Side | None = None
count: int = 0
class pygammon.GameState(board: List[Point], first_hit: int, first_borne: int, second_hit: int, second_borne: int)

Bases: tuple

Game state data

board: List[Point]

The game board

first_hit: int

Count of first player’s pieces that have been hit

first_borne: int

Count of pieces first player has borne off

second_hit: int

Count of second player’s pieces that have been hit

second_borne: int

Count of pieces second player has borne off

class pygammon.InputType(value)

Bases: Enum

Reason to receive input

MOVE = 0
UNDO = 1
class pygammon.OutputType(value)

Bases: Enum

Reason to send output

GAME_STATE = 0
TURN_ROLLS = 1
MOVE_ROLLS = 2
INVALID_MOVE = 3
GAME_WON = 4
class pygammon.structures.DieRolls(first: int, second: int)

Bases: tuple

Two die rolls

first: int

First die roll

second: int

Second die roll

class pygammon.InvalidMoveCode(value)

Bases: Enum

Invalid move error codes

DIE_INDEX_INVALID = 0
SOURCE_INVALID = 1
SOURCE_NOT_OWNED_PIECE = 2
DESTINATION_OUT_OF_BOARD = 3
DESTINATION_OCCUPIED = 4
INVALID_MOVE_TYPE = 5
NOTHING_TO_UNDO = 6
INVALID_INPUT_TYPE = 7
class pygammon.structures.SendOutputCallable(*args, **kwargs)

Bases: Protocol

__call__(output_type: OutputType, data: GameState | Tuple[int, int] | InvalidMoveCode | Side, /, side: Side | None = None) None

Call self as a function.