env.game_wrapper

env.game_wrapper

OpenSpiel backgammon wrapper with perspective-relative board views.

OpenSpiel’s Python bindings for backgammon do not expose direct accessors for bar counts, borne-off counts, or the current dice roll — only for board points. This wrapper therefore parses those fields out of str(state), which is a known-fragile pattern (OpenSpiel makes no stability guarantee on its __str__ format). The parsing is isolated to parse_bar_and_off and parse_dice; if OpenSpiel ever changes formatting, those two functions are the only places that need updating.

Classes

Name Description
BoardView Board state from the current player’s perspective.
GameState Wrapper around an OpenSpiel BackgammonState.
GameWrapper Factory for creating new backgammon games.

BoardView

env.game_wrapper.BoardView(
    my_points,
    opp_points,
    my_bar,
    opp_bar,
    my_off,
    opp_off,
    dice,
    mid_doubles=False,
)

Board state from the current player’s perspective.

All arrays use perspective-relative indexing where point 1 (index 0) is closest to the current player’s bearoff.

GameState

env.game_wrapper.GameState(state)

Wrapper around an OpenSpiel BackgammonState.

Methods

Name Description
board Return the checker count for player at board index index.
board_from_perspective Return the board from the current player’s perspective.
parse_bar_and_off Parse bar and borne-off counts from the state string.
terminal_result Return (equity, result_type) for a terminal state.
board
env.game_wrapper.GameState.board(player, index)

Return the checker count for player at board index index.

OpenSpiel indexes both players’ boards with index i corresponding to standard point 24 - i (i.e. index 0 is point 24, index 23 is point 1). See raccoon/cli/display.py for the point-number layout.

board_from_perspective
env.game_wrapper.GameState.board_from_perspective()

Return the board from the current player’s perspective.

parse_bar_and_off
env.game_wrapper.GameState.parse_bar_and_off(current_player)

Parse bar and borne-off counts from the state string.

terminal_result
env.game_wrapper.GameState.terminal_result()

Return (equity, result_type) for a terminal state.

equity is from player 0’s perspective: +1/+2/+3 or -1/-2/-3. result_type is ‘normal’, ‘gammon’, or ‘backgammon’.

Relies on OpenSpiel being loaded with scoring_type=full_scoring, which makes returns() expose the ±1/±2/±3 multipliers natively.

GameWrapper

env.game_wrapper.GameWrapper()

Factory for creating new backgammon games.

Uses OpenSpiel’s full_scoring mode so state.returns() produces ±1/±2/±3 for normal/gammon/backgammon wins (instead of the default winloss_scoring which flattens everything to ±1). This matches the money-game semantics Raccoon is training for.