Exemplo n.º 1
0
  @Override
  public Action effectuer(Humain h) {

    if (nextAction != null) h.getEsprit().getActions().push(nextAction);
    Action a;
    if (comp.compare((double) (h.getAttr().get(attribute)), d)) {
      a = listeActions.get(0).effectuer(h);
    } else {
      a = listeActions.get(1).effectuer(h);
    }
    return a;
  }
Exemplo n.º 2
0
 public Action effectuer(Humain h) {
   int cpt = 1;
   for (int i = 0; i < Configuration.VisionRadius * 2; ++i) {
     for (int j = 0; j < Configuration.VisionRadius * 2; ++j) {
       if (h.getPatchAt(i - Configuration.VisionRadius, j - Configuration.VisionRadius)
           .isMarkPresent("Champ")) {
         h.setCible(h.getPatchAt(i - Configuration.VisionRadius, j - Configuration.VisionRadius));
         break;
       }
     }
   }
   return nextAction;
 }
Exemplo n.º 3
0
  protected void initializeItemsToDraw() {

    ownedCognitons = h.getEsprit().getCognitons();
    allCognitons = new ArrayList<TypeCogniton>();
    plans = new ArrayList<NPlan>();

    for (Cogniton cog : ownedCognitons) {
      allCognitons.add(cog.getCogniton());
    }

    //	allCognitons.addAll(Configuration.cloudCognitons);
    ownedPlans = h.getEsprit().getPlans();
    for (NPlanPondere pl : ownedPlans) {
      plans.add(pl.getPlan());
    }
    for (Group gr : h.getEsprit().getGroups().keySet()) {
      groups.add(gr);
      for (TypeCogniton cog : gr.getArrayListOfCognitonType(h.getEsprit().getGroups().get(gr))) {
        allCognitons.add(cog);
      }
    }
  }
Exemplo n.º 4
0
  protected void initializeDrawing() {
    for (int i = 0; i < allCognitons.size(); i++) {
      afficherCogniton(allCognitons.get(i), 80, 40 + espacement * i);
    }

    for (int i = 0; i < plans.size(); i++) {
      afficherPlan(
          plans.get(i),
          espaceCognitonsPlans,
          40 + espacement * i,
          h.getEsprit().getPlan(plans.get(i)));
    }

    for (int i = 0; i < groups.size(); i++) {
      showGroup(
          groups.get(i),
          h.getEsprit().getGroups().get(groups.get(i)),
          espaceCognitonsPlans * 1.8,
          40 + espacement * i);
    }

    creerLiensInfluence();
    creerLiensConditionnels();
  }
Exemplo n.º 5
0
  public Action effectuer(Humain h) {
    Esprit m = h.getEsprit();

    // Number of turns
    if (m.getActionData(this) == null) {
      h.getEsprit().addTag(myTag);
      m.setActionData(this, turns - 1);
    } else {
      if (m.ownTag(myTag)) {
        m.setActionData(this, (Integer) m.getActionData(this) - 1);
      } else {
        h.getEsprit().cleanActionData(this);
        return nextAction;
      }
    }

    List<Humain> humains = h.humansHereWithTag(compatibleTag);

    // Do the trade
    if (!humains.isEmpty()) {

      Humain target = humains.get((int) Math.floor(humains.size() * Math.random()));

      // Change my inventory
      for (int i = 0; i < nItemToGive; i++) {
        h.getInventaire().deleteObjets(itemToGive, 1);
      }
      for (int i = 0; i < nItemToTake; i++) {
        h.getInventaire().addObjets(itemToTake, 1);
      }

      // Change target inventory
      for (int i = 0; i < nItemToGive; i++) {
        target.getInventaire().addObjets(itemToGive, 1);
      }
      for (int i = 0; i < nItemToTake; i++) {
        target.getInventaire().deleteObjets(itemToTake, 1);
      }

      // Remove the tags
      h.getEsprit().cleanActionData(this);
      h.getEsprit().removeTag(myTag);
      target.getEsprit().removeTag(compatibleTag);
      return listeActions.get(0);

    } else if (m.getActionData(this).equals(0)) {
      h.getEsprit().cleanActionData(this);
      h.getEsprit().removeTag(myTag);
      return listeActions.get(1);
    } else {
      return this;
    }
  }
