Package org.nlogo.agent

Examples of org.nlogo.agent.Patch


  public void perform(final Context context) {
    int BURNED_TREES_VAR = world.program().interfaceGlobals().size() + 1;
    int patchCount = world.patches().count();
    boolean any = false;
    for (int i = 0; i < patchCount; i++) {
      Patch patch = world.getPatch(i);
      double pcolor = patch.pcolorDouble();
      if (pcolor > RED_MINUS_FOUR && pcolor < RED_PLUS_ONE) {
        any = true;
        break// in the Logo code, the compiler uses _anywith to get this optimization
      }
    }
    if (!any) {
      context.finished = true;
      return;
    }
    for (int i = 0; i < patchCount; i++) {
      Patch patch = world.getPatch(i);
      // if pcolor = green
      if (patch.pcolorDouble() == GREEN) {
        // set counts (nsum4 fire)
        double counts =
            ((Double) patch.getPatchNorth().variables[FIRE_VAR]).doubleValue() +
                ((Double) patch.getPatchSouth().variables[FIRE_VAR]).doubleValue() +
                ((Double) patch.getPatchEast().variables[FIRE_VAR]).doubleValue() +
                ((Double) patch.getPatchWest().variables[FIRE_VAR]).doubleValue();
        patch.variables[COUNTS_VAR] = Double.valueOf(counts);
      }
    }
    for (int i = 0; i < patchCount; i++) {
      Patch patch = world.getPatch(i);
      double pcolor = patch.pcolorDouble();
      if (pcolor == GREEN) {
        if (((Double) patch.variables[COUNTS_VAR]).doubleValue() > 0) {
          // set fire 1
          patch.variables[FIRE_VAR] = World.ONE;
          // set pcolor red
          patch.pcolorDoubleUnchecked(BOXED_RED);
          // set burned-trees burned-trees + 1
          world.observer().variables[BURNED_TREES_VAR] =
              Double.valueOf
                  (((Double) world.observer().variables
                      [world.program().interfaceGlobals().size()])
                      .doubleValue() + 1);
        }
      } else {
        if (pcolor > RED_MINUS_FOUR && pcolor < RED_PLUS_ONE) {
          // set pcolor pcolor - 0.3
          patch.pcolor(pcolor - 0.3);
        }
      }
    }
    context.ip = next;
  }
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

  }

  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

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.