Game Development Reference
In-Depth Information
279. random.shuffle(possibleMoves)
280.
281. # return a side move, if available
282. for x, y in possibleMoves:
283. if isOnSide(x, y):
284. return [x, y]
285.
286. return getComputerMove(board, tile)
287.
288.
289. def getWorstMove(board, tile):
290. # Return the move that flips the least number of
tiles.
291. possibleMoves = getValidMoves(board, tile)
292.
293. # randomize the order of the possible moves
294. random.shuffle(possibleMoves)
295.
296. # Go through all the possible moves and remember the
best scoring move
297. worstScore = 64
298. for x, y in possibleMoves:
299. dupeBoard = getBoardCopy(board)
300. makeMove(dupeBoard, tile, x, y)
301. score = getScoreOfBoard(dupeBoard)[tile]
302. if score < worstScore:
303. worstMove = [x, y]
304. worstScore = score
305.
306. return worstMove
307.
308.
309. def getCornerWorstMove(board, tile):
310. # Return a corner, a space, or the move that flips the
least number of tiles.
311. possibleMoves = getValidMoves(board, tile)
312.
313. # randomize the order of the possible moves
314. random.shuffle(possibleMoves)
315.
316. # always go for a corner if available.
317. for x, y in possibleMoves:
318. if isOnCorner(x, y):
319. return [x, y]
320.
321. return getWorstMove(board, tile)
322.
323.
324.
325. print('Welcome to Reversi!')
Search WWH ::




Custom Search