Esempio n. 1
0
 @Override
 public void perform(final org.nlogo.nvm.Context context) {
   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);
   context.ip = next;
 }
 @Override
 public void perform(final Context context) throws LogoException {
   int numberOfTurtles = argEvalIntValue(context, 0);
   if (numberOfTurtles > 0) {
     AgentSet agentset = new ArrayAgentSet(Turtle.class, numberOfTurtles, false, world);
     AgentSet breed = breedName == 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);
       agentset.add(turtle);
       workspace.joinForeverButtons(turtle);
     }
     context.runExclusiveJob(agentset, next);
   }
   context.ip = offset;
 }
Esempio n. 3
0
 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);
     }
   }
   context.ip = next;
 }