예제 #1
0
    def get_player_actions(state, player):
        """Provide for a player and at a state all of his possible actions.

        Args:
            state (YoteState): A state object from the yote game.
            player (int, optional): True if the move is a stealing move. Defaults to False.

        Returns:
            List[YoteAction]: Contains all possible actions for a player at the given state.
        """

        actions = []
        phase = state.phase
        board = state.get_board()

        if phase == 1:
            empty_cells = board.get_all_empty_cells_without_center()
            if empty_cells and state.in_hand[player]:
                for cell in empty_cells:
                    actions.append(
                        SeegaAction(action_type=SeegaActionType.ADD, to=cell))
            return actions
        elif phase == 2:
            player_pieces = board.get_player_pieces_on_board(Color(player))
            for piece in player_pieces:
                moves = SeegaRules.get_effective_cell_moves(state, piece)
                if moves:
                    for move in moves:
                        actions.append(
                            SeegaAction(action_type=SeegaActionType.MOVE,
                                        at=piece,
                                        to=move))
            return actions
예제 #2
0
 def reverse_last_action(self):
     """
     Returns the move that was played last time
     """
     last_action = self.last_action
     reversed_action = SeegaAction(action_type=SeegaActionType.MOVE,
                                   at=last_action['action']['to'],
                                   to=last_action['action']['at'])
     return reversed_action
예제 #3
0
 def reverse_last_move(self, state):
     """
     Returns the move resulting in the previous state, allowing for (boring) self-play
     """
     # TODO use self.last_action instead of state last action (in case last move was performed by opponent)
     last_move = state.get_latest_move()
     next_move = SeegaAction(action_type=SeegaActionType.MOVE,
                             at=last_move['action']['to'],
                             to=last_move['action']['at'])
     return next_move
예제 #4
0
 def get_player_all_cases_actions(state, player):
     if state.phase == 2 and SeegaRules.is_player_stuck(state, player * -1):
         actions = list()
         piece_to_move = SeegaRules.get_unstucked_piece(state, player * -1)
         for piece in piece_to_move:
             moves = SeegaRules.get_effective_cell_moves(state, piece)
             if moves:
                 for move in moves:
                     actions.append(SeegaAction(action_type=SeegaActionType.MOVE, at=piece, to=move))
         return actions
     else:
         return SeegaRules.get_player_actions(state, player)
예제 #5
0
 def _action_from_3D_to_SeegaAction(self, action):
     x, y, z = action
     at = (x, y)
     dx, dy = Action.get_dx(z)
     to = (x + dx, y + dy)
     return SeegaAction(SeegaActionType.MOVE, at=at, to=to)