Package ise.mace.models

Examples of ise.mace.models.Food


    this.randomSeed = seed;
  }

  protected final void addFood(String name, double nutrition, int huntersRequired)
  {
    Food f = new Food(name, nutrition, huntersRequired);
    this.foods.put(f.getId().toString(), f);
  }
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 cooperateFood, defectFood, choice;

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

    AgentType group_type = null;

    //Each group must have a representative in the special group. If this
    //doesn't happen then something wrong is going on!
    if (getConn().getGroupById(this.getDataModel().getName()) == null)
    {
      System.out.println(
              "CANNOT HAPPEN: This Special Agent-Group: " + this.getId() + " [" + this.getDataModel().getName() + "] : is not representing a Group");
      return null;
    }
    else
    {
      //The special agent will follow the strategy decided by the panel of the group it represents
      group_type = this.getConn().getGroupById(this.getDataModel().getName()).getGroupStrategy();
      this.getDataModel().setAgentType(group_type);

      //If the group didn't make any decision (maybe anarchists) then do nothing.
      if (group_type == null)
      {
        //return null;
        group_type = AgentType.NOSTRATEGY;
        return null;
      }
      else
        System.out.println(
                "Type for Agent-Group [" + this.getDataModel().getName() + "] : " + group_type);
    }
    switch (group_type) /////THE0 ADDED
    {
      //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, 0.3);
      }
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

    List<String> members = this.getDataModel().getHuntingTeam().getMembers();
    int teamSize = members.size();
    PublicAgentDataModel player = this.getDataModel();
    PublicAgentDataModel opponent = null;
    Food stag = this.getFoodTypes().get(0);
    Food hare = this.getFoodTypes().get(1);

    if (teamSize > 1)
    {
      int oppIdx = (members.get(0).equals(this.getId())) ? 1 : 0;
      opponent = getConn().getAgentById(members.get(oppIdx));
    }

    boolean hasOpponent = (null != opponent);
    History<Food> opponentHuntingHistory = null;
    boolean opponentLastHuntStag = false;
    double opponentStagStrategy = 0;
    if (hasOpponent)
    {
      opponentHuntingHistory = opponent.getHuntingHistory();

      if (null != opponentHuntingHistory &&
        opponentHuntingHistory.size() > 1)
      {
        Food opponentLastHunt = opponentHuntingHistory.getValue(1);
        opponentLastHuntStag = stag.equals(opponentLastHunt);

        for (int i = 0; i < opponentHuntingHistory.size(); i++)
        {
          Food opponentFood = opponentHuntingHistory.getValue(i);
          if (stag.equals(opponentFood))
          {
            opponentStagStrategy++;
          }
        }
        opponentStagStrategy /= (double)opponentHuntingHistory.size();
      }
    }

    String groupId = player.getGroupId();
    boolean hasGroup = false;
    if (null != groupId &&
      getConn().getGroupById(groupId).getMemberList().size() > 1)
    {
      hasGroup = true;
    }
    boolean suggestedStag = false;
    if (hasGroup)
    {
      String mostTrusted = null;
      double maxTrust = 0;
      for (String member : members)
      {
        Double trust = player.getTrust(member);
        if (null == trust) continue;
        double curTrust = trust.doubleValue();
        if (curTrust < maxTrust) continue;
        maxTrust = trust;
        mostTrusted = member;
      }
      if (null != mostTrusted)
      {
        Food suggested = this.seekAvice(mostTrusted);
        suggestedStag = stag.equals(suggested);
      }
    }

    double happiness = .5;
View Full Code Here

              authCode);
  }

  private void doHuntTurn()
  {
    Food toHunt = chooseFood();

    if (toHunt == null)
    {
      logger.log(Level.WARNING, "Agent {0} did not pick a food to hunt",
              dm.getName());
View Full Code Here

   * @param agentsTeam The team are part of
   * @return What food you want to tell them to hunt
   */
  public Food advise(String agent, HuntingTeam agentsTeam)
  {
    Food advice = giveAdvice(agent, agentsTeam);
    dm.gaveAdvice(agent, advice);
    return advice;
  }
View Full Code Here

  @Override
  protected Food chooseFood()
  {
    HuntingTeam team = this.getDataModel().getHuntingTeam();
    int teamSize = (team != null ? team.getMembers().size() : 1);
    Food bestSoFar = null;

    for (Food noms : getConn().availableFoods())
    {
      if (noms.getHuntersRequired() <= teamSize)
      {
        if (bestSoFar == null)
        {
          bestSoFar = noms;
        }
        else
        {
          if (noms.getNutrition() > bestSoFar.getNutrition())
          {
            bestSoFar = noms;
          }
        }
      }
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
    //Note that in the askAdvice method we examine if an agent has a trust entry for its current opponent
    //If it does then we don't ask for advice since it is not neccessary (asking for advice costs food).
    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

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.