fixed FEN reading for castling writes

This commit is contained in:
Karma Riuk 2025-01-31 16:33:56 +01:00
parent 2e27e7b703
commit 13e3675665

View File

@ -1,4 +1,4 @@
from logic.move import Move from logic.move import CastleSide, Move
from logic.pieces.bishop import Bishop from logic.pieces.bishop import Bishop
from logic.pieces.king import King from logic.pieces.king import King
from logic.pieces.knight import Knight from logic.pieces.knight import Knight
@ -76,7 +76,7 @@ class Board:
ret._turn = Colour.BLACK ret._turn = Colour.BLACK
else: else:
raise ValueError(f"The FEN position is malformed, the active colour should be either 'w' or 'b', but is '{position[index]}'") raise ValueError(f"The FEN position is malformed, the active colour should be either 'w' or 'b', but is '{position[index]}'")
index += 1 index += 2
# -- Castling Rights # -- Castling Rights
@ -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(Board.KING_SIDE_CASTLE) ret._white_castling_write.add(CastleSide.King)
if c == "Q": if c == "Q":
ret._white_castling_write.add(Board.QUEEN_SIDE_CASTLE) ret._white_castling_write.add(CastleSide.Queen)
if c == "k": if c == "k":
ret._black_castling_write.add(Board.KING_SIDE_CASTLE) ret._black_castling_write.add(CastleSide.King)
if c == "q": if c == "q":
ret._black_castling_write.add(Board.QUEEN_SIDE_CASTLE) ret._black_castling_write.add(CastleSide.Queen)
# -- En passant target # -- En passant target
if position[index] != "-": if position[index] != "-":