Skip to content

Commit 34d74f9

Browse files
committed
Document that editing board clears move stack (fixes #887)
1 parent f9d2b0d commit 34d74f9

File tree

2 files changed

+26
-10
lines changed

2 files changed

+26
-10
lines changed

chess/__init__.py

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -623,7 +623,13 @@ def _reset_board(self) -> None:
623623
self.occupied = BB_RANK_1 | BB_RANK_2 | BB_RANK_7 | BB_RANK_8
624624

625625
def reset_board(self) -> None:
626-
"""Resets pieces to the starting position."""
626+
"""
627+
Resets pieces to the starting position.
628+
629+
:class:`~chess.Board` also resets the move stack, but not turn,
630+
castling rights and move counters. Use :func:`chess.Board.reset()` to
631+
fully restore the starting position.
632+
"""
627633
self._reset_board()
628634

629635
def _clear_board(self) -> None:
@@ -641,7 +647,11 @@ def _clear_board(self) -> None:
641647
self.occupied = BB_EMPTY
642648

643649
def clear_board(self) -> None:
644-
"""Clears the board."""
650+
"""
651+
Clears the board.
652+
653+
:class:`~chess.Board` also clears the move stack.
654+
"""
645655
self._clear_board()
646656

647657
def pieces_mask(self, piece_type: PieceType, color: Color) -> Bitboard:
@@ -877,6 +887,8 @@ def remove_piece_at(self, square: Square) -> Optional[Piece]:
877887
"""
878888
Removes the piece from the given square. Returns the
879889
:class:`~chess.Piece` or ``None`` if the square was already empty.
890+
891+
:class:`~chess.Board` also clears the move stack.
880892
"""
881893
color = bool(self.occupied_co[WHITE] & BB_SQUARES[square])
882894
piece_type = self._remove_piece_at(square)
@@ -914,6 +926,8 @@ def set_piece_at(self, square: Square, piece: Optional[Piece], promoted: bool =
914926
915927
An existing piece is replaced. Setting *piece* to ``None`` is
916928
equivalent to :func:`~chess.Board.remove_piece_at()`.
929+
930+
:class:`~chess.Board` also clears the move stack.
917931
"""
918932
if piece is None:
919933
self._remove_piece_at(square)
@@ -1010,6 +1024,8 @@ def set_board_fen(self, fen: str) -> None:
10101024
Parses *fen* and sets up the board, where *fen* is the board part of
10111025
a FEN.
10121026
1027+
:class:`~chess.Board` also clears the move stack.
1028+
10131029
:raises: :exc:`ValueError` if syntactically invalid.
10141030
"""
10151031
self._set_board_fen(fen)
@@ -1032,6 +1048,8 @@ def set_piece_map(self, pieces: Mapping[Square, Piece]) -> None:
10321048
"""
10331049
Sets up the board from a dictionary of :class:`pieces <chess.Piece>`
10341050
by square index.
1051+
1052+
:class:`~chess.Board` also clears the move stack.
10351053
"""
10361054
self._set_piece_map(pieces)
10371055

@@ -1283,8 +1301,8 @@ def apply_transform(self, f: Callable[[Bitboard], Bitboard]) -> None:
12831301

12841302
def transform(self: BaseBoardT, f: Callable[[Bitboard], Bitboard]) -> BaseBoardT:
12851303
"""
1286-
Returns a transformed copy of the board by applying a bitboard
1287-
transformation function.
1304+
Returns a transformed copy of the board (without move stack)
1305+
by applying a bitboard transformation function.
12881306
12891307
Available transformations include :func:`chess.flip_vertical()`,
12901308
:func:`chess.flip_horizontal()`, :func:`chess.flip_diagonal()`,
@@ -1305,7 +1323,7 @@ def apply_mirror(self: BaseBoardT) -> None:
13051323

13061324
def mirror(self: BaseBoardT) -> BaseBoardT:
13071325
"""
1308-
Returns a mirrored copy of the board.
1326+
Returns a mirrored copy of the board (without move stack).
13091327
13101328
The board is mirrored vertically and piece colors are swapped, so that
13111329
the position is equivalent modulo color.
@@ -1582,11 +1600,6 @@ def reset(self) -> None:
15821600
self.reset_board()
15831601

15841602
def reset_board(self) -> None:
1585-
"""
1586-
Resets only pieces to the starting position. Use
1587-
:func:`~chess.Board.reset()` to fully restore the starting position
1588-
(including turn, castling rights, etc.).
1589-
"""
15901603
super().reset_board()
15911604
self.clear_stack()
15921605

@@ -2524,6 +2537,8 @@ def set_castling_fen(self, castling_fen: str) -> None:
25242537
"""
25252538
Sets castling rights from a string in FEN notation like ``Qqk``.
25262539
2540+
Also clears the move stack.
2541+
25272542
:raises: :exc:`ValueError` if the castling FEN is syntactically
25282543
invalid.
25292544
"""

docs/core.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ Board
108108

109109
.. autoclass:: chess.Board
110110
:members:
111+
:exclude-members: set_piece_at, remove_piece_at, reset_board, set_board_fen, set_piece_map, set_chess960_pos, apply_transform
111112

112113
.. autoclass:: chess.BaseBoard
113114
:members:

0 commit comments

Comments
 (0)