-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathboard.py
94 lines (77 loc) · 2.49 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
from piece import Piece
class Board:
# board = []
# removedPiece = []
selectedPiece = False
selectPieceName = False
def __init__(self, board):
self.board = board
self.removedPiece = [],
# board setter
def setBoard(self, board):
self.board = board
return self
# piece setter
def setSelectedPiece(self, selectedPiece):
self.selectedPiece = selectedPiece
return self
def printBoard(self):
for i in self.board:
print(i)
# returns the coordinates of the piece named
def selectPiece(self, name):
self.selectPieceName = name
x = 0
y = 0
for i in self.board:
for j in i:
if self.board[x][y] == name:
self.selectedPiece = [x, y] # return the coordinates
return self
y += 1
y = 0
x += 1
self.selectedPiece = False
return self # case for if piece not found
# get moves for selected piece
def moves(self):
# case for if no piece is select
if self.selectedPiece == False:
print("No Piece Select")
return
piece = Piece(self.board, self.selectedPiece)
# print(piece.getMoves())
return piece.getMoves()
# updates board with select piece
def move(self, toX, toY):
# case for if no piece is select
if self.selectedPiece == False:
print("No Piece Select")
return
# check if move is available
# move the piece
self.board[toX][toY] = self.board[self.selectedPiece[0]][self.selectedPiece[1]]
self.board[self.selectedPiece[0]][self.selectedPiece[1]] = False
# returns list for all possible moves for piece
def getAllMoves(self, color):
x = 0
y = 0
movesPerPiece = []
for i in self.board:
for j in i:
if str(self.board[x][y])[0] == color:
self.selectedPiece = [x, y] # return the coordinates
board = self.board
selectedPiece = self.selectedPiece
piece = Piece(board, selectedPiece)
moves = piece.getMoves()
movesPerPiece += [[str(self.board[x][y]), moves]]
y += 1
y = 0
x += 1
self.selectedPiece = False
return movesPerPiece
# def getMove
#
# def recursion(self):
# pass