Beispiel #1
0
    /*
     *	mergeWithNeighbors will attempt to to merge all the AIPolygons it can from its neighbor list
     *	Parameter:	(AIPolygon)polygonToMerge is the polygon that is going to attempt to merge with
     *											neighbors
     *	return: None
     */
    void mergeWithNeighbors(AIPolygon polygonToMerge)
    {
        if (polygonToMerge != null)
        {
            int[] neighborHolder = polygonToMerge.getNeighbors();              //array hold the indices for the neighbors of polygonToMerge
            for (int count = 0; count < neighborHolder.Length; count++)
            {
                if (polygonArray [neighborHolder [count]] != null)
                {
                    AIPolygon mergedPolygon = polygonArray [polygonToMerge.getID()].mergeRegular(polygonArray [neighborHolder [count]], polygonToMerge.getID()); // this will attempt to merge two polygons and create a new AIPolygon
                    if (mergedPolygon != null)                                                                                                                   //mergedPolygon will be null if the merge was not accepted
                    {
                        if (mergedPolygon.isPolygonConvex() == true)                                                                                             // this will check to see if the new AIPolygon is convex or not
                        {
                            mergeQueue.deleteNodeOfID(neighborHolder [count]);                                                                                   // delete the old polygon from the neighbor list
                            deleteNeighborAtIndex(polygonToMerge.getID());
                            deleteNeighborAtIndex(neighborHolder [count]);
                            polygonArray [polygonToMerge.getID()] = mergedPolygon;          // add new Polygon to the polygonArray

                            polygonArray [neighborHolder [count]] = null;                   // remove the last polygon that was merged
                            checkAndAddNeighborAtIndex(polygonToMerge.getID());             //finds the neighbors of the new Polygon
                            mergeQueue.enqueue(mergedPolygon);                              // adds the new Polygon to the mergedQueue
                            return;
                        }
                    }
                }
            }
        }
    }
    /* 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: (AIAgentAStarSearchNode)
     *														node on list that is holding polygonToCheck
     */
    public AIAgentAStarSearchNode getNodeOnList(AIPolygon polygonToCheck)
    {
        AIAgentAStarSearchNode tempFront = frontOfList;

        if (tempFront == null)
        {
            return(null);
        }
        if (doesIDMatch(polygonToCheck.getID(), tempFront.getPolygon().getID()) == true)
        {
            return(tempFront);
        }
        AIAgentAStarSearchNode 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);
    }
    /* addNode adds a node to this list in order according to its fTotalCost value
     * Parameter: (AIPolygon) polygonToAdd is the polygon that will be held by the node
     * (AIAgentAStarSearchNode) parentNodeToAdd is the parent of the node to be added
     * (float) gCostToAdd is the getGFromStartingNode value to be stored in the node to be added
     * Return: none
     */
    public void addNode(AIPolygon polygonToAdd, AIAgentAStarSearchNode parentNodeToAdd, float gCostToAdd)
    {
        AIAgentAStarSearchNode newSearchNode = new AIAgentAStarSearchNode(polygonToAdd, parentNodeToAdd, gCostToAdd, goalPosition);

        inList [polygonToAdd.getID()]       = true;
        indicesArray [polygonToAdd.getID()] = numberOfNodesHeld;
        heap [numberOfNodesHeld]            = newSearchNode;
        shiftUp(numberOfNodesHeld);
        numberOfNodesHeld++;
    }
 /*
  * doesIDMatch will check to see if an ID being passed in matches the ID of the AIPolygon
  *		being held by this object
  *	Parameter:	(int)idToCheck is the ID that the caller wants to check against the AIPolygon
  *											being held
  *	Return:			(bool)
  *								false if the idToCheck does not match the ID of the AIPolygon being held
  *								true if the idToCheck matches the ID of the AIPolygon being held
  */
 public bool doesIDMatch(int idToCheck)
 {
     if (idToCheck == polygon.getID())
     {
         return(true);
     }
     return(false);
 }
    /* addNode adds a node to this list in order according to its fTotalCost value
     * Parameter: (AIPolygon) polygonToAdd is the polygon that will be held by the node
     * (AIAgentAStarSearchNode) parentNodeToAdd is the parent of the node to be added
     * (float) gCostToAdd is the getGFromStartingNode value to be stored in the node to be added
     * Return: none
     */
    public void addNode(AIPolygon polygonToAdd, AIDynamicWeightedSearchNode parentNodeToAdd, float gCostToAdd)
    {
        AIDynamicWeightedSearchNode newSearchNode;

        if (numberOfNodesHeld == 0)
        {
            newSearchNode = new AIDynamicWeightedSearchNode(polygonToAdd, parentNodeToAdd, gCostToAdd, goalPosition, AIDynamicWeightedSearch.startingH, 1);
        }
        else
        {
            newSearchNode = new AIDynamicWeightedSearchNode(polygonToAdd, parentNodeToAdd, gCostToAdd, goalPosition, AIDynamicWeightedSearch.startingH, (parentNodeToAdd.getDoFN() + 1));
        }
        inList [polygonToAdd.getID()]       = true;
        indicesArray [polygonToAdd.getID()] = numberOfNodesHeld;
        heap [numberOfNodesHeld]            = newSearchNode;
        shiftUp(numberOfNodesHeld);
        numberOfNodesHeld++;
    }
Beispiel #6
0
    /*
     * getFinalPathStartingWithNodes method will return a final path array that starts the the node
     *      containing the polygon being sent in
     * Parameter:	(AIPolygon) polygonToStartWith is the polygon that is in the node the caller wants the
     *                  final path array to start with
     * Return:		(AIPolygon[])
     *                  the final path array starting with the node containing the polygon being passed in
     */
    public AIPolygon[] getFinalPathStartingWithNode(AIPolygon polygonToStartWith)
    {
        AIAgentAStarSearchNode tempNode = closedList[polygonToStartWith.getID()];

        if (tempNode == null)
        {
            return(null);
        }
        finalSolutionStart = tempNode;
        return(getFinalPath());
    }
Beispiel #7
0
 /* 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: (AIAgentAStarSearchNode)
  *														node on list that is holding polygonToCheck
  */
 public AIAgentAStarSearchNode getNodeOnList(AIPolygon polygonToCheck)
 {
     return(heap [indicesArray [polygonToCheck.getID()]]);
 }
Beispiel #8
0
 /* isNodeOnList checks to see if node containing a certain polygon is on the list
  * Parameter: (AIPolygon) polygon whose id will be used to check if a certain node is on list
  * Return: (bool)
  *						true if a node is on the list that contains polygonToCheck
  *						false if no node on the list contains polygonToCheck
  */
 public bool isNodeOnList(AIPolygon polygonToCheck)
 {
     return(inList [polygonToCheck.getID()]);
 }
Beispiel #9
0
 /* 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: (AIAgentAStarSearchNode)
  *														node on list that is holding polygonToCheck
  */
 public AIDynBiDirOpNode getNodeOnList(AIPolygon polygonToCheck)
 {
     return(heap [indicesArray [polygonToCheck.getID()]]);
 }
 /* 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:	(AIDynamicWeightedSearchNode)
  *				node on list that is holding polygonToCheck
  */
 public AIDynamicWeightedSearchNode getNodeOnList(AIPolygon polygonToCheck)
 {
     return(heap [indicesArray [polygonToCheck.getID()]]);
 }