示例#1
0
 /**
  * Returns the name of an {@link AbstractAgent agent} or {@link AbstractGroupAgent group} based on
  * a given id
  *
  * @param id The id
  * @return The name matched with that id (or null if not located)
  * @see PublicAgentDataModel#getName()
  * @see PublicGroupDataModel#getName()
  */
 String nameOf(String id) {
   if (this.isAgentId(id)) {
     return dmodel.getAgentById(id).getName();
   }
   if (this.isGroupId(id)) {
     return dmodel.getGroupById(id).getName();
   }
   return null;
 }
示例#2
0
  /**
   * Processes the {@link Hunt} actions of {@link AbstractAgent agents} that were hunting as part of
   * {@link HuntingTeam HuntingTeams} whose hunt records were added to {@link #storedHuntResults}
   */
  private void processTeamHunts() {
    for (HuntingTeam team : storedHuntResults.keySet()) {
      // Reorganise each team into what they hunted
      // And who hunted it
      Map<Food, List<String>> hunters = new HashMap<Food, List<String>>();
      for (TeamHuntEvent h : storedHuntResults.get(team)) {
        if (!hunters.containsKey(h.getFood())) {
          hunters.put(h.getFood(), new LinkedList<String>());
        }
        hunters.get(h.getFood()).add(h.getAgent());
      }

      // Now, for each food, see if they got a unit on it
      for (Food f : hunters.keySet()) {
        List<String> agents = hunters.get(f);
        double foodGained;

        int count = 0;
        while ((count + 1) * f.getHuntersRequired() <= agents.size()) {
          ++count;
        }

        foodGained = count * f.getNutrition() / agents.size();

        // Then, for each agent, send the message
        String groupID = dmodel.getAgentById(agents.get(0)).getGroupId();
        if (groupID == null) {
          for (String agent : agents) {
            sim.getPlayer(agent)
                .enqueueInput(new HuntResult(agent, foodGained, foodGained, dmodel.time));
          }
        } else {
          Participant g = sim.getPlayer(groupID);
          for (String agent : agents) {
            g.enqueueInput(new HuntResult(agent, foodGained, 0, dmodel.time));
          }
        }
      }
    }

    storedHuntResults.clear();
  }
示例#3
0
 /**
  * Gets the agent data object associated with a particular id, which is safe for being passed to
  * other agents without giving them too much information
  *
  * @param id The id to search for
  * @return The agent object, or null if not found
  * @see #getAgents()
  */
 PublicAgentDataModel getAgentById(String id) {
   return dmodel.getAgentById(id);
 }