Skip to content

Commit a4a1da7

Browse files
authored
Merge pull request niklasf#1 from niklasf/master
Update fork with latest edits
2 parents 86f8332 + da99154 commit a4a1da7

11 files changed

Lines changed: 38 additions & 39 deletions

File tree

chess/__init__.py

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -455,12 +455,6 @@ class Move:
455455
promotion: Optional[PieceType] = None
456456
drop: Optional[PieceType] = None
457457

458-
def __init__(self, from_square: Square, to_square: Square, promotion: Optional[PieceType] = None, drop: Optional[PieceType] = None) -> None:
459-
self.from_square = from_square
460-
self.to_square = to_square
461-
self.promotion = promotion
462-
self.drop = drop
463-
464458
def uci(self) -> str:
465459
"""
466460
Gets a UCI string for the move.
@@ -568,7 +562,7 @@ def _reset_board(self) -> None:
568562
self.occupied = BB_RANK_1 | BB_RANK_2 | BB_RANK_7 | BB_RANK_8
569563

570564
def reset_board(self) -> None:
571-
"""Resets piece positions to the starting position."""
565+
"""Resets pieces to the starting position."""
572566
self._reset_board()
573567

574568
def _clear_board(self) -> None:
@@ -978,13 +972,13 @@ def set_piece_map(self, pieces: Mapping[Square, Piece]) -> None:
978972
"""
979973
self._set_piece_map(pieces)
980974

981-
def _set_chess960_pos(self, sharnagl: int) -> None:
982-
if not 0 <= sharnagl <= 959:
983-
raise ValueError(f"chess960 position index not 0 <= {sharnagl!r} <= 959")
975+
def _set_chess960_pos(self, scharnagl: int) -> None:
976+
if not 0 <= scharnagl <= 959:
977+
raise ValueError(f"chess960 position index not 0 <= {scharnagl!r} <= 959")
984978

985979
# See http://www.russellcottrell.com/Chess/Chess960.htm for
986980
# a description of the algorithm.
987-
n, bw = divmod(sharnagl, 4)
981+
n, bw = divmod(scharnagl, 4)
988982
n, bb = divmod(n, 4)
989983
n, q = divmod(n, 6)
990984

@@ -1039,16 +1033,16 @@ def _set_chess960_pos(self, sharnagl: int) -> None:
10391033
self.occupied = BB_RANK_1 | BB_RANK_2 | BB_RANK_7 | BB_RANK_8
10401034
self.promoted = BB_EMPTY
10411035

1042-
def set_chess960_pos(self, sharnagl: int) -> None:
1036+
def set_chess960_pos(self, scharnagl: int) -> None:
10431037
"""
10441038
Sets up a Chess960 starting position given its index between 0 and 959.
10451039
Also see :func:`~chess.BaseBoard.from_chess960_pos()`.
10461040
"""
1047-
self._set_chess960_pos(sharnagl)
1041+
self._set_chess960_pos(scharnagl)
10481042

10491043
def chess960_pos(self) -> Optional[int]:
10501044
"""
1051-
Gets the Chess960 starting position index between 0 and 959
1045+
Gets the Chess960 starting position index between 0 and 959,
10521046
or ``None``.
10531047
"""
10541048
if self.occupied_co[WHITE] != BB_RANK_1 | BB_RANK_2:
@@ -1295,7 +1289,7 @@ def empty(cls: Type[BaseBoardT]) -> BaseBoardT:
12951289
return cls(None)
12961290

12971291
@classmethod
1298-
def from_chess960_pos(cls: Type[BaseBoardT], sharnagl: int) -> BaseBoardT:
1292+
def from_chess960_pos(cls: Type[BaseBoardT], scharnagl: int) -> BaseBoardT:
12991293
"""
13001294
Creates a new board, initialized with a Chess960 starting position.
13011295
@@ -1305,7 +1299,7 @@ def from_chess960_pos(cls: Type[BaseBoardT], sharnagl: int) -> BaseBoardT:
13051299
>>> board = chess.Board.from_chess960_pos(random.randint(0, 959))
13061300
"""
13071301
board = cls.empty()
1308-
board.set_chess960_pos(sharnagl)
1302+
board.set_chess960_pos(scharnagl)
13091303
return board
13101304

13111305

@@ -1436,6 +1430,11 @@ def reset(self) -> None:
14361430
self.reset_board()
14371431

14381432
def reset_board(self) -> None:
1433+
"""
1434+
Resets only pieces to the starting position. Use
1435+
:func:`~chess.Board.reset()` to fully restore the starting position
1436+
(including turn, castling rights, etc.).
1437+
"""
14391438
super().reset_board()
14401439
self.clear_stack()
14411440

@@ -2114,7 +2113,7 @@ def pop(self: BoardT) -> Move:
21142113
"""
21152114
Restores the previous position and returns the last move from the stack.
21162115
2117-
:raises: :exc:`IndexError` if the stack is empty.
2116+
:raises: :exc:`IndexError` if the move stack is empty.
21182117
"""
21192118
move = self.move_stack.pop()
21202119
self._stack.pop().restore(self)
@@ -2130,7 +2129,7 @@ def peek(self) -> Move:
21302129

