Clients package

The client package contains all implementations of a player.

Clients.ClientInterface

class Clients.ClientInterface.ClientInterface(color: bool)[source]

Bases: abc.ABC

Defines interface of a client

metadata: Dict[str, str] = {}
abstract get_move()chess.engine.PlayResult[source]

Returns next move from client

Returns

next move played by the client in the normal engine output format

abstract set_move(move: chess.engine.PlayResult)None[source]

Report new move to client

Parameters

move – reports move of opponent to client using normal engine output format

color: bool
game_is_over()bool[source]

Checks if game is over

Implementations of PlayerClientInterface can choose to extend this method to display the result, accept resignation or accept draw offers

Returns

Returns True iff game is over

synchronize_clocks(clock: Optional[Tuple[datetime.timedelta, datetime.timedelta]] = None)Optional[Tuple[datetime.timedelta, datetime.timedelta]][source]

Synchronize clocks between two clients

Parameters

clock – Input clock from the other client (white time, black time)

Returns

return clock from current client (white time, black time) if available

Clients.ChessDotComClient

class Clients.ChessDotComClient.ChessDotComClient(headless: bool = False, path_userdata: Optional[str] = None)[source]

Bases: Clients.ClientInterface.ClientInterface

Defines the client to play on chess.com

color: bool
get_move()chess.engine.PlayResult[source]

Detects client move from chess.com

Returns

next move played by the client in the engine output format

set_move(move: chess.engine.PlayResult)[source]

Plays new move on chess.com

Parameters

move – reports move of opponent to client using normal engine output format

game_is_over()bool[source]

Checks if game is over by checking if the position is mate or the game over window is open

Returns

Returns True iff game is over

synchronize_clocks(clock: Optional[Tuple[datetime.timedelta, datetime.timedelta]] = None)Optional[Tuple[datetime.timedelta, datetime.timedelta]][source]

Obtains time from chess.com if the clock is running else returns input

Parameters

clock – Input clock from the other client

Returns

return clock from current client

start_new_game()bool[source]

Resets the client to start a new game, unique method for chessdotcom client

This method can be used to start a new game using the same client. This prevents us from having to reload the chromedriver

Returns

Returns new color of client

Clients.ConsoleClient

class Clients.ConsoleClient.ConsoleClient(color: bool)[source]

Bases: Clients.ClientInterface.ClientInterface

Defines commandline interface client, mainly for testing purposes

get_move()chess.engine.PlayResult[source]

Parses new move expected format <from_square><to_square> or a game end offer

Prints the current position and waits for an input move. Input move should be in format <from_square><to_square> ie. e2e4 to move pawn to e4. The move should be legal in the current position

Returns

Move played in engine plays format

set_move(move: chess.engine.PlayResult)[source]

Report new move to the client

Parameters

move – opponents move in engine format, only move field is used

color: bool

Clients.EngineClient

class Clients.EngineClient.EngineClient(color: bool, path: str, move_time=0.1)[source]

Bases: Clients.ClientInterface.ClientInterface

Defines interface for an engine

get_move()chess.engine.PlayResult[source]

Returns next move from client

set_move(move: chess.engine.PlayResult)[source]

Report new move to client

Clients.HardwareClient

class Clients.HardwareClient.HardwareClient(color: bool)[source]

Bases: Clients.ClientInterface.ClientInterface

Interface to Hardware chessboard

get_move()chess.engine.PlayResult[source]

Returns next move from client

Returns

next move played by the client in the normal engine output format

set_move(move: chess.engine.PlayResult)[source]

Report new move to client

Parameters

move – reports move of opponent to client using normal engine output format

game_is_over()bool[source]

Checks if the game has ended

Conditions checked: 1. Checkmate 2. Opponent resignation 3. Stop flag raised

synchronize_clocks(clock: Optional[Tuple[datetime.timedelta, datetime.timedelta]] = None)Optional[Tuple[datetime.timedelta, datetime.timedelta]][source]

Synchronize clocks between two clients

Parameters

clock – Input clock from the other client (white time, black time)

Returns

return clock from current client (white time, black time) if available