Exemple #1
0
    def evaluate(self, state, details=False):
        """
        The evaluate function returns a value representing the utility function of the board.
        """
        # TODO necessity to make eval fucnction symmetric ??
        is_end = SeegaRules.is_end_game(state)
        captured = state.score[self.ME] - state.score[self.OTHER]
        other_is_stuck = state.phase == 2 and SeegaRules.is_player_stuck(
            state, self.OTHER)
        control_center = state.board.get_cell_color((2, 2)) == self.color

        # weights of liner interpolation of heuristics
        w_end = 100 * (-1 if captured < 0 else (0 if captured == 0 else 1))
        w_capt = 1
        w_stuck = 1
        w_center = 0.6

        random = .001 * np.random.random(
        )  # random is to avoid always taking the first move when there is a draw
        if not details:
            return w_capt * captured + \
                   w_stuck * (1 if other_is_stuck else 0) + \
                   w_end * (1 if is_end else 0) + \
                   w_center * (1 if control_center else 0) + \
                   random
        else:
            return {
                'captured': captured,
                'other_is_stuck': other_is_stuck,
                'is_end': is_end,
                'control_center': control_center
            }
Exemple #2
0
    def make_self_play_move(self, state, fallback_function):
        for action, s in self.successors(state):
            if SeegaRules.is_player_stuck(s, self.OTHER):
                print(" - SELF PLAY MOVE FOUND")
                return action

        print(" - NO SELF PLAY MOVE FOUND, CONTINUE")
        self.repeat_boring_moves = False
        return fallback_function(state)
def is_player_stuck(state, player_id):
    return SeegaRules.is_player_stuck(state, player_id)