Package org.nlogo.agent

Examples of org.nlogo.agent.Turtle


  @Override
  public void perform(final Context context)
      throws LogoException {
    if (context.agent instanceof org.nlogo.agent.Turtle) {
      Turtle turtle = (Turtle) context.agent;
      turtle.face(argEvalDoubleValue(context, 0),
          argEvalDoubleValue(context, 1),
          true);
    } else {
      world.observer().
          face(argEvalDoubleValue(context, 0),
View Full Code Here


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

  public void perform_1(Context context) {
    Turtle turtle = (Turtle) context.agent;
    MutableDouble countdown = (MutableDouble) context.getLet(let);
    double distance = countdown.value();
    double distanceMagnitude = StrictMath.abs(distance);
    if (distanceMagnitude <= org.nlogo.api.Constants.Infinitesimal()) {
      context.ip = next;
      return;
    }
    if (distanceMagnitude <= 1.0) {
      try {
        turtle.jump(distance);
      } catch (AgentException e) { } // NOPMD
      context.ip = next;
    } else {
      int stepDistance = (distance > 0) ? 1 : -1;
      try {
        turtle.jump(stepDistance);
        countdown.value_$eq(countdown.value() - stepDistance);
      } catch (AgentException e) {
        context.ip = next;
      }
    }
View Full Code Here

    return super.toString() + ":" + breedName;
  }

  @Override
  public Object report(final Context context) throws LogoException {
    Turtle target = argEvalTurtle(context, 0);
    AgentSet breed =
        breedName == null
            ? world.links()
            : world.getLinkBreed(breedName);
    mustNotBeUndirected(breed, context);
View Full Code Here

      AgentSet breed =
          breedName == _createorderedturtles.NO_BREED
              ? world.turtles()
              : world.getBreed(breedName);
      for (int i = 0; i < numberOfTurtles; i++) {
        Turtle turtle = world.createTurtle(breed);
        turtle.colorDouble(Double.valueOf(10.0 * i + 5.0));
        turtle.heading((360.0 * i) / numberOfTurtles);
        workspace.joinForeverButtons(turtle);
      }
    }
    context.ip = next;
  }
View Full Code Here

  }

  @Override
  public Object report(final org.nlogo.nvm.Context context) throws LogoException {
    Link link;
    Turtle node;
    if (context.agent instanceof Link) {
      link = (Link) context.agent;
      if (!(context.myself() instanceof Turtle)) {
        throw new EngineException(context, this,
            I18N.errorsJ().get("org.nlogo.prim.etc._otherend.onlyTurtleCanGetLinkEnd"));
      }
      node = (Turtle) context.myself();
    } else {
      node = (Turtle) context.agent;
      if (!(context.myself() instanceof Link)) {
        throw new EngineException(context, this,
            I18N.errorsJ().get("org.nlogo.prim.etc._otherend.onlyLinkCanGetTurtleEnd"));
      }
      link = (Link) context.myself();
    }

    Turtle dest = link.end2();
    Turtle src = link.end1();
    if (dest == node) {
      return src;
    }
    if (src == node) {
      return dest;
View Full Code Here

  @Override
  public Object report(final org.nlogo.nvm.Context context) throws LogoException {
    Object agentOrSet = args[0].report(context);
    List<Turtle> resultList = new ArrayList<Turtle>();
    if (agentOrSet instanceof Turtle) {
      Turtle turtle = (Turtle) agentOrSet;
      if (turtle.id == -1) {
        throw new EngineException(context, this,
          I18N.errorsJ().getN("org.nlogo.$common.thatAgentIsDead", turtle.classDisplayName()));
      }
      addAll(resultList, turtle.getPatchHere().turtlesHere());
    } else if (agentOrSet instanceof Patch) {
      addAll(resultList, ((Patch) agentOrSet).turtlesHere());
    } else if (agentOrSet instanceof AgentSet) {
      AgentSet sourceSet = (AgentSet) agentOrSet;
      if (sourceSet.type() == Turtle.class) {
View Full Code Here

  public AgentSet report_1(Context context, Object agentOrSet)
      throws LogoException {
    List<Turtle> resultList = new ArrayList<Turtle>();
    AgentSet breed = world.getBreed(breedName);
    if (agentOrSet instanceof Turtle) {
      Turtle turtle = (Turtle) agentOrSet;
      if (turtle.id == -1) {
        throw new EngineException(context, this,
          I18N.errorsJ().getN("org.nlogo.$common.thatAgentIsDead", turtle.classDisplayName()));
      }
      for (Turtle t : turtle.getPatchHere().turtlesHere()) {
        if (t.getBreed() == breed) {
          resultList.add(t);
        }
      }
    } else if (agentOrSet instanceof Patch) {
      for (Turtle turtle : ((Patch) agentOrSet).turtlesHere()) {
        if (turtle.getBreed() == breed) {
          resultList.add(turtle);
        }
      }
    } else if (agentOrSet instanceof AgentSet) {
      AgentSet sourceSet = (AgentSet) agentOrSet;
      if (sourceSet.type() == Turtle.class) {
        for (AgentSet.Iterator iter = sourceSet.iterator(); iter.hasNext();) {
          for (Turtle turtle : ((Turtle) iter.next()).getPatchHere().turtlesHere()) {
            if (turtle.getBreed() == breed) {
              resultList.add(turtle);
            }
          }
        }
      } else if (sourceSet.type() == Patch.class) {
        for (AgentSet.Iterator iter = sourceSet.iterator(); iter.hasNext();) {
          for (Turtle turtle : ((Patch) iter.next()).turtlesHere()) {
            if (turtle.getBreed() == breed) {
              resultList.add(turtle);
            }
          }
        }
      }
View Full Code Here

  public AgentSet report_3(Context context, Agent agent)
      throws LogoException {
    List<Turtle> resultList = new ArrayList<Turtle>();
    AgentSet breed = world.getBreed(breedName);
    if (agent instanceof Turtle) {
      Turtle turtle = (Turtle) agent;
      if (turtle.id == -1) {
        throw new EngineException(context, this,
          I18N.errorsJ().getN("org.nlogo.$common.thatAgentIsDead", turtle.classDisplayName()));
      }
      for (Turtle t : turtle.getPatchHere().turtlesHere()) {
        if (t.getBreed() == breed) {
          resultList.add(t);
        }
      }
    } else if (agent instanceof Patch) {
      for (Turtle turtle : ((Patch) agent).turtlesHere()) {
        if (turtle.getBreed() == breed) {
          resultList.add(turtle);
        }
      }
    } else {
      throw new ArgumentTypeException
View Full Code Here

    long id = validLong(idDouble);
    if (id != idDouble) {
      throw new EngineException
          (context, this, idDouble + " is not an integer");
    }
    Turtle turtle = world.getTurtle(id);
    if (turtle == null) {
      return Nobody$.MODULE$;
    }
    return turtle;
  }
View Full Code Here

    if (breed == world.links()) {
      breed.setDirected(true);
    }
    AgentSet edgeset = new org.nlogo.agent.ArrayAgentSet(Link.class, agentset.count(),
        false, world);
    Turtle src = (Turtle) context.agent;
    // We have to shuffle here in order for who number assignment
    // to be random! - ST 3/15/06
    for (AgentSet.Iterator iter = agentset.shufflerator(context.job.random); iter.hasNext();) {
      Turtle dest = (Turtle) iter.next();
      if (world.linkManager.findLinkFrom(src, dest, breed, false) == null) {
        if (src == dest) {
          throw new EngineException
              (context, this,
                  I18N.errorsJ().get("org.nlogo.prim.$common.turtleCantLinkToSelf"));
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.