-
Notifications
You must be signed in to change notification settings - Fork 0
/
boardKeeper.py
73 lines (63 loc) · 2.61 KB
/
boardKeeper.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
#setting board tiles
class boardKeeper():
def __init__(self):
row1 = "---------------"
row2 = "---------------"
row3 = "---------------"
row4 = "---------------"
row5 = "---------------"
row6 = "---------------"
row7 = "---------------"
row8 = "---------------"
row9 = "---------------"
row10 = "---------------"
row11 = "---------------"
row12 = "---------------"
row13 = "---------------"
row14 = "---------------"
row15 = "---------------"
self.board = row1 + row2 + row3 + row4 + row5 + row6 + row7 + row8 + row9 + row10 + row11 + row12 + row13 + row14 + row15
def changeBoard(self, letterCombo, spaceCombo):
for (letter, space) in zip(letterCombo, spaceCombo):
self.board = self.board[:space] + letter + self.board[space+1:]
def printBoard(self):
''' Prints the board'''
board = self.board
print('Here is the current board situation.')
for row in range( int(len(board)//15) ):
for column in range(15):
print(board[15*row + column], end = ' ')
print('')
def refreshOccupied(self):
''' Get locations occupied by a letter '''
board = self.board
occupied = []
for spot in range(len(board)):
if board[spot] not in '-23@#':
occupied.append(spot)
return occupied
def refreshAttachments(self):
''' Finds every place where a word could start as attachments'''
board = self.board
attachments = set([])
for i in range(len(board)):
if board[i] not in '-23@#':
row = i//15
column = i%15
# space directions
down = (row-1)*15 + column
up = (row+1)*15 + column
left = row*15 + column-1
right = row*15 + column+1
# attachments are added
if (row != 0) and (board[down] in '-23@#') and (down not in attachments):
attachments.add(down)
if (row != 14) and (board[up] in '-23@#') and (up not in attachments):
attachments.add(up)
if (column != 0) and (board[left] in '-23@#') and (left not in attachments):
attachments.add(left)
if (column != 14) and (board[right] in '-23@#') and (right not in attachments):
attachments.add(right)
if len(attachments) == 0:
attachments.add(112)
return attachments