/* * fringeSearch method will preform the fringe search * Parameter: none * Return: none */ void fringeSearch() { AIFringeSearchNode tempNode = fringeList.getNodeOnList(startingPolygon); // the first polygon in the list fLimit = tempNode.getHCost(); //the first limit AIFringeSearchList curList = fringeList; //the current list that will be looked at AIFringeSearchList nextList = new AIFringeSearchList(goalPosition); //the list that the not good polygons will be put into while (goalFound == false && (curList.isEmpty() == false || nextList.isEmpty() == false)) { fMin = float.MaxValue; //reset the fMin firstMin = false; //reset the firstMin while (curList.isEmpty() == false) //goes until the current list is empty { tempNode = curList.popNode(); nodesVisited++; if (tempNode.getTotalCost() > fLimit) // the node is no good and the limit must be incresed { fMin = getMin(tempNode.getTotalCost(), fMin); nextList.pushAtTheEnd(tempNode); //adds the node at the end of the nextList continue; } if (tempNode.getPolygon().getHasGoal() == true) //goal node was found { finalSolutionStart = tempNode; return; } for (int count = tempNode.getPolygon().getNeighborsHeld() - 1; count >= 0; count--) { AIFringeSearchNode childNode = new AIFringeSearchNode(polygonArray[tempNode.getPolygon().getNeighborAt(count)], tempNode, (tempNode.getGFromStartNode() + (tempNode.getPolygon().getCenterVector() - polygonArray[tempNode.getPolygon().getNeighborAt(count)].getCenterVector()).magnitude), goalPosition); if (tempNode.getParentNode() == null || tempNode.getParentNode().getPolygon().getID() != childNode.getPolygon().getID()) //checks to see if the parentNode is the child node trying to be added in { if (cache[tempNode.getPolygon().getNeighborAt(count)] != null) //checks to see if the polygon has already been seen { if (childNode.getGFromStartNode() >= cache[tempNode.getPolygon().getNeighborAt(count)].getGFromStartNode()) { continue; } } if (curList.isNodeOnList(childNode.getPolygon()) == true) //checks to see if the polygon is already on the list { curList.deleteNodeOfId(childNode.getPolygon().getID()); //deletes the node } curList.enqueue(childNode.getPolygon(), childNode.getParentNode(), childNode.getGFromStartNode()); //adds the node at the front of the current list cache[tempNode.getPolygon().getNeighborAt(count)] = childNode; } } if (curList.getSize() > maxQueueSize) { maxQueueSize = curList.getSize(); } } fLimit = fMin; //sets the new Min AIFringeSearchList tempList = curList; curList = nextList; nextList = tempList; } }
//used for debugging void printFinalSolutionRecursively(AIFringeSearchNode currentNode) { if (currentNode != null) { printFinalSolutionRecursively(currentNode.getParentNode()); polygonFinalCount++; } }
/* * addFinalsolutionPolygons method is a recusive method that will look at the parent of each node passed in until * the node passed in is null, then it will add each Node's polygon to the finalSolutionArray in order * from start until end * Parameter: (AIFringeSearchNode)currentNode is the node that needs to be checked and then have its parent passed * (ref int)counter is the current count of polygons in the FinalSolution array used to access the next index * Return: none */ void addFinalSolutionPolygons(AIFringeSearchNode currentNode, ref int counter) { if (currentNode != null) { addFinalSolutionPolygons(currentNode.getParentNode(), ref counter); finalSolutionArray [counter] = currentNode.getPolygon(); if (counter != 0) { finalPathCost += (finalSolutionArray[counter].getCenterVector() - finalSolutionArray[counter - 1].getCenterVector()).magnitude; } counter++; } }