Exemple #1
0
    /*
     * 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;
        }
    }
Exemple #2
0
 /*
  * StartSearch method will start the fringe search. It will get the first polygon that the search starts in and then
  *      it will start the search
  * Parameter:	none
  * Return:	none
  */
 public void startSearch()
 {
     fringeList = new AIFringeSearchList(goalPosition);
     for (int count = 0; count < polygonArray.Length; count++)         // looks for the polygon with the agent GameObject inside it
     {
         if (polygonArray [count].getHasAgent() == true)
         {
             fringeList.enqueue(polygonArray [count], null, 0);          //adds the first polygon to the openList
             cache[count]    = fringeList.getNodeOnList(polygonArray[count]);
             startingPolygon = polygonArray[count];
             count           = polygonArray.Length;
         }
     }
     fringeSearch();             //does the AStar search
     printFinalSolution();       //prints the finalSolution for debugging
     addFinalSolutionPolygons(); //adds the finalsolution to the finalsolution array
 }