25
25
from typing import ClassVar , Callable , Counter , Dict , Generic , Hashable , Iterable , Iterator , List , Literal , Mapping , Optional , SupportsInt , Tuple , Type , TypeVar , Union
26
26
27
27
if typing .TYPE_CHECKING :
28
- from typing_extensions import TypeAlias
28
+ from typing_extensions import Self , TypeAlias
29
29
30
30
31
31
EnPassantSpec = Literal ["legal" , "fen" , "xfen" ]
@@ -1455,7 +1455,7 @@ def apply_transform(self, f: Callable[[Bitboard], Bitboard]) -> None:
1455
1455
self .occupied = f (self .occupied )
1456
1456
self .promoted = f (self .promoted )
1457
1457
1458
- def transform (self : BaseBoardT , f : Callable [[Bitboard ], Bitboard ]) -> BaseBoardT :
1458
+ def transform (self , f : Callable [[Bitboard ], Bitboard ]) -> Self :
1459
1459
"""
1460
1460
Returns a transformed copy of the board (without move stack)
1461
1461
by applying a bitboard transformation function.
@@ -1473,11 +1473,11 @@ def transform(self: BaseBoardT, f: Callable[[Bitboard], Bitboard]) -> BaseBoardT
1473
1473
board .apply_transform (f )
1474
1474
return board
1475
1475
1476
- def apply_mirror (self : BaseBoardT ) -> None :
1476
+ def apply_mirror (self ) -> None :
1477
1477
self .apply_transform (flip_vertical )
1478
1478
self .occupied_co [WHITE ], self .occupied_co [BLACK ] = self .occupied_co [BLACK ], self .occupied_co [WHITE ]
1479
1479
1480
- def mirror (self : BaseBoardT ) -> BaseBoardT :
1480
+ def mirror (self ) -> Self :
1481
1481
"""
1482
1482
Returns a mirrored copy of the board (without move stack).
1483
1483
@@ -1491,7 +1491,7 @@ def mirror(self: BaseBoardT) -> BaseBoardT:
1491
1491
board .apply_mirror ()
1492
1492
return board
1493
1493
1494
- def copy (self : BaseBoardT ) -> BaseBoardT :
1494
+ def copy (self ) -> Self :
1495
1495
"""Creates a copy of the board."""
1496
1496
board = type (self )(None )
1497
1497
@@ -1509,10 +1509,10 @@ def copy(self: BaseBoardT) -> BaseBoardT:
1509
1509
1510
1510
return board
1511
1511
1512
- def __copy__ (self : BaseBoardT ) -> BaseBoardT :
1512
+ def __copy__ (self ) -> Self :
1513
1513
return self .copy ()
1514
1514
1515
- def __deepcopy__ (self : BaseBoardT , memo : Dict [int , object ]) -> BaseBoardT :
1515
+ def __deepcopy__ (self , memo : Dict [int , object ]) -> Self :
1516
1516
board = self .copy ()
1517
1517
memo [id (self )] = board
1518
1518
return board
@@ -1694,7 +1694,7 @@ class Board(BaseBoard):
1694
1694
manipulation.
1695
1695
"""
1696
1696
1697
- def __init__ (self : BoardT , fen : Optional [str ] = STARTING_FEN , * , chess960 : bool = False ) -> None :
1697
+ def __init__ (self , fen : Optional [str ] = STARTING_FEN , * , chess960 : bool = False ) -> None :
1698
1698
BaseBoard .__init__ (self , None )
1699
1699
1700
1700
self .chess960 = chess960
@@ -1786,7 +1786,7 @@ def clear_stack(self) -> None:
1786
1786
self .move_stack .clear ()
1787
1787
self ._stack .clear ()
1788
1788
1789
- def root (self : BoardT ) -> BoardT :
1789
+ def root (self ) -> Self :
1790
1790
"""Returns a copy of the root position."""
1791
1791
if self ._stack :
1792
1792
board = type (self )(None , chess960 = self .chess960 )
@@ -2307,7 +2307,7 @@ def is_repetition(self, count: int = 3) -> bool:
2307
2307
def _push_capture (self , move : Move , capture_square : Square , piece_type : PieceType , was_promoted : bool ) -> None :
2308
2308
pass
2309
2309
2310
- def push (self : BoardT , move : Move ) -> None :
2310
+ def push (self , move : Move ) -> None :
2311
2311
"""
2312
2312
Updates the position with the given *move* and puts it onto the
2313
2313
move stack.
@@ -2428,7 +2428,7 @@ def push(self: BoardT, move: Move) -> None:
2428
2428
# Swap turn.
2429
2429
self .turn = not self .turn
2430
2430
2431
- def pop (self : BoardT ) -> Move :
2431
+ def pop (self ) -> Move :
2432
2432
"""
2433
2433
Restores the previous position and returns the last move from the stack.
2434
2434
@@ -2838,7 +2838,7 @@ def _validate_epd_opcode(self, opcode: str) -> None:
2838
2838
if blacklisted in opcode :
2839
2839
raise ValueError (f"invalid character { blacklisted !r} in epd opcode: { opcode !r} " )
2840
2840
2841
- def _parse_epd_ops (self : BoardT , operation_part : str , make_board : Callable [[], BoardT ]) -> Dict [str , Union [None , str , int , float , Move , List [Move ]]]:
2841
+ def _parse_epd_ops (self , operation_part : str , make_board : Callable [[], Self ]) -> Dict [str , Union [None , str , int , float , Move , List [Move ]]]:
2842
2842
operations : Dict [str , Union [None , str , int , float , Move , List [Move ]]] = {}
2843
2843
state = "opcode"
2844
2844
opcode = ""
@@ -3831,16 +3831,16 @@ def apply_transform(self, f: Callable[[Bitboard], Bitboard]) -> None:
3831
3831
self .ep_square = None if self .ep_square is None else msb (f (BB_SQUARES [self .ep_square ]))
3832
3832
self .castling_rights = f (self .castling_rights )
3833
3833
3834
- def transform (self : BoardT , f : Callable [[Bitboard ], Bitboard ]) -> BoardT :
3834
+ def transform (self , f : Callable [[Bitboard ], Bitboard ]) -> Self :
3835
3835
board = self .copy (stack = False )
3836
3836
board .apply_transform (f )
3837
3837
return board
3838
3838
3839
- def apply_mirror (self : BoardT ) -> None :
3839
+ def apply_mirror (self ) -> None :
3840
3840
super ().apply_mirror ()
3841
3841
self .turn = not self .turn
3842
3842
3843
- def mirror (self : BoardT ) -> BoardT :
3843
+ def mirror (self ) -> Self :
3844
3844
"""
3845
3845
Returns a mirrored copy of the board.
3846
3846
@@ -3855,7 +3855,7 @@ def mirror(self: BoardT) -> BoardT:
3855
3855
board .apply_mirror ()
3856
3856
return board
3857
3857
3858
- def copy (self : BoardT , * , stack : Union [bool , int ] = True ) -> BoardT :
3858
+ def copy (self , * , stack : Union [bool , int ] = True ) -> Self :
3859
3859
"""
3860
3860
Creates a copy of the board.
3861
3861
0 commit comments