Esempio n. 1
0
  static void ComputePath(
      Binaryheap1 open,
      state s_goal,
      ArrayList<state> closed,
      state[][] x,
      int goal_x,
      int goal_y) {
    // System.out.println("the call ");
    Integer infinity = Integer.MAX_VALUE;
    int neighbourx[] = new int[] {+1, -1, 0, 0};
    int neighboury[] = new int[] {0, 0, +1, -1};
    int i;
    // System.out.println("m here" +  s_goal.g + "value of" + open.minelement().g);
    while (s_goal.g > open.minelement().g && open.isnull() != true) {
      // System.out.println("m here inside while");
      // System.out.println("m here inside while");
      state min;
      min = open.minelement();
      /*while(x[min.x][min.y].visited !=false)
      {
      	open.delete(0);
      	min = open.minelement();

      }*/
      open.delete(0);

      if (x[min.x][min.y].value == 1) // anwar inserted
      x[min.x][min.y].visited = true;
      open.printheap();
      // closed.add(indexof,min);
      // System.out.println("m herebefore for");

      for (i = 0; i < 4; i++) { // maze-size in if
        if ((neighbourx[i] + min.x < 101)
            && (neighboury[i] + min.y < 101)
            && (neighbourx[i] + min.x >= 0)
            && (neighboury[i] + min.y >= 0)) {
          state succ = x[neighbourx[i] + min.x][neighboury[i] + min.y];
          // System.out.println("first if of ComputePath" + succ.search +"value of counter" +
          // counter);
          if (succ.x == goal_x && succ.y == goal_y) s_goal = succ;
          if (succ.search < counter) {
            succ.g = infinity;
            succ.search = counter;
            // System.out.println("first if of ComputePath-------");

          }
          // System.out.println("first if of ComputePath"+ succ.g+ "another value" + min.g+ "third
          // value"+ min.durl[i]);
          if (succ.g > (min.g) + min.durl[i]) {
            succ.g = min.g + min.durl[i];
            // System.out.println("right now succ is" + succ.x + "y value" + succ.y);
            // System.out.println("right now min is" +  min.x + "gjas" + min.y);
            succ.parent = min;
            // System.out.println("teh parent of index succ is min");

            if (open.find(succ) != 0) open.delete(open.find(succ));
            else { // System.out.println("problem is here");
              succ.f = succ.g + succ.h;
              if (x[succ.x][succ.y].visited != true) open.insert(succ);
              //	System.out.println(" succ.x = " + succ.x + " succ.y = " + succ.y);
            }
          }
          open.printheap();
          // System.out.println("problem is here");
          /*				if(open.find(succ)!=0)
          	open.delete(open.find(succ));
          else
          { 	//System.out.println("problem is here");
          	succ.f = succ.g + succ.h;
          	if(x[succ.x][succ.y].visited != true)
          		open.insert(succ);
          //	System.out.println(" succ.x = " + succ.x + " succ.y = " + succ.y);
          }	*/
        }
        // System.out.println("value of i" + i);
      }
    }
  }