@Override
  public Action effectuer(Humain h) {
    h.setHeading(Math.random() * 360.);
    h.fd(1);

    try {
      Communaute com = h.getNearestTurtle(16, Communaute.class);
      if (com == null) {
        Civilisation civ = h.getCiv().createDaugtherCivilization();
        h.setCiv(civ);
        Communaute c = new Communaute(civ);

        h.setCommunaute(c);
        h.launchAgent(c);
        c.moveTo(h.getX(), h.getY());

        // New city start with two agents for test purpose
        Humain h2 = new Humain(civ, c);
        h.launchAgent(h2);
        h2.moveTo(h.getX(), h.getY());
        Humain h3 = new Humain(civ, c);
        h.launchAgent(h3);
        h3.moveTo(h.getX(), h.getY());

        return nextAction;
      } else {
        return this;
      }
    } catch (Exception e) {
      System.out.println("Concurrent!");
    }
    return this;
  }
Exemple #2
0
  @Override
  public void update() {

    tick++;

    if (tick == 1) {
      /*Install starting civilizations*/
      ArrayList<String[]> listeCivs =
          Initialiseur.getListeChamp(
              "Civilisation",
              new File(
                  Configuration.pathToRessources
                      + "/environnements/"
                      + Configuration.environnementACharger
                      + Configuration.getExtension()));
      for (int i = 0; i < listeCivs.size(); i++) {

        int u = Integer.parseInt(listeCivs.get(i)[1]);
        int v = Integer.parseInt(listeCivs.get(i)[2]);

        Communaute c = new Communaute(Configuration.getCivilisationByName(listeCivs.get(i)[0]));
        TurtleGenerator.getInstance().createTurtle(c);
        c.moveTo(u, -v);
      }
    }

    /* Periodic actions of the environment*/
    if (tick % 150 == 0) {
      for (int xx = 0; xx < x; xx++) {
        for (int yy = 0; yy < y; yy++) {
          Terrain t = Configuration.couleurs_terrains.get(this.getPatch(xx, yy).getColor());
          for (int i = 0; i < t.getPheroCroissance().size(); i++) {
            this.getPatch(xx, yy)
                .dropPheromone(
                    t.getPheromones().get(i).getNom(), t.getPheroCroissance().get(i).floatValue());
          }

          Pheromone ph = this.getPheromone("passage");
          float phVal = ph.get(xx, yy);
          // if (phVal >= 100)  System.out.println(phVal);
          if (phVal > Configuration.EffacementRoute) {
            ph.set(xx, yy, phVal - Configuration.EffacementRoute);
          } else {
            ph.set(xx, yy, 0);
          }
          phVal = ph.get(xx, yy);
          if (this.getPatch(xx, yy).isMarkPresent("Route")
              && phVal < Configuration.EffacementRoute) {
            this.getPatch(xx, yy).getMark("Route");
          }
        }
      }
    }

    exportData();
  }