Example #1
0
  // Constructor, for the first node, have parent = null;
  public Node_2(int p1X, int p1Y, int p2X, int p2Y, Node_2 expanded, int action) {
    x1 = p1X;
    y1 = p1Y;
    x2 = p2X;
    y2 = p2Y;
    p1HasReached = false;
    p2HasReached = false;
    parent = expanded;

    if (x1 == 148 && y1 == 150 && x2 == 155 && y2 == 149) {
      x1 += 0;
    }

    updateSelfDegree();

    if (parent == null) {
      depth = 0;
      actionPath = new ArrayList<Integer>();
      value = -1;
    } else {
      depth = parent.getDepth() + 1;
      actionPath = ((ArrayList<Integer>) parent.getActionPath().clone());
      actionPath.add(action);

      // Set the value of this node equal to our heuristic rating for it
      value = this.heuristic_2();
    }
    if (parent != null && parent.x1 == p1ExitX && parent.y1 == p1ExitY && parent.selfDegree == 0) {
      x1 += 0;
    }
    if (x1 == p1ExitX && y1 == p1ExitY && selfDegree == 0) {
      x1 += 0;
    }
  }
Example #2
0
 @Override
 public int compareTo(Node_2 n) {
   if (this.getValue() > n.getValue()) {
     return 1;
   } else if (this.getValue() < n.getValue()) {
     return -1;
   } else if (this.getDepth() < n.getDepth()) {
     return 1;
   } else if (this.getDepth() > n.getDepth()) {
     return -1;
   } else {
     return 0;
   }
 }
Example #3
0
 public static void reRunHeuristic(ArrayList<Node_2> set) {
   System.out.println("Degree is now: " + degree);
   ArrayList<Node_2> newSet = new ArrayList<Node_2>();
   for (Node_2 n : set) {
     //			if(n.getValue() > 9999){
     n.value = n.heuristic();
     n.updateSelfDegree();
     newSet.add(n);
     //			} else if (n.getValue() <= degree){
     //				newSet.add(n);
     //			}
   }
   set = newSet;
   System.out.println();
 }
Example #4
0
 public static void addPathCost(Node_2 n, int playerNum, int[][] map1, int[][] map2) {
   int x;
   int y;
   int exitX;
   int exitY;
   int[][] map;
   if (playerNum == 1) {
     x = n.getX1();
     y = n.getY1();
     exitX = p1ExitX;
     exitY = p1ExitY;
     map = map1;
   } else {
     x = n.getX2();
     y = n.getY2();
     exitX = p2ExitX;
     exitY = p2ExitY;
     map = map2;
   }
   int toAdd = 0;
   while (x != exitX && y != exitY) {
     if (x != exitX) {
       if (exitX > x) {
         ++x;
       } else {
         --x;
       }
     }
     if (y != exitY) {
       if (exitY > y) {
         ++y;
       } else {
         --y;
       }
     }
     if (map[y][x] != 0) {
       ++toAdd;
     }
   }
   n.value += toAdd;
   if (playerNum == 1) {
     addPathCost(n, playerNum + 1, map1, map2);
   }
 }
Example #5
0
 public static void addDiff(ArrayList<Node_2> set) {
   reRunHeuristic(set);
   for (Node_2 n : set) {
     n.value += n.calcDiff();
   }
 }