/*
  * searchStart method will begin the search by first setting the first node in the open list, which holds the
  *      polygon that has the agent GameObject in it, then it will call the functions to do the search, build the
  *      finalSolution array, and set the wayPoints
  *	Parameters:	none
  *	Return:	none
  */
 public void startSearch()
 {
     openList = new AIAgentAStarSearchListOp(goalPosition, polygonArray.Length);
     for (int count = 0; count < polygonArray.Length; count++)         // looks for the polygon with the agent GameObject inside it
     {
         if (polygonArray [count].getHasAgent() == true && polygonArray[count].getAgentID() == 1)
         {
             openList.addNode(polygonArray [count], null, 0);          //adds the first polygon to the openList
             count = polygonArray.Length;
         }
     }
     AStarSearch();              //does the AStar search
     printFinalSolution();       //prints the finalSolution for debugging
     addFinalSolutionPolygons(); //adds the finalsolution to the finalsolution array
 }
Beispiel #2
0
 /*
  * AIBiDirectionalAStartAgentOp's constructor will set up the initial values for instance variables
  * Parameters:	(Vector3)goalPositionToAdd is the position that the goal this search is looking for is at
  *              (AIPolygon[])polygonsToAdd is the array of polygons that it will search through
  *              (bool)isBackwardsToAdd is the bool to tell if this search is going from the goal or from the agent
  */
 public AIBiDirectionalAStarAgentOp(Vector3 goalPositionToAdd, AIPolygon[] polygonsToAdd, bool isBackwardsToAdd)
 {
     polygonArray      = polygonsToAdd;
     goalPosition      = goalPositionToAdd;
     isBackwards       = isBackwardsToAdd;
     polygonFinalCount = 0;
     maxQueueSize      = 0;
     nodesVisited      = 0;
     openList          = new AIAgentAStarSearchListOp(goalPosition, polygonArray.Length);
     closedList        = new AIAgentAStarSearchNode[polygonArray.Length];
     for (int count = 0; count < polygonArray.Length; count++)
     {
         closedList [count] = null;
     }
     if (isBackwards == true)                                      //going from the goal
     {
         for (int count = 0; count < polygonArray.Length; count++) // looks for the polygon with the agent GameObject inside it
         {
             if (polygonArray [count].getHasGoal() == true)
             {
                 openList.addNode(polygonArray [count], null, 0);              //adds the first polygon to the openList
                 count = polygonArray.Length;
             }
         }
     }
     else                                                          //going from the agent
     {
         for (int count = 0; count < polygonArray.Length; count++) // looks for the polygon with the agent GameObject inside it
         {
             if (polygonArray [count].getHasAgent() == true)
             {
                 openList.addNode(polygonArray [count], null, 0);              //adds the first polygon to the openList
                 count = polygonArray.Length;
             }
         }
     }
     gCost = 0f;
 }