Game Development Reference
In-Depth Information
131. # Returns a list with the player's tile as the first
item, and the computer's tile as the second.
132. tile = ''
133. while not (tile == 'X' or tile == 'O'):
134. print('Do you want to be X or O?')
135. tile = input().upper()
136.
137. # the first element in the tuple is the player's tile,
the second is the computer's tile.
138. if tile == 'X':
139. return ['X', 'O']
140. else:
141. return ['O', 'X']
142.
143.
144. def whoGoesFirst():
145. # Randomly choose the player who goes first.
146. if random.randint(0, 1) == 0:
147. return 'computer'
148. else:
149. return 'player'
150.
151.
152. def playAgain():
153. # This function returns True if the player wants to
play again, otherwise it returns False.
154. print('Do you want to play again? (yes or no)')
155. return input().lower().startswith('y')
156.
157.
158. def makeMove(board, tile, xstart, ystart):
159. # Place the tile on the board at xstart, ystart, and
flip any of the opponent's pieces.
160. # Returns False if this is an invalid move, True if it
is valid.
161. tilesToFlip = isValidMove(board, tile, xstart, ystart)
162.
163. if tilesToFlip == False:
164. return False
165.
166. board[xstart][ystart] = tile
167. for x, y in tilesToFlip:
168. board[x][y] = tile
169. return True
170.
171.
172. def getBoardCopy(board):
173. # Make a duplicate of the board list and return the
duplicate.
174. dupeBoard = getNewBoard()
175.
176. for x in range(8):
177. for y in range(8):
178. dupeBoard[x][y] = board[x][y]
Search WWH ::




Custom Search