minor fixes
This commit is contained in:
parent
06f78487d9
commit
ffe76b161a
@ -41,6 +41,7 @@ class Board:
|
|||||||
@staticmethod
|
@staticmethod
|
||||||
def setup_FEN_position(position: str) -> "Board":
|
def setup_FEN_position(position: str) -> "Board":
|
||||||
ret = Board()
|
ret = Board()
|
||||||
|
index = 0
|
||||||
|
|
||||||
# -- Pieces
|
# -- Pieces
|
||||||
pieces = "prnbqk" # possible pieces
|
pieces = "prnbqk" # possible pieces
|
||||||
@ -49,6 +50,7 @@ class Board:
|
|||||||
x = 0
|
x = 0
|
||||||
y = 7 # FEN starts from the top left, so 8th rank
|
y = 7 # FEN starts from the top left, so 8th rank
|
||||||
for c in position:
|
for c in position:
|
||||||
|
index += 1
|
||||||
if c == " ":
|
if c == " ":
|
||||||
break
|
break
|
||||||
if c in pieces or c in pieces.upper():
|
if c in pieces or c in pieces.upper():
|
||||||
@ -69,18 +71,18 @@ class Board:
|
|||||||
|
|
||||||
|
|
||||||
# -- Active colour
|
# -- Active colour
|
||||||
index = position.find(" ") # find the first space
|
|
||||||
index += 1
|
|
||||||
if position[index] == "w":
|
if position[index] == "w":
|
||||||
ret._turn = Piece.WHITE
|
ret._turn = Piece.WHITE
|
||||||
elif position[index] == "b":
|
elif position[index] == "b":
|
||||||
ret._turn = Piece.BLACK
|
ret._turn = Piece.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
|
||||||
|
|
||||||
|
|
||||||
# -- Castling Rights
|
# -- Castling Rights
|
||||||
for c in position:
|
for c in position[index:]:
|
||||||
|
index += 1
|
||||||
if c == "-" or c == " ":
|
if c == "-" or c == " ":
|
||||||
break
|
break
|
||||||
|
|
||||||
@ -96,7 +98,6 @@ class Board:
|
|||||||
ret._black_castling_write.add(Board.QUEEN_SIDE_CASTLE)
|
ret._black_castling_write.add(Board.QUEEN_SIDE_CASTLE)
|
||||||
|
|
||||||
# -- En passant target
|
# -- En passant target
|
||||||
index = position.find(" ", index + 1)
|
|
||||||
if position[index] != "-":
|
if position[index] != "-":
|
||||||
ret._en_passant_target = position[index:index+2]
|
ret._en_passant_target = position[index:index+2]
|
||||||
|
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
from logic.board import Board, create_board
|
from logic.board import Board
|
||||||
from view.gui import GUI
|
from view.gui import GUI
|
||||||
from view.tui import TUI
|
from view.tui import TUI
|
||||||
|
|
||||||
if __name__ == "__main__":
|
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)
|
board = Board.setup_FEN_position(initial_board_position)
|
||||||
|
|
||||||
view = GUI(board)
|
view = GUI(board)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user