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
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
def get_actions(self, world_state: Dict): actions = [] alive_countries = self.get_alive() for i, country in enumerate(self.countries): if not country.alive: continue action = country.get_action(world_state) # Check if attack is valid if helpers.is_valid_action(action, alive_countries): actions.append(action) return actions