-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBoardFile.py
63 lines (57 loc) · 2.25 KB
/
BoardFile.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
class Board:
def __init__(self):
self.b = [
['_', '_', '_', '_', '_', '_', '_', '_'],
['_', '_', '_', '_', '_', '_', '_', '_'],
['_', '_', '_', '_', '_', '_', '_', '_'],
['_', '_', '_', 'W', 'B', '_', '_', '_'],
['_', '_', '_', 'B', 'W', '_', '_', '_'],
['_', '_', '_', '_', '_', '_', '_', '_'],
['_', '_', '_', '_', '_', '_', '_', '_'],
['_', '_', '_', '_', '_', '_', '_', '_']
]
def get_scores(self):
count_w = 0
count_b = 0
for i in self.b:
for j in i:
if j == 'W':
count_w += 1
elif j == 'B':
count_b += 1
return count_w, count_b
def diplay_moves(self, board):
for i in board:
for j in i:
print(j,
end=" ") #the end=" " argument in the print function is used to prevent a newline character from being printed after each element, so all elements in the same row are printed on the same line.
print()
def show_available_moves(self, valid_moves):
global i
state = [row[:] for row in self.b] # Create a copy of self.b
counter_row = 0
print(range(8), end=" ")
for move in valid_moves:
i = move[-1]
j = move[-2]
print(i, j)
for row_idx, row in enumerate(state):
for col_idx, column in enumerate(row):
if i == row_idx and j == col_idx:
state[i][j] = "O"
print(" ", end=" ")
for r in range(8):
print(r, end=" ")
print()
for row in state:
print(counter_row, end=" ")
counter_row += 1
for element in row:
print(element, end=" ")
print()
def print_board(self):
for i in self.b:
for j in i:
print(j,
end=" ") #the end=" " argument in the print function is used to prevent a newline character from being printed after each element, so all elements in the same row are printed on the same line.
print()