Package ise.mace.models

Examples of ise.mace.models.Food


   */
  private List<Food> getFoodTypes()
  {
    List<Food> foodArray = new LinkedList<Food>();
    List<Food> foodList = new LinkedList<Food>();
    Food cooperateFood, defectFood;

    //Stores the two sources in an array
    for (Food noms : getConn().availableFoods())
    {
      foodArray.add(noms);
View Full Code Here


    @Override
    public Input handle(Action action, String actorID)
    {
      final Hunt act = (Hunt)action;
      final Food food = dmodel.getFoodById(act.getFoodTypeId());

      // This line gets the agents datamodel
      // Just trust me on that one :P
      final PublicAgentDataModel am = ((AbstractAgent)sim.getPlayer(actorID)).getDataModel();
      if (am.getHuntingTeam() == null)
      {
        Input result;
        if (food.getHuntersRequired() <= 1)
        {
          result = new HuntResult(actorID, food.getNutrition(),
                  food.getNutrition(), dmodel.getTime());
        }
        else
        {
          result = new HuntResult(actorID, 0, 0, dmodel.getTime());
        }
        sim.getPlayer(actorID).enqueueInput(result);
      }
      else
      {
        if (!storedHuntResults.containsKey(am.getHuntingTeam()))
        {
          storedHuntResults.put(am.getHuntingTeam(),
                  new LinkedList<TeamHuntEvent>());
        }
        storedHuntResults.get(am.getHuntingTeam()).add(new TeamHuntEvent(act,
                actorID));
      }
      logger.log(Level.FINE, "Agent {0} hunted {1}{2}", new Object[]
              {
                nameOf(actorID),
                food.getName(),
                am.getHuntingTeam() == null ? " alone." : " with team " + am.getHuntingTeam().hashCode()
              });
      return null;
    }
View Full Code Here

    if (getDataModel().getHuntingTeam() == null) return null;
    List<String> members = this.getDataModel().getHuntingTeam().getMembers();

    //We assume there will only be two food sources (stags/rabbits)
    List<Food> foodArray = new LinkedList<Food>();
    Food suggestedFood, cooperateFood, defectFood, choice;

    //Distinguish between stag (cooperate) and rabbit (defect)
    foodArray = this.getFoodTypes();
    cooperateFood = foodArray.get(0);
    defectFood = foodArray.get(1);

    String groupID = this.getDataModel().getGroupId();
    //If the agent belongs to a group then it can ask for advice
    if (groupID != null && getConn().getGroupById(groupID).getMemberList().size() > 1)
    {
      suggestedFood = this.askAdvice(members);
      if (suggestedFood != null)
      {
        return suggestedFood;
      }
    }

    //If the agent is not in a group or advisor didn't give a definitive answer then hunt
    //according to type
    switch (this.getDataModel().getAgentType())
    {
      //The choice is always to hunt stags
      case AC:
        choice = cooperateFood;
        break;

      //The choice is always to hunt rabbits
      case AD:
        choice = defectFood;
        break;

      // Picks a random stratergy
      case R:
        choice = (uniformRandBoolean() ? cooperateFood : defectFood);
        break;

      //If first time cooperate else imitate what your partner (opponent?) choose the previous time
      case TFT:
        //Get last hunting choice of opponent and act accordingly
        Food opponentPreviousChoice = cooperateFood;

        // TFT makes no sense in a team of 1...
        if (members.size() == 1)
        {
          choice = cooperateFood;
View Full Code Here

      return null;
    }

    //We assume there will only be two food sources (stags/rabbits)
    List<Food> foodArray = new LinkedList<Food>();
    Food cooperateFood, defectFood, choice;

    //Distinguish between stag (cooperate) and rabbit (defect)
    foodArray = this.getFoodTypes();
    cooperateFood = foodArray.get(0);
    defectFood = foodArray.get(1);
View Full Code Here

    String opponentID;
    Map<String, Double> newTrustValue = new HashMap<String, Double>();
    double trust;

    //get what this agent has chosen to hunt in this round
    Food lastHunted = this.getDataModel().getLastHunted();

    //Get the members of the hunting team
    if (this.getDataModel().getHuntingTeam() == null) return null;
    List<String> members = this.getDataModel().getHuntingTeam().getMembers();

    //If agent didn't go hunting or has no team pair then do nothing
    if ((lastHunted == null) || (members.size() < 2)) return null;

    //Find out agent's opponent ID
    if (members.get(0).equals(this.getId()))
    {
      opponentID = members.get(1);

    }
    else
    {
      opponentID = members.get(0);

    }

    //Get agent's trust value for this particular opponent
    //If there is no entry initialise it
    if (this.getDataModel().getTrust(opponentID) != null)
    {
      trust = this.getDataModel().getTrust(opponentID);
    }
    else
    {
      trust = 0.1;
    }

    //If agent hunted stag then check what the opponent did. If betrayed decrease trust
    // otherwise increase it. If the agent hunted rabbit no change in trust
    if (lastHunted.getName().equals("Stag"))
    {
      if (foodHunted == 0) //Agent has been betrayed
      {
        trust = scale(trust, -1, this.uniformRand());
      }
View Full Code Here

   * @param none
   * @return The suggested food type
   */
  private Food askAdvice(List<String> members)
  {
    Food suggestedFood = null;
    String opponentID = null;

    //If the agent has no pair then no advice
    if (members.size() == 1) return null;

View Full Code Here

   */
  private List<Food> getFoodTypes()
  {
    List<Food> foodArray = new LinkedList<Food>();
    List<Food> foodList = new LinkedList<Food>();
    Food cooperateFood, defectFood;

    //Stores the two sources in an array
    for (Food noms : getConn().availableFoods())
    {
      foodArray.add(noms);
View Full Code Here

   * @return The food they choose to hunt
   */
  @Override
  protected Food chooseFood()
  {
    Food bestSoFar = null;

    for (Food noms : getConn().availableFoods())
    {
      if (noms.getHuntersRequired() <= 1)
      {
        if (bestSoFar == null)
        {
          bestSoFar = noms;
        }
        else if (noms.getNutrition() > bestSoFar.getNutrition())
        {
          bestSoFar = noms;
        }
      }
    }
View Full Code Here

TOP

Related Classes of ise.mace.models.Food

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.