-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathBoard.py
88 lines (74 loc) · 2.94 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
from Box import Box
from Position import Position
class Board:
def __init__(self):
self.board_length = 7
self.coins_for_daddy = 3
self.board = [[Box() for _ in range(self.board_length)] for _ in range(self.board_length)]
self.valid_positions = []
self.loadValidPositions()
self.loadDefaultBoard()
def displayBoard(self):
for row in range(len(self.board)):
for col in range(len(self.board[row])):
box = self.board[row][col]
print_symbol = (box.symbol if box.symbol else "O") if box.is_allowed else "-"
print(print_symbol,end=" ")
print("")
def getBox(self,Position):
if(Position.row>=self.board_length or Position.column>=self.board_length):
return None
else:
return self.board[Position.row][Position.column]
def getBoxFromRowAndColumn(self,row,column):
if(row>=self.board_length or column>=self.board_length):
return None
else:
return self.board[row][column]
'''
loads the used box position in valid_positions
'''
def loadValidPositions(self):
self.valid_positions = []
# first row
self.valid_positions.append(Position(0, 0))
self.valid_positions.append(Position(0, 3))
self.valid_positions.append(Position(0, 6))
# second row
self.valid_positions.append(Position(1, 1))
self.valid_positions.append(Position(1, 3))
self.valid_positions.append(Position(1, 5))
# third row
self.valid_positions.append(Position(2, 2))
self.valid_positions.append(Position(2, 3))
self.valid_positions.append(Position(2, 4))
# fourth row
self.valid_positions.append(Position(3, 0))
self.valid_positions.append(Position(3, 1))
self.valid_positions.append(Position(3, 2))
self.valid_positions.append(Position(3, 4))
self.valid_positions.append(Position(3, 5))
self.valid_positions.append(Position(3, 5))
self.valid_positions.append(Position(3, 6))
# fifth row
self.valid_positions.append(Position(4, 2))
self.valid_positions.append(Position(4, 3))
self.valid_positions.append(Position(4, 4))
# sixth row
self.valid_positions.append(Position(5, 1))
self.valid_positions.append(Position(5, 3))
self.valid_positions.append(Position(5, 5))
# seventh row
self.valid_positions.append(Position(6, 0))
self.valid_positions.append(Position(6, 3))
self.valid_positions.append(Position(6, 6))
'''
making the some of the boxes as usable boxes
'''
def loadDefaultBoard(self):
for poistion in self.valid_positions:
box = self.board[poistion.row][poistion.column]
# making this box can be used one
box.updateIsAllowed()
# b1 = Board()
# b1.displayBoard()