Package org.nlogo.agent

Examples of org.nlogo.agent.Patch


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

  @Override
  public void perform(final Context context) throws LogoException {
    Patch parent = (Patch) context.agent;
    int numberOfTurtles = argEvalIntValue(context, 0);
    org.nlogo.util.MersenneTwisterFast random = context.job.random;
    if (numberOfTurtles > 0) {
      AgentSet agentset =
          new ArrayAgentSet(Turtle.class, numberOfTurtles,
              false, world);
      if (breedName == NO_BREED) {
        for (int i = 0; i < numberOfTurtles; i++) {
          Turtle child = parent.sprout
              (random.nextInt(14), random.nextInt(360), world.turtles());
          agentset.add(child);
          workspace.joinForeverButtons(child);
        }
      } else {
        AgentSet breed = world.getBreed(breedName);
        for (int i = 0; i < numberOfTurtles; i++) {
          Turtle child = parent.sprout
              (random.nextInt(14), random.nextInt(360), breed);
          agentset.add(child);
          workspace.joinForeverButtons(child);
        }
      }
View Full Code Here


  public Object report(Context context) {
    return report_1(context);
  }

  public Object report_1(Context context) {
    Patch patch;
    if (context.agent instanceof Patch) {
      patch = ((Patch) context.agent).getPatchWest();
    } else if (context.agent instanceof Turtle) {
      patch = ((Turtle) context.agent).getPatchHere().getPatchWest();
    } else {
View Full Code Here

  public Object report(Context context) throws LogoException {
    return report_1(context);
  }

  public double report_1(Context context) throws LogoException {
    Patch patch;
    if (context.agent instanceof Turtle) {
      patch = ((Turtle) context.agent).getPatchHere();
    } else {
      patch = (Patch) context.agent;
    }
    double sum = 0;
    for (AgentSet.Iterator it = patch.getNeighbors().iterator(); it.hasNext();) {
      Object value = ((Patch) it.next()).getPatchVariable(vn);
      if (!(value instanceof Double)) {
        throw new EngineException(context, this,
            I18N.errorsJ().getN("org.nlogo.prim.$common.noSumOfListWithNonNumbers",
                Dump.logoObject(value).toString(), TypeNames.name(value)));
View Full Code Here

  public Object report(Context context) {
    return report_1(context);
  }

  public Object report_1(Context context) {
    Patch patch;
    if (context.agent instanceof Patch) {
      patch = ((Patch) context.agent).getPatchSouthEast();
    } else if (context.agent instanceof Turtle) {
      patch = ((Turtle) context.agent).getPatchHere().getPatchSouthEast();
    } else {
View Full Code Here

  public Object report(Context context) {
    return report_1(context);
  }

  public Object report_1(Context context) {
    Patch patch;
    if (context.agent instanceof Patch) {
      patch = ((Patch) context.agent).getPatchNorthEast();
    } else if (context.agent instanceof Turtle) {
      patch = ((Turtle) context.agent).getPatchHere().getPatchNorthEast();
    } else {
View Full Code Here

  // doesn't work at runtime ("Inconsistent stack height") - ST 2/10/09
  @Override
  public Object report(final Context context) throws LogoException {
    double dx = argEvalDoubleValue(context, 0);
    double dy = argEvalDoubleValue(context, 1);
    Patch patch = null;
    try {
      patch = context.agent.getPatchAtOffsets(dx, dy);
    } catch (org.nlogo.api.AgentException e) {
      return Nobody$.MODULE$;
    }
View Full Code Here

    // part 3: construct a new agentset and return it
    if (sourceSet.type() == Patch.class) {
      if (sourceSet != world.patches()) {   //sourceSet is not the entire set of patches
        for (Iterator<Patch> iter = patches.iterator(); iter.hasNext();) {
          Patch patch = iter.next();
          if (sourceSet.contains(patch)) {
            result.add(patch);
          }
        }
      } else //sourceSet is the entire set of patches
        result.addAll(patches);
      }
    } else if (sourceSet.type() == Turtle.class) {
      if (sourceSet != world.turtles()) {  //sourceSet is not the entire set of turtles
        if (world.isBreed(sourceSet)) {  //source set is a breed
          for (Iterator<Patch> iter = patches.iterator(); iter.hasNext();) {
            Patch otherPatch = iter.next();
            for (Turtle tempTurtle : otherPatch.turtlesHere()) {
              if (sourceSet == tempTurtle.getBreed()) {
                result.add(tempTurtle);
              }
            }
          }
        } else //sourceSet not the entire set of turtles and is not a breed
          for (Iterator<Patch> iter = patches.iterator(); iter.hasNext();) {
            Patch otherPatch = iter.next();
            for (Turtle tempTurtle : otherPatch.turtlesHere()) {
              if (sourceSet.contains(tempTurtle)) {
                result.add(tempTurtle);
              }
            }
          }
View Full Code Here

      if (x == null || y == null) {
        throw new EngineException(context, this,
            I18N.errorsJ().getN("org.nlogo.prim.etc._atpoints.invalidListOfPoints", Dump.logoObject(points)));
      }
      try {
        Patch patch = null;
        if (!is3D) {
          patch = agent.getPatchAtOffsets(x.doubleValue(), y.doubleValue());
        } else {
          patch =
              ((org.nlogo.agent.Agent3D) agent).getPatchAtOffsets(x.doubleValue(),
View Full Code Here

  }

  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
View Full Code Here

  }

  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
View Full Code Here

TOP

Related Classes of org.nlogo.agent.Patch

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.