Skip to content

Commit ffa0482

Browse files
authored
Merge pull request #1143 from MarkZH/docs
Add some missing docstrings
2 parents b3c1f62 + 2b8b0eb commit ffa0482

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

chess/__init__.py

+21
Original file line numberDiff line numberDiff line change
@@ -1810,11 +1810,13 @@ def ply(self) -> int:
18101810
return 2 * (self.fullmove_number - 1) + (self.turn == BLACK)
18111811

18121812
def remove_piece_at(self, square: Square) -> Optional[Piece]:
1813+
"""Remove a piece, if any, from the given square and return the removed piece."""
18131814
piece = super().remove_piece_at(square)
18141815
self.clear_stack()
18151816
return piece
18161817

18171818
def set_piece_at(self, square: Square, piece: Optional[Piece], promoted: bool = False) -> None:
1819+
"""Place a piece on a square."""
18181820
super().set_piece_at(square, piece, promoted=promoted)
18191821
self.clear_stack()
18201822

@@ -1998,6 +2000,7 @@ def is_pseudo_legal(self, move: Move) -> bool:
19982000
return bool(self.attacks_mask(move.from_square) & to_mask)
19992001

20002002
def is_legal(self, move: Move) -> bool:
2003+
"""Check if a move is legal in the current position."""
20012004
return not self.is_variant_end() and self.is_pseudo_legal(move) and not self.is_into_check(move)
20022005

20032006
def is_variant_end(self) -> bool:
@@ -2034,9 +2037,27 @@ def is_variant_draw(self) -> bool:
20342037
return False
20352038

20362039
def is_game_over(self, *, claim_draw: bool = False) -> bool:
2040+
"""
2041+
Check if the game is over by any rule.
2042+
2043+
The game is not considered to be over by the
2044+
:func:`fifty-move rule <chess.Board.can_claim_fifty_moves()>` or
2045+
:func:`threefold repetition <chess.Board.can_claim_threefold_repetition()>`,
2046+
unless *claim_draw* is given. Note that checking the latter can be
2047+
slow.
2048+
"""
20372049
return self.outcome(claim_draw=claim_draw) is not None
20382050

20392051
def result(self, *, claim_draw: bool = False) -> str:
2052+
"""
2053+
Return the result of a game: 1-0, 0-1, 1/2-1/2, or *.
2054+
2055+
The game is not considered to be over by the
2056+
:func:`fifty-move rule <chess.Board.can_claim_fifty_moves()>` or
2057+
:func:`threefold repetition <chess.Board.can_claim_threefold_repetition()>`,
2058+
unless *claim_draw* is given. Note that checking the latter can be
2059+
slow.
2060+
"""
20402061
outcome = self.outcome(claim_draw=claim_draw)
20412062
return outcome.result() if outcome else "*"
20422063

0 commit comments

Comments
 (0)