fixed giga spelling mistake (it's castling right, not castling write)
This commit is contained in:
parent
e862ab6b0b
commit
1be71bf203
@ -15,8 +15,8 @@ class Board:
|
|||||||
self._white: dict[Position, Piece] = {}
|
self._white: dict[Position, Piece] = {}
|
||||||
self._black: dict[Position, Piece] = {}
|
self._black: dict[Position, Piece] = {}
|
||||||
self._turn = None
|
self._turn = None
|
||||||
self._white_castling_write = set()
|
self._white_castling_rights = set()
|
||||||
self._black_castling_write = set()
|
self._black_castling_rights = set()
|
||||||
self._en_passant_target = None
|
self._en_passant_target = None
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
@ -88,13 +88,13 @@ class Board:
|
|||||||
sides = "kq"
|
sides = "kq"
|
||||||
assert c in sides or c in sides.upper(), f"The FEN position is malformed, the castling rights should be either k or q (both either lower- or upper-case), instead is '{c}'"
|
assert c in sides or c in sides.upper(), f"The FEN position is malformed, the castling rights should be either k or q (both either lower- or upper-case), instead is '{c}'"
|
||||||
if c == "K":
|
if c == "K":
|
||||||
ret._white_castling_write.add(CastleSide.King)
|
ret._white_castling_rights.add(CastleSide.King)
|
||||||
if c == "Q":
|
if c == "Q":
|
||||||
ret._white_castling_write.add(CastleSide.Queen)
|
ret._white_castling_rights.add(CastleSide.Queen)
|
||||||
if c == "k":
|
if c == "k":
|
||||||
ret._black_castling_write.add(CastleSide.King)
|
ret._black_castling_rights.add(CastleSide.King)
|
||||||
if c == "q":
|
if c == "q":
|
||||||
ret._black_castling_write.add(CastleSide.Queen)
|
ret._black_castling_rights.add(CastleSide.Queen)
|
||||||
|
|
||||||
# -- En passant target
|
# -- En passant target
|
||||||
if position[index] != "-":
|
if position[index] != "-":
|
||||||
@ -152,8 +152,8 @@ class Board:
|
|||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def castling_writes_for(self, colour: Colour) -> set[CastleSide]:
|
def castling_rights_for(self, colour: Colour) -> set[CastleSide]:
|
||||||
return self._white_castling_write if colour == Colour.WHITE else self._black_castling_write
|
return self._white_castling_rights if colour == Colour.WHITE else self._black_castling_rights
|
||||||
|
|
||||||
def make_move(self, move: Move) -> "Board":
|
def make_move(self, move: Move) -> "Board":
|
||||||
dest_piece = self.piece_at(move.pos.x, move.pos.y)
|
dest_piece = self.piece_at(move.pos.x, move.pos.y)
|
||||||
@ -166,8 +166,8 @@ class Board:
|
|||||||
ret._white = self._white.copy()
|
ret._white = self._white.copy()
|
||||||
ret._black = self._black.copy()
|
ret._black = self._black.copy()
|
||||||
ret._turn = Colour.WHITE if self._turn == Colour.BLACK else Colour.BLACK
|
ret._turn = Colour.WHITE if self._turn == Colour.BLACK else Colour.BLACK
|
||||||
ret._white_castling_write = self._white_castling_write.copy()
|
ret._white_castling_rights = self._white_castling_rights.copy()
|
||||||
ret._black_castling_write = self._black_castling_write.copy()
|
ret._black_castling_rights = self._black_castling_rights.copy()
|
||||||
|
|
||||||
|
|
||||||
piece = move.piece
|
piece = move.piece
|
||||||
@ -201,22 +201,22 @@ class Board:
|
|||||||
# -- Check for castling rights
|
# -- Check for castling rights
|
||||||
if piece.colour == Colour.WHITE:
|
if piece.colour == Colour.WHITE:
|
||||||
if type(piece) == King:
|
if type(piece) == King:
|
||||||
ret._white_castling_write = set()
|
ret._white_castling_rights = set()
|
||||||
|
|
||||||
if type(piece) == Rook:
|
if type(piece) == Rook:
|
||||||
if piece.pos.x == 0 and CastleSide.Queen in ret._white_castling_write:
|
if piece.pos.x == 0 and CastleSide.Queen in ret._white_castling_rights:
|
||||||
ret._white_castling_write.remove(CastleSide.Queen)
|
ret._white_castling_rights.remove(CastleSide.Queen)
|
||||||
elif piece.pos.x == 7 and CastleSide.King in ret._white_castling_write:
|
elif piece.pos.x == 7 and CastleSide.King in ret._white_castling_rights:
|
||||||
ret._white_castling_write.remove(CastleSide.King)
|
ret._white_castling_rights.remove(CastleSide.King)
|
||||||
else:
|
else:
|
||||||
if type(piece) == King:
|
if type(piece) == King:
|
||||||
ret._black_castling_write = set()
|
ret._black_castling_rights = set()
|
||||||
|
|
||||||
if type(piece) == Rook:
|
if type(piece) == Rook:
|
||||||
if piece.pos.x == 0 and CastleSide.Queen in ret._black_castling_write:
|
if piece.pos.x == 0 and CastleSide.Queen in ret._black_castling_rights:
|
||||||
ret._black_castling_write.remove(CastleSide.Queen)
|
ret._black_castling_rights.remove(CastleSide.Queen)
|
||||||
elif piece.pos.x == 7 and CastleSide.King in ret._black_castling_write:
|
elif piece.pos.x == 7 and CastleSide.King in ret._black_castling_rights:
|
||||||
ret._black_castling_write.remove(CastleSide.King)
|
ret._black_castling_rights.remove(CastleSide.King)
|
||||||
|
|
||||||
|
|
||||||
return ret
|
return ret
|
||||||
|
@ -23,11 +23,11 @@ class King(Piece):
|
|||||||
return self.keep_only_blocking(ret, board)
|
return self.keep_only_blocking(ret, board)
|
||||||
|
|
||||||
# -- Castles
|
# -- Castles
|
||||||
castling_writes = board.castling_writes_for(self.colour)
|
castling_rights = board.castling_rights_for(self.colour)
|
||||||
if len(castling_writes) == 0:
|
if len(castling_rights) == 0:
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
if CastleSide.King in castling_writes:
|
if CastleSide.King in castling_rights:
|
||||||
clear = True
|
clear = True
|
||||||
for dx in range(1, 3):
|
for dx in range(1, 3):
|
||||||
x = self.pos.x + dx
|
x = self.pos.x + dx
|
||||||
@ -45,7 +45,7 @@ class King(Piece):
|
|||||||
if clear:
|
if clear:
|
||||||
ret.append(Move(self, Position(6, self.pos.y), castle_side=CastleSide.King))
|
ret.append(Move(self, Position(6, self.pos.y), castle_side=CastleSide.King))
|
||||||
|
|
||||||
if CastleSide.Queen in castling_writes:
|
if CastleSide.Queen in castling_rights:
|
||||||
clear = True
|
clear = True
|
||||||
for dx in range(1, 3):
|
for dx in range(1, 3):
|
||||||
x = self.pos.x - dx
|
x = self.pos.x - dx
|
||||||
|
Loading…
x
Reference in New Issue
Block a user