Advertisement
Guest User

Untitled

a guest
Jul 21st, 2017
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.10 KB | None | 0 0
  1. def make_move(self, move):
  2. """Apply move to current game.
  3.  
  4. Arguments:
  5. move: A pair (r, c) representing square self._state[0][r][c]
  6.  
  7. Assumptions:
  8. (r, c) are valid coordinates for self._state[0]. If they represent
  9. a valid move for current player, then the current player occupies
  10. that position and the opponent becomes the current player.
  11. Otherwise self._state is left unchanged.
  12.  
  13. Returns:
  14. New TicTacToe gamestate with move recorded on
  15. self._state[0] and current player replaced by opponent, if
  16. this is legal. Otherwise return None.
  17. """
  18.  
  19. #If given spot is not valid move, return None
  20. if move not in self.next_move():
  21.  
  22. return None
  23.  
  24. #Otherwise, put current player in that spot and return new gamestate
  25. else:
  26.  
  27. state = list(copy.deepcopy(self._state[0]))
  28. state[move[0]][move[1]] = self.player()
  29. return TicTacToe((tuple(state), self.opponent()))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement