fixed the colour that was extracted
This commit is contained in:
parent
baa09135ee
commit
16d107e5ea
@ -4,7 +4,7 @@ from logic.pieces.knight import Knight
|
||||
from logic.pieces.queen import Queen
|
||||
from logic.pieces.rook import Rook
|
||||
from logic.pieces.pawn import Pawn
|
||||
from logic.pieces.piece import Piece
|
||||
from logic.pieces.piece import Colour, Piece
|
||||
from logic.position import Position
|
||||
|
||||
from typing import Type
|
||||
@ -55,9 +55,9 @@ class Board:
|
||||
pos = Position(x, y)
|
||||
piece = Board._piece_class_from_char(c)
|
||||
if c.isupper():
|
||||
ret._white[pos] = piece(pos, Piece.WHITE)
|
||||
ret._white[pos] = piece(pos, Colour.WHITE)
|
||||
else:
|
||||
ret._black[pos] = piece(pos, Piece.BLACK)
|
||||
ret._black[pos] = piece(pos, Colour.BLACK)
|
||||
|
||||
x += 1
|
||||
continue
|
||||
@ -70,9 +70,9 @@ class Board:
|
||||
|
||||
# -- Active colour
|
||||
if position[index] == "w":
|
||||
ret._turn = Piece.WHITE
|
||||
ret._turn = Colour.WHITE
|
||||
elif position[index] == "b":
|
||||
ret._turn = Piece.BLACK
|
||||
ret._turn = Colour.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
|
||||
|
@ -30,21 +30,24 @@ class GUI(View):
|
||||
for y in range(8):
|
||||
for x in range(8):
|
||||
colour = colours[(x + y) % 2]
|
||||
if self.state["selected_piece"] and Position(x, 7-y) in self.state["legal_moves"]:
|
||||
colour = "#ADD8E6" # Highlight legal moves
|
||||
if self.state["selected_piece"]:
|
||||
possible_positions = [move.pos for move in self.state["legal_moves"]]
|
||||
if Position(x, 7-y) in possible_positions:
|
||||
colour = "#ADD8E6" # Highlight legal moves
|
||||
|
||||
self.canvas.create_rectangle(
|
||||
x * self.tile_size,
|
||||
y * self.tile_size,
|
||||
(x + 1) * self.tile_size,
|
||||
(y + 1) * self.tile_size,
|
||||
fill=colour
|
||||
fill=colour,
|
||||
outline=colour,
|
||||
)
|
||||
|
||||
piece = self.board.piece_at(x, 7-y)
|
||||
|
||||
if piece:
|
||||
text_colour = "white" if piece.colour == Piece.WHITE else "black"
|
||||
text_colour = "white" if piece.colour == Colour.WHITE else "black"
|
||||
self.canvas.create_text(
|
||||
(x + 0.5) * self.tile_size,
|
||||
(y + 0.5) * self.tile_size,
|
||||
|
Loading…
x
Reference in New Issue
Block a user