Exemplo n.º 6
0
  public ArrayList<Patch> AStar(Humain h, Patch cible) {
    int[][] map = new int[h.getWorldWidth()][h.getWorldHeight()];
    int minx = Math.min(cible.x, h.xcor());
    int maxx = Math.max(cible.x, h.xcor());
    int miny = Math.min(cible.y, h.ycor());
    int maxy = Math.max(cible.y, h.ycor());

    int addi = 0;
    int nb = 0;
    int min = 10000;
    for (int l = 0; l < Configuration.terrains.size(); l++) {
      if (Configuration.terrains.get(l).getInfranchissable() == false) {
        nb++;
        addi += Configuration.terrains.get(l).getPassabilite();
        if (Configuration.terrains.get(l).getPassabilite() < min) {
          min = Configuration.terrains.get(l).getPassabilite();
        }
      }
    }
    int defaut = min /*addi/nb*/;
    for (int i = minx - Configuration.VisionRadius * 6;
        i < maxx + Configuration.VisionRadius * 6;
        i++) {
      for (int j = miny - Configuration.VisionRadius * 4;
          j < maxy + Configuration.VisionRadius * 4;
          j++) {
        if (i > 0 && i < h.getWorldWidth() && j > 0 && j < h.getWorldHeight()) {

          map[i][j] = defaut;
        }
      }
    }

    for (int i = 0; i < Configuration.VisionRadius * 2; i++) {
      for (int j = 0; j < Configuration.VisionRadius * 2; j++) {
        //	Color couleur = h.getPatchColorAt(i - h.getVisionRadius(), j - h.getVisionRadius());

        if (h.xcor() + i - Configuration.VisionRadius < h.getWorldWidth()
            && h.ycor() + j - Configuration.VisionRadius < h.getWorldHeight()
            && h.xcor() + i - Configuration.VisionRadius > 0
            && h.ycor() + j - Configuration.VisionRadius > 0) {
          int passabilite =
              Configuration.couleurs_terrains
                  .get(
                      h.getPatchAt(i - Configuration.VisionRadius, j - Configuration.VisionRadius)
                          .getColor())
                  .getPassabilite();
          if (h.smellAt("passage", i - Configuration.VisionRadius, j - Configuration.VisionRadius)
              > 0) {
            map[h.xcor() + i - Configuration.VisionRadius][
                    h.ycor() + j - Configuration.VisionRadius] =
                (int)
                    (passabilite
                        - (passabilite
                            / 2
                            * 1
                            / h.smellAt(
                                "passage",
                                i - Configuration.VisionRadius,
                                j - Configuration.VisionRadius)));
          } else {
            map[h.xcor() + i - Configuration.VisionRadius][
                    h.ycor() + j - Configuration.VisionRadius] =
                passabilite;
          }

          if (h.getPatchAt(i - Configuration.VisionRadius, j - Configuration.VisionRadius)
              .isMarkPresent("Route")) {
            map[h.xcor() + i - Configuration.VisionRadius][
                    h.ycor() + j - Configuration.VisionRadius] =
                map[h.xcor() + i - Configuration.VisionRadius][
                        h.ycor() + j - Configuration.VisionRadius]
                    / 2;
          }

          if (Configuration.couleurs_terrains
                  .get(
                      h.getPatchAt(i - Configuration.VisionRadius, j - Configuration.VisionRadius)
                          .getColor())
                  .getInfranchissable()
              == true) {
            map[h.xcor() + i - Configuration.VisionRadius][
                    h.ycor() + j - Configuration.VisionRadius] =
                Integer.MAX_VALUE;
          }
        }
      }
    }
    /*	for(int i = 0; i < map.length; i++)
    {
    	System.out.print("[");
    	for(int j = 0;j < map[i].length;j++)
    	{
    		if(map[i][j] != 1000)
    		{
    			System.out.print(map[i][j]);
    		}
    	}
    	System.out.println("]");
    }*/
    ArrayList<Noeud> liste_noeud = new ArrayList<Noeud>();
    ArrayList<Noeud> open_list = new ArrayList<Noeud>();
    ArrayList<Noeud> close_list = new ArrayList<Noeud>();
    Noeud noeud = new Noeud(h.getPatch().x, h.getPatch().y, 0, 0);
    noeud.setDistanceRacine(0);
    close_list.add(noeud);
    liste_noeud.add(noeud);
    int cpt = 1;
    for (int i = -1; i < 2; i++) {
      for (int j = -1; j < 2; j++) {
        int x = noeud.getPosX();
        int y = noeud.getPosY();
        if ((x + i < h.getWorldWidth() && x + i > 0)
            && (y + j < h.getWorldHeight() && y + j > 0)
            && (i != 0 || j != 0)
            && map[x + i][y + j] != Integer.MAX_VALUE) {
          Noeud noeu = new Noeud(x + i, y + j, 0, cpt);
          int distanceRacine = map[x + i][y + j];
          noeu.setDistanceRacine(distanceRacine);
          open_list.add(noeu);
          liste_noeud.add(noeu);
          cpt++;
        }
      }
    }
    /*System.out.println("Open_list 1 : ");
    for(int i = 0; i < open_list.size();i++)
    {
    	System.out.println("Noeud : "+open_list.get(i).getId()+" x : "+open_list.get(i).getPosX()+" y : "+open_list.get(i).getPosY()+ " distance : "+open_list.get(i).getDistanceRacine());
    }*/
    Noeud suivant = h.PlusProcheNoeud(open_list, cible);
    if (suivant != null) {
      /*if(suivant.getParent() != noeud.getId())
      {

      	for(int i = 0; i< close_list.size();i++)
      	{
      		if(close_list.get(i).getId() > suivant.getParent())
      		{
      			close_list.remove(i);
      		}
      	}

      }*/
      close_list.add(suivant);
    }
    // System.out.println("close_list 1 : " + close_list);
    noeud = suivant;

    while (noeud != null && (noeud.getPosX() != cible.x || noeud.getPosY() != cible.y)) {
      // System.out.println("Agent : "+h.getID()+" Noeud suivant : "+noeud.getId()+ " x :
      // "+noeud.getPosX()+ " y : "+noeud.getPosY()+ " parent : "+noeud.getParent()+ " x cible :
      // "+cible.x+" y cible : "+cible.y);
      open_list.remove(noeud);
      for (int i = -1; i < 2; i++) {
        for (int j = -1; j < 2; j++) {
          int x = noeud.getPosX();
          int y = noeud.getPosY();
          if ((x + i < h.getWorldWidth() && x + i > 0)
              && (y + j < h.getWorldHeight() && y + j > 0)
              && (i != 0 || j != 0)
              && map[x + i][y + j] != Integer.MAX_VALUE) {
            Noeud noeu = new Noeud(x + i, y + j, noeud.getId(), cpt);
            if (!doublons(open_list, noeu)) {
              int distanceRacine = map[x + i][y + j] + noeud.getDistanceRacine();
              noeu.setDistanceRacine(distanceRacine);
              open_list.add(noeu);
              liste_noeud.add(noeu);
              cpt++;
              //	System.out.println("Nouveau noeud "+noeu.getId()+" x : "+noeu.getPosX() + " y :
              // "+noeu.getPosY());
            }
          }
        }
      }
      suivant = h.PlusProcheNoeud(open_list, cible);
      if (suivant != null) {
        /*if(suivant.getParent() != noeud.getId())
        {

        	for(int i = 0; i< close_list.size();i++)
        	{
        		if(close_list.get(i).getId() > suivant.getParent())
        		{
        			close_list.remove(i);
        		}
        	}

        }*/
        close_list.add(suivant);
      }
      noeud = suivant;
    }

    ArrayList<Patch> liste = new ArrayList<Patch>();

    /*	for(int i = 0;i < close_list.size();i++)
    {
    	int x = close_list.get(i).getPosX();
    	int y = close_list.get(i).getPosY();
    	if(map[x][y] >= Configuration.VitesseEstimeeParDefaut)
    	{
    		return liste;
    	}
    	else
    	{
    		liste.add(0,h.getPatchAt(x - h.position.x, y - h.position.y));
    	}
    }*/
    Noeud nodesui = close_list.get(close_list.size() - 1);
    while (!(nodesui.getPosX() == h.getPatch().x && nodesui.getPosY() == h.getPatch().y)) {
      int x = nodesui.getPosX();
      int y = nodesui.getPosY();
      liste.add(0, h.getPatchAt(x - h.getPatch().x, y - h.getPatch().y));
      nodesui = liste_noeud.get(nodesui.getParent());
    }
    //		System.out.println("Debut ");
    for (int i = 0; i < liste.size(); i++) {
      int x = liste.get(i).x;
      int y = liste.get(i).y;
      if (x > h.xcor() + Configuration.VisionRadius
          || x < h.xcor() - Configuration.VisionRadius
          || y > h.ycor() + Configuration.VisionRadius
          || y < h.ycor() - Configuration.VisionRadius) {

        if (i == 0) {
          // System.out.println("test");

          h.setHeading(Math.random() * 360.);
          h.fd(1);
        }
        //	System.out.println("Fin 1 "+"cible x : "+cible.x+" cible y :"+cible.y);
        return liste;
      }
      //		System.out.println("Pos => x : "+x + " y : "+y);
    }
    //		System.out.println("Pos => x : "+h.xcor() + " y : "+h.ycor());
    //	System.out.println("Fin 2 cible x : "+cible.x+" cible y :"+cible.y);
    return liste;
  }
