Beispiel #1
0
  protected void deplace(AgentFeu iAgentFeu, Model iModel, Integer iDist) {
    Integer deplacementRestant = this.getDeplacement();
    Integer newX, newY, currentX, currentY;
    currentX = newX = this.getX();
    currentY = newY = this.getY();
    while (deplacementRestant > 0) {
      Integer deltaX = currentX - iAgentFeu.getX();
      Integer deltaY = currentY - iAgentFeu.getY();
      int[][] newPosition = new int[4][2];
      int dividerX = Math.abs(deltaX) != 0 ? Math.abs(deltaX) : 1;
      int dividerY = Math.abs(deltaY) != 0 ? Math.abs(deltaY) : 1;
      if ((Math.max(Math.abs(deltaX), Math.abs(deltaY)) == Math.abs(deltaX)) && deltaX != 0) {
        newPosition =
            getNewAbscissePosition(currentX, currentY, deltaX, deltaY, dividerX, dividerY);
      } else if (deltaY != 0) {
        newPosition =
            getNewOrdonneePosition(currentX, currentY, deltaX, deltaY, dividerX, dividerY);
      } else {
        // Le pompier est sur un feu
        return;
      }
      Integer nb_test = 0;

      do {
        Random random = new Random();
        Integer directionProbability = random.nextInt(100) + 1;
        Integer direction;
        int firstProba = ConstantesAgents.REDUCE_HIGHER;
        int secondProba = firstProba + ConstantesAgents.REDUCE_LOWER;
        int thirdProba = secondProba + ConstantesAgents.INCREASE_LOWER;
        int fourthProba = thirdProba + ConstantesAgents.INCREASE_HIGHER;
        if (directionProbability <= firstProba) {
          direction = 0;
        } else if (directionProbability <= secondProba) {
          direction = 1;
        } else if (directionProbability <= thirdProba) {
          direction = 2;
        } else if (directionProbability <= fourthProba) {
          direction = 3;
        } else {
          // La somme des constantes ne fait pas 100%
          return;
        }
        newX = newPosition[direction][0];
        newY = newPosition[direction][1];
        nb_test++;
      } while (!deplacementPossible(iModel, newX, newY)
          && nb_test <= ConstantesAgents.TRY_POSITION);

      if (nb_test <= 4) {
        deplace(iModel, newX, newY);
      } else {
        newX = currentX;
        newY = currentY;
      }
      deplacementRestant--;
    }
    return;
  }
Beispiel #2
0
 private void eteindreFeu(Model iModel, AgentFeu aAgentFeu) {
   this.setFeu(aAgentFeu);
   aAgentFeu.reduceRes(iModel, this.getForce());
 }