-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathboard.py
42 lines (36 loc) · 1.2 KB
/
board.py
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
35
36
37
38
39
40
41
42
from square import Square
from pieces import Piece
from typing import List
class Board:
board: List[List[Square]] = []
size = (8, 8)
def __init__(self) -> None:
self.board = []
for i in range(self.size[0]):
temp = []
for j in range(self.size[1]):
temp.append(Square((i, j)))
self.board.append(temp)
def addPiece(self, piece: Piece):
i, j = piece.position
self.board[i][j].addPiece(piece)
def __str__(self):
board = ""
for row in self.board:
board += "---------------------------------"
board += "\n"
for item in row:
board += str(item)
board += "\n"
board += "---------------------------------"
return board
def board_index(self):
board = ""
for i, _ in enumerate(self.board):
board += "---------------------------------------------------------"
board += "\n"
for j, _ in enumerate(self.board[i]):
board += str(f"|({i}, {j})")
board += "|\n"
board += "---------------------------------------------------------"
return board