コード例 #1
0
    def do_battle(self):
        ''' Returns True when done, false otherwise '''
        legal_battles = self._create_set_of_legal_battles()
        battle = self.battle(legal_battles)

        if battle:
            tattack, tdefend, num_armies = battle
            legal_battles_to_ids = map(
                lambda (a, d): (a['territory'], d['territory']), legal_battles)
            if ((tattack, tdefend) not in legal_battles_to_ids):
                self._err(AttackError.ILLEGAL_ATTACK(tattack, tdefend))
            else:
                t = utils.get_territory_by_id(
                    tattack, self.player_status['territories'])
                # There must be enough troops to attack
                if num_armies > t['num_armies'] - 1:
                    self._err(
                        AttackError.NOT_ENOUGH_ARMY(tattack, tdefend,
                                                    num_armies))
                # There can't be more than 3 troops attacking
                elif num_armies > 3:
                    self._err(
                        AttackError.TOO_MUCH_ARMY(tattack, tdefend,
                                                  num_armies))
                else:
                    # Everything is valid
                    self.attack(tattack, tdefend, num_armies)
                    time.sleep(config.DELAY_BETWEEN_ACTIONS)
                    self._refresh_state()
                    if utils.get_territory_by_id(
                            tdefend, self.player_status['territories']):
                        print "Conquered"
                        attack_move = (utils.get_territory_by_id(tattack, self.player_status['territories']), \
                            utils.get_territory_by_id(tdefend, self.player_status['territories']), \
                            utils.get_territory_by_id(tattack, self.player_status['territories'])['num_armies'] - 1)
                        sim_score = self.fe.evaluate_action(
                            attack_move, self.map_layout, self.player_status,
                            self.enemy_status)
                        score = features.evaluate_fortify(
                            self.map_layout, self.player_status,
                            self.enemy_status)
                        if sim_score > score:
                            print "ATTACK MOVE!"
                            self.transfer_armies(
                                tattack, tdefend,
                                utils.get_territory_by_id(
                                    tattack, self.player_status['territories'])
                                ['num_armies'] - 1)
            return False
        else:
            return True
コード例 #2
0
ファイル: AIBase.py プロジェクト: jrsun/brisk
    def do_battle(self):
        ''' Returns True when done, false otherwise '''
        legal_battles = self._create_set_of_legal_battles()
        battle = self.battle(legal_battles)

        if battle:
            tattack, tdefend, num_armies = battle
            legal_battles_to_ids = map(lambda (a,d): (a['territory'], d['territory']), legal_battles)
            if ((tattack, tdefend) not in legal_battles_to_ids):
                self._err(AttackError.ILLEGAL_ATTACK(tattack, tdefend))
            else:
                t = utils.get_territory_by_id(tattack, self.player_status['territories'])
                # There must be enough troops to attack
                if num_armies > t['num_armies'] - 1:
                    self._err(AttackError.NOT_ENOUGH_ARMY(tattack, tdefend, num_armies))
                # There can't be more than 3 troops attacking
                elif num_armies > 3:
                    self._err(AttackError.TOO_MUCH_ARMY(tattack, tdefend, num_armies))
                else:
                    # Everything is valid
                    self.attack(tattack, tdefend, num_armies)
                    time.sleep(config.DELAY_BETWEEN_ACTIONS)
                    self._refresh_state()
                    if utils.get_territory_by_id(tdefend, self.player_status['territories']):
                        print "Conquered"
                        attack_move = (utils.get_territory_by_id(tattack, self.player_status['territories']), \
                            utils.get_territory_by_id(tdefend, self.player_status['territories']), \
                            utils.get_territory_by_id(tattack, self.player_status['territories'])['num_armies'] - 1)
                        sim_score = self.fe.evaluate_action(attack_move, self.map_layout, self.player_status, self.enemy_status)
                        score = features.evaluate_fortify(self.map_layout, self.player_status, self.enemy_status)
                        if sim_score > score:
                            print "ATTACK MOVE!"
                            self.transfer_armies(tattack, tdefend, utils.get_territory_by_id(tattack, self.player_status['territories'])['num_armies'] - 1)      
            return False
        else:
            return True
コード例 #3
0
 def evaluate_action(self, action, map_layout, player_status, enemy_status):
     (sim_player_status,
      sim_enemy_status) = self._simulate(action, player_status,
                                         enemy_status)
     return features.evaluate_fortify(map_layout, sim_player_status,
                                      sim_enemy_status)
コード例 #4
0
ファイル: Fortify_Evaluator.py プロジェクト: jrsun/brisk
 def evaluate_action(self, action, map_layout, player_status, enemy_status):
     (sim_player_status, sim_enemy_status) = self._simulate(action, player_status, enemy_status)
     return features.evaluate_fortify(map_layout, sim_player_status, sim_enemy_status)