Examples of Turtle


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

Examples of org.nlogo.agent.Turtle

  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

Examples of org.nlogo.agent.Turtle

  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

Examples of org.nlogo.agent.Turtle

  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

Examples of org.nlogo.agent.Turtle

            "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

Examples of org.nlogo.agent.Turtle

  }

  @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

Examples of org.nlogo.agent.Turtle

  }

  @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

Examples of org.nlogo.agent.Turtle

  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

Examples of org.nlogo.api.Turtle

  private void updateTurtles(World world, DiffBuffer buf) {
    // turtles, on the other hand, can die, so we move each one to a new
    // map as we encounter it...
    Map<Double, TurtleData> newTurtles = new HashMap<Double, TurtleData>();
    for (Agent a : world.turtles().agents()) {
      Turtle turtle = (Turtle) a;
      TurtleData diffs = updateTurtle(turtle);
      if (diffs != null) {
        buf.addTurtle(diffs);
      }
      TurtleData tmp = turtles.remove(Double.valueOf(turtle.id()));
      newTurtles.put(Double.valueOf(turtle.id()), tmp);
    }
    // now, any turtles left in the old map must have died...
    for (TurtleData turtle : turtles.values()) {
      // so, add a new "dead" TurtleData to the outgoing buffer.
      buf.addTurtle(new TurtleData(turtle.id()));
    }
    // finally, the new map replaces the old one.
    turtles = newTurtles;
  }
View Full Code Here

Examples of org.nlogo.api.Turtle

   * and the observer is not riding this agent). Note: if this agent has a label, the agent will
   * be regarded as "visible".
   */
  boolean agentIsVisible(Agent agent) {
    if (agent instanceof Turtle) {
      Turtle turtle = (Turtle) agent;

      boolean riding_agent = (world.observer().perspective() == PerspectiveJ.RIDE())
          && (world.observer().targetAgent() == turtle);

      return !riding_agent && !turtle.hidden()
        && (turtle.alpha() > 0.0 || turtle.hasLabel());
    } else if (agent instanceof Link) {
      Link link = (Link) agent;
      return !link.hidden() && (link.alpha() > 0.0 || link.hasLabel());
    } else if (agent instanceof Patch3D) {
      // Patch3D supports the alpha variable, so check Patch3D
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.