Ejemplo n.º 1
0
  @ScheduledMethod(start = 1, interval = 1)
  public void step() {
    // get the grid location of this Zombie
    GridPoint pt = grid.getLocation(this);

    // use the GridCellNgh class to create GridCells for
    // the surrounding neighborhood .
    GridCellNgh<Human> nghCreator = new GridCellNgh<Human>(grid, pt, Human.class, 1, 1);
    List<GridCell<Human>> gridCells = nghCreator.getNeighborhood(true);
    SimUtilities.shuffle(gridCells, RandomHelper.getUniform());

    GridPoint pointWithMostHumans = null;
    int maxCount = -1;
    for (GridCell<Human> cell : gridCells) {
      if (cell.size() > maxCount) {
        pointWithMostHumans = cell.getPoint();
        maxCount = cell.size();
      }
    }
    moveTowards(pointWithMostHumans);
    infect();
  }