Engine

class engine.Engine[source]

Bases: object

Game engine.

BRAINS: Final[dict[Strategy, Callable[[], Brain]]] = {Strategy.NEGAMAX: <class 'ai.brain.AlphaBetaPruner'>, Strategy.RANDOM: <class 'ai.brain.Random'>}

Map for strategies and the respective brain.

DEFAULT_MAX_BRANCHING_FACTOR: Final[int] = 256

Default value for option MaxBranchingFactor.

DEFAULT_NUM_THREADS: Final[int] = 2

Default value for option NumThreads.

DEFAULT_STRATEGY_BLACK: Final[Strategy] = 'Negamax'

Default value for option StrategyBlack.

DEFAULT_STRATEGY_WHITE: Final[Strategy] = 'Negamax'

Default value for option StrategyWhite.

MAX_MAX_BRANCHING_FACTOR: Final[int] = 1024

Maximum value for option MaxBranchingFactor.

MAX_NUM_THREADS: Final[int] = 4

Maximum value for option NumThreads.

MIN_MAX_BRANCHING_FACTOR: Final[int] = 8

Minimum value for option MaxBranchingFactor.

MIN_NUM_THREADS: Final[int] = 1

Minimum value for option NumThreads.

OPTION_TYPES: Final[dict[Option, OptionType]] = {Option.MAX_BRANCHING_FACTOR: OptionType.INT, Option.NUM_THREADS: OptionType.INT, Option.STRATEGY_BLACK: OptionType.ENUM, Option.STRATEGY_WHITE: OptionType.ENUM}

Map for options and their type.

VERSION: Final[str] = '1.6.1'

Engine version.

bestmove(restriction: str, value: str) None[source]

Handles ‘bestmove’ command with arguments.

Parameters:
  • restriction (str) – Type of restriction in searching for the best move.

  • value (str) – Value of the restriction (time or depth).

error(error: str | Exception) None[source]

Outputs as an error the given message/exception.

Parameters:

message (str | Exception) – Message or exception.

help(arguments: list[str]) None[source]

Handles ‘help’ command with arguments.

Parameters:

arguments (list[str]) – Command arguments.

info() None[source]

Handles ‘info’ command.

is_active(board: Board | None) TypeGuard[Board][source]

Checks whether the current playing Board is initialized.

Parameters:

board (Optional[Board]) – Current playing Board.

Returns:

Whether the Board is initialized.

Return type:

TypeGuard[Board]

newgame(arguments: list[str]) None[source]
Handles ‘newgame’ command with arguments.
Tries to create a new game by instantiating the Board.
Parameters:

arguments (list[str]) – Command arguments.

options(arguments: list[str]) None[source]

Handles ‘options’ command with arguments.

Parameters:

arguments (list[str]) – Command arguments.

play(move: str) None[source]

Handles ‘play’ command with its argument (MoveString).

Parameters:

move (str) – MoveString.

start() None[source]

Engine main loop to handle commands.

threads = 4
undo(arguments: list[str]) None[source]

Handles ‘undo’ command with arguments.

Parameters:

arguments (list[str]) – Command arguments.

validmoves() None[source]

Handles ‘validmoves’ command.