Exemplo n.º 7
0
  public Action effectuer(Humain h) {

    Patch cible = h.getCible();
    if (h.xcor() != cible.x || h.ycor() != cible.y) {
      if (h.getChemin().isEmpty()) {
        h.face(cible);
        h.getChemin().addAll(AStar(h, cible));
        /*	for(int i = 0; i < h.getChemin().size();i++)
        {
        	h.getChemin().get(i).color = Color.red;
        }*/

      }

      if (h.getChemin() != null && !h.getChemin().isEmpty()) {
        Patch pCible = h.getChemin().get(0);
        h.face(pCible);
      }

      h.fd(1);
      if (h.getChemin() != null && !h.getChemin().isEmpty() && h.getChemin().get(0) != null) {
        h.getChemin().remove(0);
      }
      h.getPatch().incrementPatchVariable("passage", 1.0f);
      if (h.smell("passage") > Configuration.passagesPourCreerRoute && !h.isMarkPresent("Route")) {
        Amenagement_Route troncon = new Amenagement_Route(h.getPatch());
        // this.addAmenagement(troncon);  /*TODO : adapter les amenagements*/
        h.getPatch().dropMark("Route", troncon);
      }
      return this;
    } else {
      return nextAction;
    }
  }
Exemplo n.º 8
0
  public void updateData() {

    try {
      semaphore.acquire();
    } catch (InterruptedException ex) {
      System.out.println(ex);
    }

    groups = new ArrayList<Group>();
    for (Group gr : h.getEsprit().getGroups().keySet()) {
      groups.add(gr);
    }

    // Add cognitons
    for (Cogniton cog : h.getEsprit().getCognitons()) {
      if (!this.cognitonIsDrawn(cog.getCogniton())) {
        this.afficherCogniton(cog.getCogniton(), Math.random() * 400, Math.random() * 400);

        this.gCognitons.get(gCognitons.size() - 1).setOpacite(0.0);
        this.gCognitons
            .get(gCognitons.size() - 1)
            .addAnimation(
                new JJAnimationOpacite(50, gCognitons.get(gCognitons.size() - 1), 0.02, false));

        this.supprimerLiensInfluence();
        this.supprimerLiensConditionnels();
        this.clearTriggerLink();

        creerLiensInfluence();
        creerLiensConditionnels();
        createTriggerLink();
      }
    }
    for (Group gr : groups) {
      for (Cogniton cog : gr.getRolesAndCulturons().get(h.getEsprit().getGroups().get(gr))) {
        if (!this.cognitonIsDrawn(cog.getCogniton())) {
          this.afficherCogniton(cog.getCogniton(), Math.random() * 400, Math.random() * 400);

          this.gCognitons.get(gCognitons.size() - 1).setOpacite(0.0);
          this.gCognitons
              .get(gCognitons.size() - 1)
              .addAnimation(
                  new JJAnimationOpacite(50, gCognitons.get(gCognitons.size() - 1), 0.02, false));

          this.supprimerLiensInfluence();
          this.supprimerLiensConditionnels();
          this.clearTriggerLink();

          creerLiensInfluence();
          creerLiensConditionnels();
          createTriggerLink();
        }
      }
    }

    // Add plans
    for (NPlanPondere pl : h.getEsprit().getPlans()) {
      if (!this.planIsDrawn(pl.getPlan())) {
        this.afficherPlan(pl.getPlan(), Math.random() * 400, Math.random() * 400, pl);

        this.gPlan.get(gPlan.size() - 1).setOpacite(0.0);
        this.gPlan
            .get(gPlan.size() - 1)
            .addAnimation(new JJAnimationOpacite(50, gPlan.get(gPlan.size() - 1), 0.02, false));

        this.supprimerLiensInfluence();
        this.supprimerLiensConditionnels();
        this.clearTriggerLink();

        creerLiensInfluence();
        creerLiensConditionnels();
        createTriggerLink();
      }
    }
    // Remove cognitons
    for (TypeCogniton cog : Configuration.cognitons) {
      if (cog.getType() != TypeDeCogniton.CULTURON
          && this.cognitonIsDrawn(cog)
          && !h.getEsprit().ownCogniton(cog)) {
        this.removeCogniton(cog);

        this.supprimerLiensInfluence();
        this.supprimerLiensConditionnels();
        this.clearTriggerLink();

        creerLiensInfluence();
        creerLiensConditionnels();
        createTriggerLink();
      } else if (cog.getType() == TypeDeCogniton.CULTURON) {
        boolean exist = false;
        for (Group gr : groups) {
          if (gr.roleContainsCulturon(cog, h.getEsprit().getGroups().get(gr))) {
            exist = true;
          }
        }
        if (!exist) {
          this.removeCogniton(cog);

          this.supprimerLiensInfluence();
          this.supprimerLiensConditionnels();
          this.clearTriggerLink();

          creerLiensInfluence();
          creerLiensConditionnels();
          createTriggerLink();
        }
      }
    }
    // Remove plans
    for (NPlan pl : Configuration.plans) {
      if (this.planIsDrawn(pl) && !h.getEsprit().ownPlan(pl)) {
        this.removePlan(pl);

        this.supprimerLiensInfluence();
        this.supprimerLiensConditionnels();
        this.clearTriggerLink();

        creerLiensInfluence();
        creerLiensConditionnels();
        createTriggerLink();
      }
    }
    semaphore.release();
  }
Exemplo n.º 9
0
  @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;
  }