示例#1
0
  public void trouverVoisinEtMaj(Vecteur point) {
    /* Autour du point (i,j) */
    int x = (int) point.getX();
    int y = (int) point.getY();
    /* Boucle: pour di allant de -1 à 1 et dj allant de -1 à 1 */
    for (int di = -1; di <= 1; di++) {
      for (int dj = -1; dj <= 1; dj++) {
        Vecteur d = new Vecteur(x + di, y + dj);
        /* Eliminer les indices inintéressants (continue) */
        if (di == 0 && dj == 0) {
          continue;
        }
        /* Eliminer les mauvais voisins */
        if (!ToolsTerrain.isRunnable(circuit.getTerrain(d))) {
          continue;
        }

        if ((di + x >= circuit.getHeight())
            || (dj + y >= circuit.getWidth())
            || (di + x < 0)
            || (dj + y < 0)) {
          continue;
        }
        if (dist[x][y] == 0) {
          if (VTools.prodScal(circuit.getDirectionArrivee(), new Vecteur(di, dj)) > 0) {
            continue;
          }
        }
        /* Compare la nouvelle distance avec la distance actuelle */
        int poids = poids(di, dj);
        if (dist[x + di][y + dj] > dist[x][y] + poids) {
          q.remove(d);
          dist[x + di][y + dj] = dist[x][y] + poids;
          q.add(d);
        }
      }
    }
  }