Example #1
0
 /** @param parent the parent to set */
 public void setParent(Node parent) {
   int parentDirectionIndex = -1;
   if (Arrays.asList(forwardChildren).contains(parent)) {
     this.setDirection(NodeDirection.REVERSE);
     parentDirectionIndex = Arrays.asList(forwardChildren).indexOf(parent);
   }
   if (Arrays.asList(reverseChildren).contains(parent)) {
     this.setDirection(NodeDirection.FORWARD);
     parentDirectionIndex = Arrays.asList(reverseChildren).indexOf(parent) + 3;
   }
   if (getTyp() == NodeTyp.Y) {
     parentDirectionIndex = parentDirectionIndex + 6;
   }
   if (parentDirectionIndex < 0 || parentDirectionIndex > 11 || parent == null) {
     parentDirection = ParentDirection.NONE;
   } else {
     parentDirection = ParentDirection.values()[parentDirectionIndex];
   }
   //        System.out.println("index: "+parentDirectionIndex+" enum: "+parentDirection);
   if (parent != null && getTyp() == parent.getTyp()) {
     setStraightCount(parent.getStraightCount() + 1);
   } else {
     setStraightCount(0);
   }
   this.parent = parent;
   changedValue();
 }
Example #2
0
 public int compare(Node o1, Node o2) {
   int ret = 0;
   if (o1.getHeuristicValue() < o2.getHeuristicValue()) {
     ret = -1;
   } else if (o1.getHeuristicValue() > o2.getHeuristicValue()) {
     ret = 1;
   }
   return ret;
 }
Example #3
0
 /** @param direction the direction to set */
 public void setDirection(NodeDirection direction) {
   if (direction != null && getDirection() != direction) {
     Node[] children = getChildren();
     for (Node child : Arrays.asList(children)) {
       if (child != null && child.getParent() == this) {
         child.reset();
       }
     }
   }
   this.direction = direction;
   changedDirection();
 }
 /** Test of run method, of class BreadthFirst. */
 @Test
 public void testRun() {
   System.out.println("run");
   Maze maze = new Maze();
   maze.setStart(maze.getMazeCell(0, 0));
   BreadthFirst instance = new BreadthFirst();
   instance.run(maze);
   MazeCell cell = maze.getStart();
   Node[] nodes = cell.getNodes();
   for (Node node : nodes) {
     if (node != null) {
       assertTrue(0.5 == node.getValue());
     }
   }
 }
Example #5
0
 public String printData() {
   String ret = print() + "\nForwardChildren\n";
   for (Node child : forwardChildren) {
     if (child != null) {
       ret += child.print() + ", ";
     }
   }
   ret += "\nReverseChildren\n";
   for (Node child : reverseChildren) {
     if (child != null) {
       ret += child.print() + ", ";
     }
   }
   ret += "\n";
   return ret;
 }