Package org.timerescue.element.agent

Examples of org.timerescue.element.agent.Agent


   */
  public void run() {
    // TODO Auto-generated method stub
    //See what all agents are up to
    for (Iterator<Agent> iterator = agents.iterator(); iterator.hasNext();) {
      Agent agent =  iterator.next();
      //Sets environment information for all Agents
      //TODO Change the default neighbor radio for the distance perception of the agent     
      sendParametersToAgent(
          getSorroundings(
            agent.getCoordinate(),
            Coordinate.Constants.DEFAULT_NEIGHBOR_RADIO), agent);
      //Ask the agent what to do
      Action action = agent.decide();
      //Executes the action
      executeAction(action);
     
    }

View Full Code Here


       
      }
    }
    //Sent all closer Agents in the map
    for (Iterator<Agent> iterator = agents.iterator(); iterator.hasNext();) {
      Agent agent =  iterator.next();
     
      if (center.isClose(agent.getCoordinate(), distance_sense)){
        information_paramaters.addParamData(Constants.SURROUND_PROPERTY, agent);
      }
    }
    //Add the array to the parameters object
    information_paramaters.addArrayParamData(
View Full Code Here

    for (Iterator<Action> iterator = conditions.iterator(); iterator.hasNext();) {
      Action condition = iterator.next();
      //Agents Loop
      for (Iterator<Agent> agent_iterator = agents.iterator();
          agent_iterator.hasNext();) {
        Agent agent = agent_iterator.next();
        sendParametersToAgent(condition, agent);
      }
    }
  }
View Full Code Here

    return null;
  }

  @Override
  protected InformationParameters executeAgent() {
    Agent target = null, attacker = null;
    int range = 0, target_life, attacker_attack, target_defense, speed;
    PropertyHolder target_property_holder, attacker_property_holder;
    StateHolder target_state_holder, attacker_state_holder;
   
    //Get target and the attacker
    target = getTarget();
    attacker = getAttacker();
    //states holders
    target_state_holder = target.getState_holder();
    attacker_state_holder = attacker.getState_holder();
    //Range
    range = getRange();
    Coordinate target_position = target.getCoordinate(),
        attacker_position = attacker.getCoordinate();
    //Properties
    target_property_holder = target.getProperty_holder();
    attacker_property_holder = attacker.getProperty_holder();
    //TODO Is the target visible?
    int visibility = attacker.getVisibility();
    if(target_position.isClose(attacker_position, visibility)){
      //If the target is close enough for a close range attack
      if (target_position.isClose(attacker_position, range)){
        //Attack the target properties!     
        target_life = target.getLife();     
        if(target_life > 0) {//is it alive?         
          //TODO define a method to obtain the properties casted
          //TODO Define a practical formulas, this is just for testing
          target_defense = target.getArmor();
          attacker_attack = attacker.getStrength()* 2;
          target_life -= attacker_attack - target_defense;
          target.setLife(target_life);
          //Add states       
          target_state_holder.addState(this);
          attacker_state_holder.addState(this);
          return this;
        }else{
          //Remove states if the target is dead
          removeStates();
        }
       
      }else{ //It's too far, lets get closer
        speed = attacker.getSpeed();
        attacker.move(target.getCoordinate(), speed);       
      }
    }else{
      //Remove states if the target is far away
      removeStates();
    }
View Full Code Here

    return null;
  }
 
  @Override
  public boolean removeStates() {
    Agent target = null, attacker = null;
    StateHolder target_state_holder, attacker_state_holder;
    try {
      target = getTarget();
      attacker = getAttacker();
      target_state_holder = target.getState_holder();
      attacker_state_holder = attacker.getState_holder();
      target_state_holder.removeState(this);
      attacker_state_holder.removeState(this);
    } catch (Exception e) {
      // TODO Log this
View Full Code Here

  @Override
  protected InformationParameters executeAgent() {
    // TODO Auto-generated method stub
    try {
      Random seed = new Random();
      Agent wanderer = (Agent)getParam(Constants.Parameter.WANDERER);
      int speed = Integer.parseInt(
          wanderer.getProperty_holder().getCurrentProperty(
              Agent.Constants.Property.SPEED));
      //points toward a random direction
      wanderer.move(
          new Coordinate(seed.nextInt(), seed.nextInt(), seed.nextInt()),
          speed);
    } catch (InvalidPropertyException e) {
      // TODO log this
    }
View Full Code Here

   * @throws java.lang.Exception
   */
  @Before
  public void setUp() throws Exception {
    action = new WanderAction();
    agent = new Agent();
    agent.setCoordinate(0, 0, 0);   
    action.addParamData("WANDERER", agent);
  }
View Full Code Here

TOP

Related Classes of org.timerescue.element.agent.Agent

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.