/** @return node that contains the path traveled from start to finish */ protected Node mazeSearch() { Node currNode = this.pq.remove(); // found solution if current node is the on FIN if (this.solution[currNode.getX()][currNode.getY()] == FIN) { return currNode; } exploreMoves(currNode); return mazeSearch(); }
/** * explore the neighbor nodes and add them to the queue if they have not been explored * * @param currNode */ protected void exploreMoves(Node currNode) { int x = currNode.getX(); int y = currNode.getY(); // Add all adjacent nodes that are not WALLS to the list // Left boolean l = checkAndAddNodeToList(currNode, x - 1, y); // Up boolean u = checkAndAddNodeToList(currNode, x, y - 1); // Right boolean r = checkAndAddNodeToList(currNode, x + 1, y); // Down boolean d = checkAndAddNodeToList(currNode, x, y + 1); }
/** execute algorithm and create the solution maze matrix */ public void search() { findStartFin(); this.totalCost = 0; this.expands = 0; Node solNode = mazeSearch(); this.solNode = solNode; this.expands -= this.pq.size(); // backtrack from fin to start while (solNode.getParent() != null) { int x = solNode.getX(); int y = solNode.getY(); this.solution[x][y] = FIN; // MARK THE SOLUTION PATH WITH THE START SYMBOL solNode = solNode.getParent(); this.totalCost++; debugSolution(solNode); } }