Package org.nlogo.agent

Examples of org.nlogo.agent.Turtle


    context.ip = next;
  }

  public void perform_1(final Context context, double xvalue, double yvalue)
      throws LogoException {
    Turtle turtle = (Turtle) context.agent;
    try {
      turtle.xandycor(turtle.shortestPathX(xvalue),
          turtle.shortestPathY(yvalue));
    } catch (org.nlogo.api.AgentException e) {
      throw new EngineException(context, this,
          I18N.errorsJ().getN("org.nlogo.prim.etc._setxy.pointOutsideWorld", xvalue, yvalue));
    }
    context.ip = next;
View Full Code Here


  public void perform(final Context context) {
    perform_1(context);
  }

  public void perform_1(final Context context) {
    Turtle turtle = (Turtle) context.agent;
    turtle.moveToPatchCenter();
    Patch patch = turtle.getPatchHere();
    double winningValue = Double.MAX_VALUE;
    List<Patch> winners = new ArrayList<Patch>();
    for (AgentSet.Iterator it = patch.getNeighbors4().iterator(); it.hasNext();) {
      Patch tester = (Patch) it.next();
      Object value = tester.getPatchVariable(reference.vn());
      if (!(value instanceof Double)) {
        continue;
      }
      double dvalue = ((Double) value).doubleValue();
      // need to be careful here to handle properly the case where
      // dvalue equals Double.MAX_VALUE - ST 10/11/04, 1/6/07
      if (dvalue <= winningValue) {
        if (dvalue < winningValue) {
          winningValue = dvalue;
          winners.clear();
        }
        winners.add(tester);
      }
    }
    if (!winners.isEmpty() &&
        (!(patch.getPatchVariable(reference.vn()) instanceof Double) ||
            winningValue < ((Double) patch.getPatchVariable(reference.vn())).doubleValue())) {
      Patch winner = winners.get(context.job.random.nextInt(winners.size()));
      turtle.face(winner, true);
      try {
        turtle.moveTo(winner);
      } catch (AgentException ex) {
        // should be impossible
        throw new IllegalStateException(ex);
      }
    }
View Full Code Here

  public void perform(final Context context) {
    perform_1(context);
  }

  public void perform_1(final Context context) {
    Turtle turtle = (Turtle) context.agent;
    turtle.moveToPatchCenter();
    Patch patch = turtle.getPatchHere();
    double winningValue = -Double.MAX_VALUE;
    List<Patch> winners = new ArrayList<Patch>();
    for (AgentSet.Iterator it = patch.getNeighbors().iterator(); it.hasNext();) {
      Patch tester = (Patch) it.next();
      Object value = tester.getPatchVariable(reference.vn());
      if (!(value instanceof Double)) {
        continue;
      }
      double dvalue = ((Double) value).doubleValue();
      // need to be careful here to handle properly the case where
      // dvalue equals - Double.MAX_VALUE - ST 10/11/04, 1/6/07
      if (dvalue >= winningValue) {
        if (dvalue > winningValue) {
          winningValue = dvalue;
          winners.clear();
        }
        winners.add(tester);
      }
    }
    if (!winners.isEmpty() &&
        (!(patch.getPatchVariable(reference.vn()) instanceof Double) ||
            winningValue > ((Double) patch.getPatchVariable(reference.vn())).doubleValue())) {
      Patch winner = winners.get(context.job.random.nextInt(winners.size()));
      turtle.face(winner, true);
      try {
        turtle.moveTo(winner);
      } catch (AgentException ex) {
        // should be impossible
        throw new IllegalStateException(ex);
      }
    }
View Full Code Here

  public void perform(final Context context) {
    perform_1(context);
  }

  public void perform_1(final Context context) {
    Turtle turtle = (Turtle) context.agent;
    turtle.moveToPatchCenter();
    Patch patch = turtle.getPatchHere();
    double winningValue = Double.MAX_VALUE;
    List<Patch> winners = new ArrayList<Patch>();
    for (AgentSet.Iterator it = patch.getNeighbors().iterator(); it.hasNext();) {
      Patch tester = (Patch) it.next();
      Object value = tester.getPatchVariable(reference.vn());
      if (!(value instanceof Double)) {
        continue;
      }
      double dvalue = ((Double) value).doubleValue();
      // need to be careful here to handle properly the case where
      // dvalue equals Double.MAX_VALUE - ST 10/11/04, 1/6/07
      if (dvalue <= winningValue) {
        if (dvalue < winningValue) {
          winningValue = dvalue;
          winners.clear();
        }
        winners.add(tester);
      }
    }
    if (!winners.isEmpty() &&
        (!(patch.getPatchVariable(reference.vn()) instanceof Double) ||
            winningValue < ((Double) patch.getPatchVariable(reference.vn())).doubleValue())) {
      Patch winner = winners.get(context.job.random.nextInt(winners.size()));
      turtle.face(winner, true);
      try {
        turtle.moveTo(winner);
      } catch (AgentException ex) {
        // should be impossible
        throw new IllegalStateException(ex);
      }
    }
View Full Code Here

            "O---", true);
  }

  @Override
  public void perform(final org.nlogo.nvm.Context context) throws LogoException {
    Turtle turtle = argEvalTurtle(context, 0);
    if (turtle.id == -1) {
      throw new EngineException(context, this,
        I18N.errorsJ().getN("org.nlogo.$common.thatAgentIsDead", turtle.classDisplayName()));
    }
    world.observer().setPerspective(PerspectiveJ.RIDE(), turtle);
    world.observer().followDistance(0);
    context.ip = next;
  }
View Full Code Here

  }

  @Override
  public void perform(final Context context)
      throws LogoException {
    Turtle turtle = (Turtle) context.agent;
    turtle.face(argEvalDoubleValue(context, 0),
        argEvalDoubleValue(context, 1),
        false);
    context.ip = next;
  }
View Full Code Here

  }

  @Override
  public void perform(final Context context)
      throws LogoException {
    Turtle turtle = argEvalTurtle(context, 0);
    if (turtle.id == -1) {
      throw new EngineException(context, this,
        I18N.errorsJ().getN("org.nlogo.$common.thatAgentIsDead", turtle.classDisplayName()));
    }
    world.observer().setPerspective(PerspectiveJ.FOLLOW(), turtle);
    // the following code is duplicated in _follow and _followme - ST 6/28/05
    int distance = (int) turtle.size() * 5;
    world.observer()
        .followDistance
            (StrictMath.max(1, StrictMath.min(distance, 100)));
    context.ip = next;
  }
