@Override
  public void eventOccurred(final AuctionEvent event) {
    super.eventOccurred(event);

    if (event instanceof SimulationStartedEvent) {
      minValueDist =
          new Uniform(
              generator.getMinValueMin(),
              generator.getMinValueMax(),
              Galaxy.getInstance().getDefaultTyped(GlobalPRNG.class).getEngine());
      rangeDist =
          new Uniform(
              generator.getRangeMin(),
              generator.getRangeMax(),
              Galaxy.getInstance().getDefaultTyped(GlobalPRNG.class).getEngine());
    } else if (event instanceof GameStartingEvent) {

      final double minValue = minValueDist.nextDouble();
      final double maxValue = minValue + rangeDist.nextDouble();

      setDistribution(
          new Uniform(
              minValue,
              maxValue,
              Galaxy.getInstance().getDefaultTyped(GlobalPRNG.class).getEngine()));
      drawRandomValue();
    }
  }
Ejemplo n.º 2
0
  private void pickSmart() {
    this.buildingFound = false;
    synchronized (ContextManager.randomLock) {
      Collections.shuffle(GlobalVars.burgleMap); // Shuffle the map
      for (Building b : GlobalVars.burgleMap) {
        // TODO: Tune this logic for Objective #2 of the project. Consider game theory or some other
        // type
        //      of SoS decision making process to decide if it is best to travel to burgle location
        // or
        //      prevent other burgles by traveling to less-burgled parts of the map (e.g. replace
        // the 25%
        //      value with "game theory" idea where the cost/benefits are adjusted (trade study) to
        //      analyze behavior on crime
        Uniform uniform = RandomHelper.createUniform(0, 1);
        if (uniform.nextDouble()
            < GlobalVars.probTraveltoRecentCrime) { // 25% chance of traveling near recent crime
          if ((b.jurisdiction == this.jurisdiction) && !(this.burgleMapSave.contains(b))) {
            this.b_pick = b;
            this.route = new Route(this, b.getCoords(), b_pick); // Initialize route to target;
            this.buildingFound = true;
            this.burgleMapSave.add(b);
            break; // stop searching
          }
        }
      }

      if (this.buildingFound == false) {
        pickRandom(); // no previously burgled building exists in memory map for given jurisdiction
      }
    }
  }
Ejemplo n.º 3
0
 @Override
 public double nextDoubleUniform() {
   return uniform.nextDouble();
 }
Ejemplo n.º 4
0
  /**
   * Rain clouds appear with a certain chance, influenced by the weather For every rain cloud in the
   * grid the velocity of every rain object is updated Rain clouds are removed if they have passed a
   * certain time
   */
  @ScheduledMethod(start = 1, interval = 1, priority = 0)
  public void rain() {
    // Let new raingroups appear with a certain chance
    double chance = SimulationParameters.rainProb;
    // The probability of rain appearing decreases if there is already rain in the grid
    if (noRainGroups == 1) chance = (chance / (noRainGroups)) * 0.5;
    if (noRainGroups == 2) chance = (chance / (noRainGroups)) * 0.1;
    if (noRainGroups > 2) chance = (chance / (noRainGroups)) * 0.01;
    double f = urng.nextDouble();
    if (f < chance) {
      // Let rain appear
      int x = rand.nextInt((SimulationParameters.gridSize - 0) + 1);
      int y = rand.nextInt((SimulationParameters.gridSize - 0) + 1);
      int[] newLoc = {x, y};
      // Let new raingroup appear in random location
      RainGroup rg = new RainGroup(ContextUtils.getContext(this), grid, newLoc);
      noRainGroups++;
      rainGroups.add(rg);
    }

    ArrayList<RainGroup> toRemove = new ArrayList<RainGroup>();
    for (RainGroup rg : rainGroups) {
      // Get velocity vector of the rain
      float x = Wind.getWindVelocity().x;
      float y = Wind.getWindVelocity().y;
      Vector2 velRain = new Vector2(x, y);
      velRain.setLength(
          Wind.getWindVelocity().len() * 0.9f); // Rain speed is a bit lower than that of the wind

      List<Rain> toRemove1 = new ArrayList<Rain>();
      // Let rain be carried by the wind
      if (urng.nextDouble() < velRain.len()) {
        for (Rain rain : rg.getRainObjects()) {
          Directions dir = Directions.fromVectorToDir(velRain);
          GridPoint pt = grid.getLocation(rain);
          int cX = pt.getX() + dir.xDiff;
          int cY = pt.getY() + dir.yDiff;

          // If new rain-location is out of borders, delete this rain object
          // In this way the cloud "travels" out of the grid
          if (cX < 0
              || cX >= SimulationParameters.gridSize
              || cY < 0
              || cY >= SimulationParameters.gridSize) {
            toRemove1.add(rain);
          } else grid.moveTo(rain, cX, cY);
        }
      }

      for (Rain r : toRemove1) {
        rg.removeRain(r);
        TreeBuilder.performance.decreaseRainCount();
      }
    }

    // Remove the raingroups from our list which were removed from the context
    for (RainGroup rg : toRemove) {
      rainGroups.remove(rg);
      noRainGroups--;
    }
  }