21312130
def find_move(self, from_square: Square, to_square: Square, promotion: Optional[PieceType] = None) -> Move:
21322131
"""
2133-
Finds a matching legal move for an origin square, a target square and
2132+
Finds a matching legal move for an origin square, a target square, and
21342133
an optional promotion piece type.
21352134
21362135
For pawn moves to the backrank, the promotion piece type defaults to
@@ -2386,8 +2385,8 @@ def set_piece_map(self, pieces: Mapping[Square, Piece]) -> None:
23862385
super().set_piece_map(pieces)
23872386
self.clear_stack()
23882387

2389-
def set_chess960_pos(self, sharnagl: int) -> None:
2390-
super().set_chess960_pos(sharnagl)
2388+
def set_chess960_pos(self, scharnagl: int) -> None:
2389+
super().set_chess960_pos(scharnagl)
23912390
self.chess960 = True
23922391
self.turn = WHITE
23932392
self.castling_rights = self.rooks
@@ -2399,7 +2398,7 @@ def set_chess960_pos(self, sharnagl: int) -> None:
23992398

24002399
def chess960_pos(self, *, ignore_turn: bool = False, ignore_castling: bool = False, ignore_counters: bool = True) -> Optional[int]:
24012400
"""
2402-
Gets the Chess960 starting position index between 0 and 956
2401+
Gets the Chess960 starting position index between 0 and 956,
24032402
or ``None`` if the current position is not a Chess960 starting
24042403
position.
24052404
@@ -3536,9 +3535,9 @@ def from_epd(cls: Type[BoardT], epd: str, *, chess960: bool = False) -> Tuple[Bo
35363535
return board, board.set_epd(epd)
35373536

35383537
@classmethod
3539-
def from_chess960_pos(cls: Type[BoardT], sharnagl: int) -> BoardT:
3538+
def from_chess960_pos(cls: Type[BoardT], scharnagl: int) -> BoardT:
35403539
board = cls.empty(chess960=True)
3541-
board.set_chess960_pos(sharnagl)
3540+
board.set_chess960_pos(scharnagl)
35423541
return board
35433542

35443543

chess/variant.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -772,8 +772,8 @@ def parse_san(self, san: str) -> chess.Move:
772772
return super().parse_san(san)
773773

774774
def has_insufficient_material(self, color: chess.Color) -> bool:
775-
# In practise no material can leave the game, but this is easy to
776-
# implement anyway. Note that bishops can be captured and put onto
775+
# In practice, no material can leave the game, but this is easy to
776+
# implement, anyway. Note that bishops can be captured and put onto
777777
# a different color complex.
778778
return (
779779
chess.popcount(self.occupied) + sum(len(pocket) for pocket in self.pockets) <= 3 and

docs/variant.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,16 @@ python-chess supports several chess variants.
77
>>>
88
>>> board = chess.variant.GiveawayBoard()
99

10-
>>> # General information about the variants
10+
>>> # General information about the variants.
1111
>>> type(board).uci_variant
1212
'giveaway'
1313
>>> type(board).xboard_variant
1414
'giveaway'
1515
>>> type(board).starting_fen
1616
'rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w - - 0 1'
1717

18-
See :func:`chess.Board.is_variant_end()`, :func:`~chess.Board.is_variant_win()`
19-
:func:`~chess.Board.is_variant_draw()` :func:`~chess.Board.is_variant_loss()`
18+
See :func:`chess.Board.is_variant_end()`, :func:`~chess.Board.is_variant_win()`,
19+
:func:`~chess.Board.is_variant_draw()`, or :func:`~chess.Board.is_variant_loss()`
2020
for special variant end conditions and results.
2121

2222
================ ========================================= ============= ============

examples/bratko_kopec/bratko_kopec.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/usr/bin/env python
1+
#!/usr/bin/env python3
22

33
"""Run an EPD test suite with a UCI engine."""
44

examples/chess960_pos_list.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/usr/bin/env python
1+
#!/usr/bin/env python3
22

33
"""List all Chess960 starting positions."""
44

@@ -10,11 +10,11 @@
1010
def main(bench_only: bool = False) -> None:
1111
board = chess.Board.empty(chess960=True)
1212

13-
for sharnagl in range(0, 960):
14-
board.set_chess960_pos(sharnagl)
13+
for scharnagl in range(0, 960):
14+
board.set_chess960_pos(scharnagl)
1515

1616
if not bench_only:
17-
print(str(sharnagl).rjust(3), board.fen())
17+
print(str(scharnagl).rjust(3), board.fen())
1818

1919

2020
if __name__ == "__main__":

examples/perft/perft.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/usr/bin/env python
1+
#!/usr/bin/env python3
22

33
"""
44
Run perft test to check correctness and speed of the legal move generator.

examples/polyglot_tree.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/usr/bin/env python
1+
#!/usr/bin/env python3
22

33
"""Print a Polyglot opening book in tree form."""
44

examples/push_san.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/usr/bin/env python
1+
#!/usr/bin/env python3
22

33
"""Play the immortal game using push_san() from chess.Board()."""
44

examples/xray_attacks.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/usr/bin/env python
1+
#!/usr/bin/env python3
22

33
"""Compute X-ray attacks through more valuable pieces."""
44

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/usr/bin/env python
1+
#!/usr/bin/env python3
22
# -*- coding: utf-8 -*-
33
#
44
# This file is part of the python-chess library.

0 commit comments

Comments
 (0)