View Full Code Here

  public void perform(final Context context) {
    perform_1(context);
  }

  public void perform_1(final Context context) {
    Turtle turtle = (Turtle) context.agent;
    turtle.moveToPatchCenter();
    Patch patch = turtle.getPatchHere();
    double winningValue = -Double.MAX_VALUE;
    List<Patch> winners = new ArrayList<Patch>();
    for (AgentSet.Iterator it = patch.getNeighbors4().iterator(); it.hasNext();) {
      Patch tester = (Patch) it.next();
      Object value = tester.getPatchVariable(reference.vn());
      if (!(value instanceof Double)) {
        continue;
      }
      double dvalue = ((Double) value).doubleValue();
      // need to be careful here to handle properly the case where
      // dvalue equals - Double.MAX_VALUE - ST 10/11/04, 1/6/07
      if (dvalue >= winningValue) {
        if (dvalue > winningValue) {
          winningValue = dvalue;
          winners.clear();
        }
        winners.add(tester);
      }
    }
    if (!winners.isEmpty() &&
        (!(patch.getPatchVariable(reference.vn()) instanceof Double) ||
            winningValue > ((Double) patch.getPatchVariable(reference.vn())).doubleValue())) {
      Patch winner = winners.get(context.job.random.nextInt(winners.size()));
      turtle.face(winner, true);
      try {
        turtle.moveTo(winner);
      } catch (AgentException ex) {
        // should be impossible
        throw new IllegalStateException(ex);
      }
    }
View Full Code Here

TOP

Related Classes of org.nlogo.agent.Turtle

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.