chessengine.pgn.node#

class chessengine.pgn.node.Game(root_node)#

A class representing a game, keeping track of the moves made throughout the game and the GameNodes reached as a result. Used to record a game and replay it.

add_header(key: str, value: str) None#

Add a header to Game.headers

Parameters:
  • key (str) – The header to be added (usually sourced from the PGN file)

  • value (str) – The value of the header

Raises:

PGNParsingError – If the key has already been added to the Game

Return type:

None

class chessengine.pgn.node.GameNode(turn: str)#

A class representing a node in a game. Useful for parsing a PGN game and building a tree of moves for the opening book.

Provides a children dictionary that maps a move (str) made from this GameNode to the GameNode representing the new Board state.

Parameters:

turn (str) – The side to move on this GameNode.

add_child(move: str)#

Create a new GameNode and add it as a child to the current node in the children dictionary.

Parameters:

move (str) – The move made to reach the new game node

Return GameNode:

Return the newly created GameNode.

get_child(move: str)#

Check if move is a child of this GameNode. If it is, return the corresponding GameNode, else raise ValueError.

Parameters:

move (str) – The move to check for

Return GameNode:

Return the GameNode if found

Raises:

ValueError – If the move passed is not a child of the GameNode