Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def next_move(self):
- """Return a (possibly empty) list of legal moves for current player.
- Assumptions:
- The list will be empty if either player has already won, and
- the order of moves in the list is not significant
- Returns:
- A list of pairs of legal moves of the form (r, c) such that
- self._state[0][r][c] is currently unoccupied and the current player
- may move by occupying it.
- """
- move_list = []
- player = self._state[1]
- opponent = self.opponent()
- if self.winner(player):
- return move_list
- if self.winner(opponent):
- return move_list
- for i in range(len(self._state[0])):
- for b in range(len(self._state[0][i])):
- if self._state[0][i][b]== None:
- move_list.append((i,b))
- return move_list
- def make_move(self, move):
- """Apply move to current game.
- Arguments:
- move: A pair (r, c) representing square self._state[0][r][c]
- Assumptions:
- (r, c) are valid coordinates for self._state[0]. If they represent
- a valid move for current player, then the current player occupies
- that position and the opponent becomes the current player.
- Otherwise self._state is left unchanged.
- Returns:
- New TicTacToe gamestate with move recorded on
- self._state[0] and current player replaced by opponent, if
- this is legal. Otherwise return None.
- """
- if self._state[move[0]][move[1]] != None:
- return None
- else:
- board = copy.deepcopy(self._state[0])
- board[move[0]][move[1]] = self.player()
- opp = self.opponent()
- return TicTacToe((board, opp))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement