-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBoard.py
More file actions
34 lines (29 loc) · 1.6 KB
/
Board.py
File metadata and controls
34 lines (29 loc) · 1.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
from typing import List
from Piece import Color, Piece
from Pieces.Bishop import Bishop
from Pieces.Empty import Empty
from Pieces.King import King
from Pieces.Knight import Knight
from Pieces.Pawn import Pawn
from Pieces.Queen import Queen
from Pieces.Rook import Rook
class Board:
setup = [
[Rook(Color.BLACK), Knight(Color.BLACK), Bishop(Color.BLACK), Queen(Color.BLACK), King(Color.BLACK),
Bishop(Color.BLACK), Knight(Color.BLACK), Rook(Color.BLACK)],
[Pawn(Color.BLACK), Pawn(Color.BLACK), Pawn(Color.BLACK), Pawn(Color.BLACK), Pawn(Color.BLACK),
Pawn(Color.BLACK), Pawn(Color.BLACK), Pawn(Color.BLACK)],
[Empty(), Empty(), Empty(), Empty(), Empty(), Empty(), Empty(), Empty()],
[Empty(), Empty(), Empty(), Empty(), Empty(), Empty(), Empty(), Empty()],
[Empty(), Empty(), Empty(), Empty(), Empty(), Empty(), Empty(), Empty()],
[Empty(), Empty(), Empty(), Empty(), Empty(), Empty(), Empty(), Empty()],
[Pawn(Color.WHITE), Pawn(Color.WHITE), Pawn(Color.WHITE), Pawn(Color.WHITE), Pawn(Color.WHITE),
Pawn(Color.WHITE), Pawn(Color.WHITE), Pawn(Color.WHITE)],
[Rook(Color.WHITE), Knight(Color.WHITE), Bishop(Color.WHITE), Queen(Color.WHITE), King(Color.WHITE),
Bishop(Color.WHITE), Knight(Color.WHITE), Rook(Color.WHITE)]
]
def __init__(self, initial_board: List[List[Piece]] | None = None) -> None:
self.board = self.setup if initial_board is None else initial_board
def __str__(self) -> str:
board_string = '\n'.join(''.join(map(str, row)) for row in self.board)
return f'\n{board_string}\n'