From ffe76b161a4d5dfa56380c20fce5eeadf1068d81 Mon Sep 17 00:00:00 2001 From: Karma Riuk Date: Wed, 29 Jan 2025 16:55:54 +0100 Subject: [PATCH] minor fixes --- src/logic/board.py | 9 +++++---- src/main.py | 4 ++-- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/logic/board.py b/src/logic/board.py index 38b04a0..024b92e 100644 --- a/src/logic/board.py +++ b/src/logic/board.py @@ -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] diff --git a/src/main.py b/src/main.py index 9a110bd..1c150a3 100644 --- a/src/main.py +++ b/src/main.py @@ -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)