def remove_agent(self, agent: GUIAgent): """ Removes the given agent. :param agent: the agent to remove :return: """ self.index_manager.free_index(agent.overall_index) self.agents.remove(agent) self.update_teams_listwidgets() self.overall_config.set_value(MATCH_CONFIGURATION_HEADER, PARTICIPANT_COUNT_KEY, len(self.agents)) self.overall_config.set_value(PARTICIPANT_CONFIGURATION_HEADER, PARTICIPANT_LOADOUT_CONFIG_KEY, "None", agent.overall_index) if len(self.agents) == 0: return if agent.get_team() == 0: if self.blue_listwidget.count() != 0: self.blue_listwidget.setCurrentRow( self.blue_listwidget.count() - 1) else: self.orange_listwidget.setCurrentRow( self.orange_listwidget.count() - 1) else: if self.orange_listwidget.count() != 0: self.orange_listwidget.setCurrentRow( self.orange_listwidget.count() - 1) else: self.blue_listwidget.setCurrentRow( self.blue_listwidget.count() - 1)
def add_agent(self, overall_index=None, team_index=None): """ Creates the agent using self.agent_class and adds it to the index manager. :param overall_index: The index of the bot in the config file if it already exists. :param team_index: The index of the team to place the agent in :return agent: an Agent (gui_agent) with either given index or a free one, returns None if there is no index given and all indices are occupied """ if overall_index is None: if not self.index_manager.has_free_slots(): return overall_index = self.index_manager.get_new_index() else: self.index_manager.use_index(overall_index) agent = GUIAgent(overall_index=overall_index) if team_index is not None: agent.set_team(team_index) self.agents.append(agent) self.overall_config.set_value(MATCH_CONFIGURATION_HEADER, PARTICIPANT_COUNT_KEY, len(self.agents)) return agent