Game

These are the modules in the othello.game subpackage that deal with tracking the state of an Othello game.

othello.game.game_state

Game state module.

class othello.game.game_state.GameState(board, current_player, move=None, prev_move=None)

An Othello game state.

board

Board instance reflecting current state.

current_player

Player whose turn it is.

last_move

The last Move played.

second_last_move

The second to last Move played.

apply_move(move)

Apply Move to GameState.

Parameters

move (Move) – Move to be applied.

Return type

GameState

Returns

New GameState instance.

Raises

InvalidMoveError – If the move is illegal given the game state.

is_over()

Returns whether game is over given the current state.

Return type

bool

Returns

True if game is over, False otherwise.

legal_moves()

Returns list of legal plays for the current player.

Return type

List[Point]

Returns

List of Point instances that are legal plays.

classmethod new_game(board_size=8)

Constructor for initial game state.

Parameters

board_size (int) – Board size.

Return type

GameState

Returns

Initial game state.

winner()

Returns whether game is over.

If a player has resigned, the other player is the winner. If neither player has resigned, the winner is the player with the most discs on the board. If they have an equal count, it is a draw.

Return type

Optional[Player]

Returns

Player who won if there is a winner, None if it is a draw.

exception othello.game.game_state.InvalidMoveError

Raised when passing while there are legal disc placements.

othello.game.board

Board module.

class othello.game.board.Board(size)

Othello board.

Board instances keep track of what color discs are on what locations.

size

Board size.

count_discs(player)

Count discs on board corresponding to the given player.

Parameters

player (Player) – Player whose discs are counted.

Return type

int

Returns

Disc count.

get_valid_moves(player)

Get valid moves and their captures.

Parameters

player (Player) – Player whose moves are considered.

Return type

Dict[Point, List[Point]]

Returns

Dictionary mapping valid disc placements to discs captured by the move.

place_disc(player, point)

Place disc corresponding to player at the given point.

If the move is valid, the Board instance will be updated to reflect the disc being at that point and all outflanked discs being reversed.

Parameters
  • player (Player) – The disc placed corresponds to this player.

  • point (Point) – The disc will be placed at this point.

Raises

InvalidDiscPlacementError – If disc cannot legally be placed at the given point.

Return type

None

exception othello.game.board.BoardSizeError

Raised when initializing Board object with invalid board size.

exception othello.game.board.InvalidDiscPlacementError

Raised when placing disc on Board at an invalid location.