Exemplo n.º 1
0
    /* updateNode updates the parent of a node and the gFromStartingNodeCost of a node
     * Parameter:	(AIDynBiDirOpNode) nodeToUpdate is the node to be updated
     *              (AIDynBiDirOpNode) newParentNode is the new parent of the node to be updated
     *              (float) newCost is the new gFromStartingNodeCost of the node to be updated
     * Return: none
     */
    public void updateNode(AIDynBiDirOpNode nodeToUpdate, AIDynBiDirOpNode newParentNode, float newCost)
    {
        AIPolygon temp = nodeToUpdate.getPolygon();

        deleteNodeOfId(nodeToUpdate.getPolygon().getID());
        addNode(temp, newParentNode, newCost);
    }
Exemplo n.º 2
0
 /*
  * addFinalsolutionPolygonsPreOrder 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 pre order
  *      from start until end
  * Parameter:	(AIDynBiDirOpNode)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 addFinalSolutionPolygonsPreOrder(AIDynBiDirOpNode currentNode, ref int counter)
 {
     if (currentNode != null)
     {
         finalSolutionArray [counter] = currentNode.getPolygon();
         counter++;
         addFinalSolutionPolygonsPreOrder(currentNode.getParentNode(), ref counter);
     }
 }
Exemplo n.º 3
0
    /* popNode removes and returns the node at the front of the list (node with lowest fToatlCost value)
     * Parameter: none
     * Return: (AIDynBiDirOpNod)
     *				node that was removed from the front of this list
     */
    public AIDynBiDirOpNode popNode()
    {
        if (numberOfNodesHeld == 0)
        {
            return(null);
        }
        AIDynBiDirOpNode tempNode = heap [0];

        indicesArray [tempNode.getPolygon().getID()] = -1;
        numberOfNodesHeld--;
        heap [0] = heap [numberOfNodesHeld];
        indicesArray [heap [0].getPolygon().getID()] = 0;
        if (numberOfNodesHeld > 0)
        {
            shiftDown(0);
        }
        return(tempNode);
    }
Exemplo n.º 4
0
    /*
     * doSearch method will run the A* search till a goal is found, or a node is in another agent closed list, or the
     *      nodes expanded is equal to the nodesToExpand variable
     * Parameter:	(int)nodesToExpand is the number of nodes that the search can expand
     *              (AIDynBiDirOpNode[]) secondSearchClosedList is the closed list from the other agent
     * Return:		(int)
     *                  0 if nothing was found
     *                  1 if the goal for this search agent was found
     *                  2 if a node on the second agent's closed list was found
     */
    public int doSearch(int nodesToExpand, AIDynBiDirOpNode[] secondSearchClosedList)
    {
        int nodesExpandedCount = 0;

        while (openList.isEmpty() == false && nodesExpandedCount < nodesToExpand) //goes until nothing is left on the open list meaning a path could not be found
        {
            currentNode = openList.popNode();                                     //take the first(Best) polygon off the openList
            nodesVisited++;
            if (currentNode == null)
            {
                return(0);
            }
            closedList[currentNode.getPolygon().getID()] = currentNode;
            if (isBackwards == true)
            {
                if (currentNode.getPolygon().getHasAgent() == true)
                {
                    finalSolutionStart = currentNode;
                    return(1);
                }
            }
            else
            {
                if (currentNode.getPolygon().getHasGoal() == true)                //checks to see if the currentNode has the goal inside its polygon
                {
                    finalSolutionStart = currentNode;
                    return(1);
                }
            }
            if (secondSearchClosedList[currentNode.getPolygon().getID()] != null)
            {
                finalSolutionStart = currentNode;
                return(2);
            }
            for (int count = 0; count < currentNode.getPolygon().getNeighborsHeld(); count++)            //adds all the neighbors that are not on the closed list to the open list
            {
                if (closedList[currentNode.getPolygon().getNeighborAt(count)] == null)
                {
                    gCost = (currentNode.getPolygon().getCenterVector() - polygonArray[currentNode.getPolygon().getNeighborAt(count)].getCenterVector()).magnitude + currentNode.getGFromStartingNode();
                    if (openList.isNodeOnList(polygonArray[currentNode.getPolygon().getNeighborAt(count)]) == false)
                    {
                        openList.addNode(polygonArray[currentNode.getPolygon().getNeighborAt(count)], currentNode, gCost);
                    }
                    else if (openList.getNodeOnList(polygonArray[currentNode.getPolygon().getNeighborAt(count)]).compareToG(gCost) > 0f)                    //updates the a Nodes information if the new GCost (cost from start to node) is less then what was previously in it
                    {
                        openList.updateNode(openList.getNodeOnList(polygonArray[currentNode.getPolygon().getNeighborAt(count)]), currentNode, gCost);
                    }
                }
            }
            if (openList.getSize() > maxQueueSize)
            {
                maxQueueSize = openList.getSize();
            }
            nodesExpandedCount++;
        }
        return(0);
    }
Exemplo n.º 5
0
 /*
  * getFinalPathStart method will return the starting polygon of the final solution
  * Parameter:	none
  * Return:	(AIPolygon)
  *              the starting polygon of the final solution
  */
 public AIPolygon getFinalPathStart()
 {
     return(finalSolutionStart.getPolygon());
 }
Exemplo n.º 6
0
 /*
  * deletingNode method will place a node on the closed list essectially deleting it
  * Parameter:	(AIDynBiDirOpNode)tempNode is the node that needs to be placed on the closed list
  * Return:	none
  */
 public void deletingNode(AIDynBiDirOpNode tempNode)
 {
     closedList[tempNode.getPolygon().getID()] = tempNode;
 }