Exemplo n.º 1
0
    def get_healths(has_nukes: bool, own_id: int, world_state: Dict):
        """
        Return a dictionary mapping country ids to their distance.
        """

        future_state = Bot.simulate(own_id, mydeepcopy(world_state))

        healths = {}

        for i in future_state["future_alive"]:
            c = world_state["countries"][i]
            if c["ID"] == own_id:
                continue

            elif (c["Filename"] == "ping_bot"
                    and len(future_state["future_alive"]) > 2):

                if has_nukes and not c["Nukes"]:
                    healths[c["ID"]] = 10000  # Massive priority
                    break
                else:
                    continue

            healths[c["ID"]] = c["Health"]

        return healths
Exemplo n.º 2
0
    def get_action(self, world_state: Dict):
        """ Get the action from the player bot
        """

        action = None
        country_status = self.serialize()

        try:
            action = self.player.action(country_status,
                                        mydeepcopy(world_state))

            if action and action["Type"] == "Attack" and "Weapon" in action:
                action["Source"] = self.id
                action = self._do_action(action)

                assert is_valid_action(action, world_state["countries"])

            else:  # Idle
                action = {}

        except Exception:
            if self.verbose:
                print("Caught exception for", self.name)
                print(traceback.format_exc())

                if action:
                    print("Attempted action:", action)

            return {}

        else:
            return action
Exemplo n.º 3
0
    def get_action(self, world_state: Dict):
        """ Get the action from the player bot
        """

        action = None
        country_status = self.serialize()

        try:
            attack = self.player.action(country_status,
                                        mydeepcopy(world_state))

            if attack:
                attack["Source"] = self.id
                attack = self._do_action(attack)

                action = {"Attack": attack}

                assert is_valid_action(action, world_state["alive_players"])

            else:
                action = {}

        except Exception:
            if self.verbose:
                print("Caught exception for", self.name)
                print(traceback.format_exc())

                if action:
                    print("Attempted action:", action)

            return {}

        else:
            return action
Exemplo n.º 4
0
    def get_action(self, world_state: Dict):
        """ Get the action from the player bot
        """

        country_status = self.serialize()

        try:
            action = self.player.action(country_status, mydeepcopy(world_state))
        except Exception:
            if self.verbose:
                print("Caught exception for", self.name)
                print(traceback.format_exc())
            action = {}

        action["Source"] = self.id
        action = self._do_action(action)

        return action
Exemplo n.º 5
0
 def import_state(self, world_state):
     self.active_weapons = mydeepcopy(world_state["active_weapons"])
     self.countries.import_state(world_state["countries"])
     self.events = mydeepcopy(world_state["events"])