UCI Engine

A Qt-compatible interface similar to chess.engine

class chessengine.ChessEngine(engine2Option: Tuple[PathLike, Dict[str, str | int | bool | None]], limit: Limit = Limit(depth=10), timeout_msec: int = 1000, log: Callable[[str], None] | None = None, parent: QObject | None = None)[source]

A Universal Chess Interface (UCI) engine using (QProcess)

Parameters:
  • engine2Option – a pair of a path to the executable and dict of the changed options

  • limit – a limit definition for the engine (see chess.engine.Limit)

  • timeout_msec – timeout for the engine to respond (should be at least 1000)

  • log – log for the engine’s commands

  • ChessEngine.bestMoveScoreSignalpyqtSignal emitted when a best move is available

__init__(engine2Option: Tuple[PathLike, Dict[str, str | int | bool | None]], limit: Limit = Limit(depth=10), timeout_msec: int = 1000, log: Callable[[str], None] | None = None, parent: QObject | None = None) None[source]
kill(beSilent: bool = False) None[source]

Kills the process, engine cannot be used anymore

setLog(log: Callable[[str], None] | None = None) None[source]

Sets the log for engine’s commands

Parameters:

log – log for the engine’s commands, default = None

getScore(hintID: int = 0) int | None[source]

Delivers the score for a hint, if available

Parameters:

hintID – hint, i.e. alternative to be used (0 for best move)

Returns:

score in centipawns or None

isReady() bool[source]

Checks whether the engine is able to receive commands

Returns:

boolean indicating the response

uciNewGame(fen: str | None = None, moves: List[Move] = []) bool[source]

Wrapper for the UCI ucinewgame command

Parameters:
  • fen – starting position in Forsyth-Edwards-Notation (FEN)

  • moves – list of moves to be applied

Returns:

boolean indicating the success

uciSetOption(name: str, value: bool | int | str | None) bool[source]

Wrapper for the UCI setoption command

Parameters:
  • name – name of the option

  • value – value, type depends on name

Returns:

boolean indicating the success

uciGo(search_moves: Iterable[Move] | None = None, ponder: bool = False, infinite: bool = False) bool[source]

Wrapper for the UCI go command

Parameters:
  • search_moves – list of moves to be searched

  • ponder – suggest a response to the best-move

  • infinite – improve the best-move continuously

Returns:

boolean indicating the success

uciStop() bool[source]

Wrapper for the UCI stop command to stop an infinite go

Returns:

boolean indicating the success

uciQuit() None[source]

Terminate the engine

startPlay() bool[source]

Emits uciGO in play mode, i.e.g

  • UCI_AnalyseMode = off

  • MultiPV = 1, i.e. no alternative move suggestions

Returns:

boolean indicating the success

startAnalysis(multiPV: int = 1) bool[source]

Emits uciGO in analyse mode, i.e.

  • UCI_AnalyseMode = off

  • MultiPV = multiPV

Parameters:

multiPV – number of alternative move suggestions

Returns:

boolean indicating the success