/* deleteNodeOfId deletes the node from the list that is holding a polygon with a certain id * Parameter: (int) idToDelete is the id of the polygon being held by the node to be deleted * Return: none */ public void deleteNodeOfId(int idToDelete) { AIFringeSearchNode tempFront = frontOfList; if (frontOfList != null) { if (doesIDMatch(frontOfList.getPolygon().getID(), idToDelete) == true) { frontOfList = frontOfList.getNextNode(); numberOfNodesHeld--; return; } AIFringeSearchNode tempback = tempFront.getNextNode(); while ((tempback.getNextNode() != null) && (doesIDMatch(tempback.getPolygon().getID(), idToDelete) == false)) { tempFront = tempback; tempback = tempFront.getNextNode(); } if (doesIDMatch(tempback.getPolygon().getID(), idToDelete) == true) { tempFront.setNextNode(tempback.getNextNode()); } numberOfNodesHeld--; } }
/* * 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; } }
/* getNodeOnList returns node from list that contains a specified polygon * Parameter: (AIPolygon) polygonToCheck is the polygon being held by the node to be returned * Return: (AIFringeSearchNode) * node on list that is holding polygonToCheck */ public AIFringeSearchNode getNodeOnList(AIPolygon polygonToCheck) { AIFringeSearchNode tempFront = frontOfList; if (tempFront == null) { return(null); } if (doesIDMatch(polygonToCheck.getID(), tempFront.getPolygon().getID()) == true) { return(tempFront); } AIFringeSearchNode tempBack = tempFront.getNextNode(); while ((tempBack != null) && (tempBack.getNextNode() != null) && (doesIDMatch(polygonToCheck.getID(), tempBack.getPolygon().getID()) == false)) { tempFront = tempBack; tempBack = tempFront.getNextNode(); } if (tempBack == null) { return(null); } if (doesIDMatch(polygonToCheck.getID(), tempBack.getPolygon().getID()) == true) { return(tempBack); } return(null); }
/* * 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++; } }