Skip to content

Commit f76c387

Browse files
authored
Merge pull request #1023 from MarkZH/documentation
Engine communication documentation
2 parents fa152ad + 0fcee35 commit f76c387

2 files changed

Lines changed: 24 additions & 6 deletions

File tree

chess/engine.py

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -449,10 +449,18 @@ class Info(enum.IntFlag):
449449
@dataclasses.dataclass
450450
class Opponent:
451451
"""Used to store information about an engine's opponent."""
452+
452453
name: Optional[str]
454+
"""The name of the opponent."""
455+
453456
title: Optional[str]
457+
"""The opponent's title--for example, GM, IM, or BOT."""
458+
454459
rating: Optional[int]
460+
"""The opponent's ELO rating."""
461+
455462
is_engine: Optional[bool]
463+
"""Whether the opponent is a chess engine/computer program."""
456464

457465

458466
class PovScore:
@@ -1158,7 +1166,7 @@ async def send_opponent_information(self, *, opponent: Optional[Opponent] = None
11581166
method should be called before the first move of a game--i.e., the
11591167
first call to :func:`chess.engine.Protocol.play()`.
11601168
1161-
:param opponent: Optional. The opponent's information.
1169+
:param opponent: Optional. An instance of :class:`chess.engine.Opponent` that has the opponent's information.
11621170
:param engine_rating: Optional. This engine's own rating. Only used by XBoard engines.
11631171
"""
11641172

@@ -1272,9 +1280,9 @@ async def send_game_result(self, board: chess.Board, winner: Optional[Color] = N
12721280
Sends the engine the result of the game.
12731281
12741282
XBoard engines receive the final moves and a line of the form
1275-
"result <winner> {<ending>}". The <winner> field is one of "1-0",
1276-
"0-1", "1/2-1/2", or "*" to indicate white won, black won, draw,
1277-
or adjournment, respectively. The <ending> field is a description
1283+
``result <winner> {<ending>}``. The ``<winner>`` field is one of ``1-0``,
1284+
``0-1``, ``1/2-1/2``, or ``*`` to indicate white won, black won, draw,
1285+
or adjournment, respectively. The ``<ending>`` field is a description
12781286
of the specific reason for the end of the game: "White mates",
12791287
"Time forfeiture", "Stalemate", etc.
12801288
@@ -1284,9 +1292,10 @@ async def send_game_result(self, board: chess.Board, winner: Optional[Color] = N
12841292
:param board: The final state of the board.
12851293
:param winner: Optional. Specify the winner of the game. This is useful
12861294
if the result of the game is not evident from the board--e.g., time
1287-
forfeiture or draw by agreement.
1295+
forfeiture or draw by agreement. If not ``None``, this parameter
1296+
overrides any winner derivable from the board.
12881297
:param game_ending: Optional. Text describing the reason for the game
1289-
ending. Similarly to the winner paramter, this overrides any game
1298+
ending. Similarly to the winner parameter, this overrides any game
12901299
result derivable from the board.
12911300
:param game_complete: Optional. Whether the game reached completion.
12921301
"""

docs/engine.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,15 @@ Example: Let Stockfish play against itself, 100 milliseconds per move.
7070
.. autoclass:: chess.engine.PlayResult
7171
:members:
7272

73+
.. autoclass:: chess.engine.Protocol
74+
:members: send_opponent_information
75+
76+
.. autoclass:: chess.engine.Opponent
77+
:members:
78+
79+
.. autoclass:: chess.engine.Protocol
80+
:members: send_game_result
81+
7382
Analysing and evaluating a position
7483
-----------------------------------
7584

0 commit comments

Comments
 (0)