Пример #1
0
 def get_sucessors(self):
     # TODO: consider accuracy, crits, status, move effects, etc. when choosing sucessors
     # TODO: rearrange child order for optimization
     sucessors = []
     #import pdb; pdb.set_trace()
     for a in Action.get_all():
         for b in Action.get_all():
             if self.are_actions_valid(a, b):
                 sucessors.append((a, b, self.mutate(a, b)))
     return sucessors
Пример #2
0
 def get_sucessors(self):
     # TODO: consider accuracy, crits, status, move effects, etc. when choosing sucessors
     # TODO: rearrange child order for optimization
     sucessors = []
     #import pdb; pdb.set_trace()
     for a in Action.get_all():
         for b in Action.get_all():
             if self.are_actions_valid(a, b):
                 sucessors.append((a, b, self.mutate(a, b)))
     return sucessors
Пример #3
0
    def get_next_action(self):
        build_game_tree(self)

        if CONF['debug_level'] >= 2:
            print('Current State: ' + str(self))
            for c in self.children:
                print(
                    'Team1 Move: %s,\nTeam2 Move: %s,\nNew State Value: %f,\nNew State {\n%s\n}'
                    % (Action.to_str(c[0]), Action.to_str(
                        c[1]), c[2].worst_child_val, str(c[2])))

        # choose an action: get the worst value from each possible action of the opponent and group
        # it by move. Then, choose the move with the highest value.
        worst_actions_group_by_a = []
        for a in Action.get_all():
            l = []
            for c in self.children:
                if c[0] == a:
                    l.append((c[2].state.value(), c[2].state))
            worst_actions_group_by_a.append(
                min([c[0] for c in l]) if l else -1.0)

        best_action = 0
        max_val = worst_actions_group_by_a[0]

        for i in range(1, len(worst_actions_group_by_a)):
            if max_val < worst_actions_group_by_a[i]:
                best_action = i
                max_val = worst_actions_group_by_a[i]

        return best_action
Пример #4
0
    def get_next_action(self):
        build_game_tree(self)

        if CONF['debug_level'] >= 1:
            print('Current State: ' + str(self))
            for c in self.children:
                print('Team1 Move: %s,\nTeam2 Move: %s,\nNew State Value: %f,\nNew State {\n%s\n}' % (
                    Action.to_str(c[0]), 
                    Action.to_str(c[1]), 
                    c[2].worst_child_val,
                    str(c[2])))

        # choose an action: get the worst value from each possible action of the opponent and group
        # it by move. Then, choose the move with the highest value.
        worst_actions_group_by_a = []
        for a in Action.get_all():
            l = []
            for c in self.children:
                if c[0] == a:
                    l.append((c[2].state.value(), c[2].state))
            worst_actions_group_by_a.append(
                min([c[0] for c in l]) if l else -1.0
            )

        best_action = 0
        max_val = worst_actions_group_by_a[0]

        for i in range(1, len(worst_actions_group_by_a)):
            if max_val < worst_actions_group_by_a[i]:
                best_action = i
                max_val = worst_actions_group_by_a[i]

        return best_action
Пример #5
0
def random_get_enemy_action(game_tree):
    valid_actions = []
    for a in Action.get_all():
        if game_tree.state.is_action_valid(a, game_tree.state.team2):
            valid_actions.append(a)
    return random.choice(valid_actions)
Пример #6
0
def random_get_enemy_action(game_tree):
    valid_actions = []
    for a in Action.get_all():
        if game_tree.state.is_action_valid(a, game_tree.state.team2):
            valid_actions.append(a)
    return random.choice(valid_actions)