Game Development Reference
In-Depth Information
15 - Reversi
82. break
83. tilesToFlip.append([x, y])
84.
85. board[xstart][ystart] = ' ' # restore the empty space
86. if len(tilesToFlip) == 0: # If no tiles were flipped,
this is not a valid move.
87. return False
88. return tilesToFlip
89.
90.
91. def isOnBoard(x, y):
92. # Returns True if the coordinates are located on the
board.
93. return x >= 0 and x <= 7 and y >= 0 and y <=7
94.
95.
96. def getBoardWithValidMoves(board, tile):
97. # Returns a new board with . marking the valid moves
the given player can make.
98. dupeBoard = getBoardCopy(board)
99.
100. for x, y in getValidMoves(dupeBoard, tile):
101. dupeBoard[x][y] = '.'
102. return dupeBoard
103.
104.
105. def getValidMoves(board, tile):
106. # Returns a list of [x,y] lists of valid moves for the
given player on the given board.
107. validMoves = []
108.
109. for x in range(8):
110. for y in range(8):
111. if isValidMove(board, tile, x, y) != False:
112. validMoves.append([x, y])
113. return validMoves
114.
115.
116. def getScoreOfBoard(board):
117. # Determine the score by counting the tiles. Returns a
dictionary with keys 'X' and 'O'.
118. xscore = 0
119. oscore = 0
120. for x in range(8):
121. for y in range(8):
122. if board[x][y] == 'X':
123. xscore += 1
124. if board[x][y] == 'O':
125. oscore += 1
126. return {'X':xscore, 'O':oscore}
127.
128.
129. def enterPlayerTile():
130. # Let's the player type which tile they want to be.
Search WWH ::




Custom Search