minor fixes

This commit is contained in:
Karma Riuk 2025-01-29 16:55:54 +01:00
parent 06f78487d9
commit ffe76b161a
2 changed files with 7 additions and 6 deletions

View File

@ -41,6 +41,7 @@ class Board:
@staticmethod
def setup_FEN_position(position: str) -> "Board":
ret = Board()
index = 0
# -- Pieces
pieces = "prnbqk" # possible pieces
@ -49,6 +50,7 @@ class Board:
x = 0
y = 7 # FEN starts from the top left, so 8th rank
for c in position:
index += 1
if c == " ":
break
if c in pieces or c in pieces.upper():
@ -69,18 +71,18 @@ class Board:
# -- Active colour
index = position.find(" ") # find the first space
index += 1
if position[index] == "w":
ret._turn = Piece.WHITE
elif position[index] == "b":
ret._turn = Piece.BLACK
else:
raise ValueError(f"The FEN position is malformed, the active colour should be either 'w' or 'b', but is '{position[index]}'")
index += 1
# -- Castling Rights
for c in position:
for c in position[index:]:
index += 1
if c == "-" or c == " ":
break
@ -96,7 +98,6 @@ class Board:
ret._black_castling_write.add(Board.QUEEN_SIDE_CASTLE)
# -- En passant target
index = position.find(" ", index + 1)
if position[index] != "-":
ret._en_passant_target = position[index:index+2]

View File

@ -1,9 +1,9 @@
from logic.board import Board, create_board
from logic.board import Board
from view.gui import GUI
from view.tui import TUI
if __name__ == "__main__":
initial_board_position = "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w"
initial_board_position = "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1"
board = Board.setup_FEN_position(initial_board_position)
view = GUI(board)