games.nim.standalone_game¶

Standalone game implementation of Nim.

This script allows playing Nim without requiring the full Haive framework.

Classes¶

NimGameManager

Manager for the Nim game.

NimMove

Move in the Nim game.

NimState

State for the Nim game.

NimUI

UI for the Nim game.

Functions¶

main()

Run the Nim game.

parse_args()

Parse command line arguments.

Module Contents¶

class games.nim.standalone_game.NimGameManager¶

Manager for the Nim game.

static apply_move(state, move)¶

Apply a move to the current state.

Parameters:
Return type:

NimState

static check_game_status(state)¶

Check and update the game status.

Parameters:

state (NimState)

Return type:

NimState

static initialize(pile_sizes=None, misere_mode=False)¶

Initialize a new game state.

Parameters:
Return type:

NimState

class games.nim.standalone_game.NimMove(/, **data)¶

Bases: pydantic.BaseModel

Move in the Nim game.

Create a new model by parsing and validating input data from keyword arguments.

Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.

self is explicitly positional-only to allow self as a field name.

Parameters:

data (Any)

class games.nim.standalone_game.NimState(/, **data)¶

Bases: pydantic.BaseModel

State for the Nim game.

Create a new model by parsing and validating input data from keyword arguments.

Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.

self is explicitly positional-only to allow self as a field name.

Parameters:

data (Any)

property board_string: str¶

Return a string representation of the board.

Return type:

str

property is_game_over: bool¶

Check if the game is over.

Return type:

bool

property nim_sum: int¶

Calculate the nim-sum (XOR sum) of the pile sizes.

Return type:

int

property stones_left: int¶

Return the total number of stones left.

Return type:

int

class games.nim.standalone_game.NimUI(delay=0.5)¶

UI for the Nim game.

Initialize the UI.

Parameters:

delay (float)

announce_winner(state)¶

Announce the winner of the game.

Parameters:

state (NimState)

display_game_state(state)¶

Display the current game state.

Parameters:

state (NimState)

get_computer_move(state)¶

Generate a computer move.

Parameters:

state (NimState)

Return type:

NimMove

prompt_for_move(state)¶

Prompt the user for a move.

Parameters:

state (NimState)

Return type:

NimMove

games.nim.standalone_game.main()¶

Run the Nim game.

games.nim.standalone_game.parse_args()¶

Parse command line arguments.