(board, computerTile)
| 484 | |
| 485 | |
| 486 | def getComputerMove(board, computerTile): |
| 487 | # Given a board and the computer's tile, determine where to |
| 488 | # move and return that move as a [x, y] list. |
| 489 | possibleMoves = getValidMoves(board, computerTile) |
| 490 | |
| 491 | # randomize the order of the possible moves |
| 492 | random.shuffle(possibleMoves) |
| 493 | |
| 494 | # always go for a corner if available. |
| 495 | for x, y in possibleMoves: |
| 496 | if isOnCorner(x, y): |
| 497 | return [x, y] |
| 498 | |
| 499 | # Go through all possible moves and remember the best scoring move |
| 500 | bestScore = -1 |
| 501 | for x, y in possibleMoves: |
| 502 | dupeBoard = copy.deepcopy(board) |
| 503 | makeMove(dupeBoard, computerTile, x, y) |
| 504 | score = getScoreOfBoard(dupeBoard)[computerTile] |
| 505 | if score > bestScore: |
| 506 | bestMove = [x, y] |
| 507 | bestScore = score |
| 508 | return bestMove |
| 509 | |
| 510 | |
| 511 | def checkForQuit(): |
no test coverage detected