Skip to content

Commit e0be0b4

Browse files
committed
documentation tweaks and updates
1 parent 0d7a29f commit e0be0b4

2 files changed

Lines changed: 32 additions & 25 deletions

File tree

chess/engine.py

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -665,13 +665,14 @@ def play(self, board, limit, *, game=None, info=INFO_NONE, ponder=False, root_mo
665665
666666
:param board: The position. The entire move stack will be sent to the
667667
engine.
668-
:param limit: An instance of :class:`~chess.engine.Limit` that
668+
:param limit: An instance of :class:`chess.engine.Limit` that
669669
determines when to stop thinking.
670670
:param game: Optional. An arbitrary object that identifies the game.
671-
Will automatically clear hashtables if the object is not equal
672-
to the previous game.
671+
Will automatically inform the engine if the object is not equal
672+
to the previous game (e.g. ``ucinewgame``, ``new``).
673673
:param info: Selects which additional information to retrieve from the
674-
engine. ``INFO_NONE``, ``INFO_BASE``, ``INFO_SCORE``, ``INFO_PV``,
674+
engine. ``INFO_NONE``, ``INFO_BASE`` (basic information that is
675+
trivial to obtain), ``INFO_SCORE``, ``INFO_PV``,
675676
``INFO_REFUTATION``, ``INFO_CURRLINE``, ``INFO_ALL`` or any
676677
bitwise combination. Some overhead is associated with parsing
677678
extra information.
@@ -687,20 +688,22 @@ def play(self, board, limit, *, game=None, info=INFO_NONE, ponder=False, root_mo
687688
@asyncio.coroutine
688689
def analyse(self, board, limit, *, multipv=None, game=None, info=INFO_ALL, root_moves=None, options={}):
689690
"""
690-
Analyses a position and returns an info dictionary.
691+
Analyses a position and returns a dictionary of
692+
`information <#chess.engine.PlayResult.info>`_.
691693
692694
:param board: The position to analyse. The entire move stack will be
693695
sent to the engine.
694-
:param limit: An instance of :class:`~chess.engine.Limit` that
696+
:param limit: An instance of :class:`chess.engine.Limit` that
695697
determines when to stop the analysis.
696698
:param multipv: Optional. Analyse multiple root moves. Will return a list of
697699
at most *multipv* dictionaries rather than just a single
698700
info dictionary.
699701
:param game: Optional. An arbitrary object that identifies the game.
700-
Will automatically clear hashtables if the object is not equal
701-
to the previous game.
702+
Will automatically inform the engine if the object is not equal
703+
to the previous game (e.g. ``ucinewgame``, ``new``).
702704
:param info: Selects which information to retrieve from the
703-
engine. ``INFO_NONE``, ``INFO_BASE``, ``INFO_SCORE``, ``INFO_PV``,
705+
engine. ``INFO_NONE``, ``INFO_BASE`` (basic information that is
706+
trivial to obtain), ``INFO_SCORE``, ``INFO_PV``,
704707
``INFO_REFUTATION``, ``INFO_CURRLINE``, ``INFO_ALL`` or any
705708
bitwise combination. Some overhead is associated with parsing
706709
extra information.
@@ -725,15 +728,16 @@ def analysis(self, board, limit=None, *, multipv=None, game=None, info=INFO_ALL,
725728
726729
:param board: The position to analyse. The entire move stack will be
727730
sent to the engine.
728-
:param limit: Optional. An instance of :class:`~chess.engine.Limit`
731+
:param limit: Optional. An instance of :class:`chess.engine.Limit`
729732
that determines when to stop the analysis. Analysis is infinite
730733
by default.
731734
:param multipv: Optional. Analyse multiple root moves.
732735
:param game: Optional. An arbitrary object that identifies the game.
733736
Will automatically clear hashtables if the object is not equal
734737
to the previous game.
735738
:param info: Selects which information to retrieve from the
736-
engine. ``INFO_NONE``, ``INFO_BASE``, ``INFO_SCORE``, ``INFO_PV``,
739+
engine. ``INFO_NONE``, ``INFO_BASE`` (basic information that is
740+
trivial to obtain), ``INFO_SCORE``, ``INFO_PV``,
737741
``INFO_REFUTATION``, ``INFO_CURRLINE``, ``INFO_ALL`` or any
738742
bitwise combination. Some overhead is associated with parsing
739743
extra information.

docs/engine.rst

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,18 @@
1-
Engine communication [experimental]
1+
Engine communication (experimental)
22
===================================
33

44
UCI and XBoard are protocols for communicating with chess engines. This module
55
implements an abstraction for playing moves and analysing positions with
66
both kinds of engines.
77

88
:warning: This is an experimental module that may change in semver incompatible
9-
ways. Please weigh in on the design if the provided APIs do not cover
10-
your use case.
9+
ways. Please `weigh in <https://github.com/niklasf/python-chess/issues/new>`_
10+
on the design if the provided APIs do not cover your use case.
1111

1212
The intention is to eventually replace ``chess.uci`` and ``chess.xboard``,
1313
but not before things have settled down and there has been a transition
1414
period.
1515

16-
The XBoard implementation is currently only a skeleton.
17-
1816
The preferred way to use the API is with an
1917
`asyncio <https://docs.python.org/3/library/asyncio.html>`_ event loop.
2018
The examples also show a simple synchronous wrapper
@@ -35,7 +33,7 @@ Example: Let Stockfish play against itself, 100 milliseconds per move.
3533
3634
board = chess.Board()
3735
while not board.is_game_over():
38-
result = engine.play(board, chess.engine.Limit(movetime=100))
36+
result = engine.play(board, chess.engine.Limit(time=0.100))
3937
board.push(result.move)
4038
4139
engine.quit()
@@ -51,7 +49,7 @@ Example: Let Stockfish play against itself, 100 milliseconds per move.
5149
5250
board = chess.Board()
5351
while not board.is_game_over():
54-
result = await engine.play(board, chess.engine.Limit(movetime=100))
52+
result = await engine.play(board, chess.engine.Limit(time=0.100))
5553
board.push(result.move)
5654
5755
await engine.quit()
@@ -115,11 +113,16 @@ Example: Let Stockfish play against itself, 100 milliseconds per move.
115113

116114
.. py:attribute:: info
117115
118-
A dictionary of extra information sent by the engine. Known keys are
119-
``score``, ``depth``, ``seldepth``, ``time``, ``nodes``, ``pv``,
120-
``multipv``, ``currmove``, ``currmovenumber``, ``hashfull``, ``nps``,
121-
``tbhits``, ``cpuload``, ``refutation``, ``currline``, ``ebf`` and
122-
``string``.
116+
A dictionary of extra information sent by the engine. Commonly used
117+
keys are: ``score``, ``pv``, ``depth``, ``seldepth``, ``time``
118+
(in seconds), ``nodes``, ``nps``, ``tbhits``, ``multipv``.
119+
120+
Others: ``currmove``, ``currmovenumber``, ``hashfull``
121+
``cpuload``, ``refutation``, ``currline``, ``ebf`` and ``string``.
122+
123+
.. py:attribute:: draw_offered
124+
125+
Whether the engine offered a draw before moving.
123126

124127
Analysing and evaluating a position
125128
-----------------------------------
@@ -134,7 +137,7 @@ Example:
134137
engine = chess.engine.SimpleEngine.popen_uci("stockfish")
135138
136139
board = chess.Board()
137-
info = engine.analyse(board, chess.engine.Limit(movetime=100))
140+
info = engine.analyse(board, chess.engine.Limit(time=0.100))
138141
print("Score:", info["score"])
139142
# Score: +20
140143
@@ -155,7 +158,7 @@ Example:
155158
transport, engine = await chess.engine.popen_uci("stockfish")
156159
157160
board = chess.Board()
158-
info = await engine.analyse(board, chess.engine.Limit(movetime=100))
161+
info = await engine.analyse(board, chess.engine.Limit(time=0.100))
159162
print(info["score"])
160163
# Score: +20
161164

0 commit comments

Comments
 (0)