Esempio n. 1
0
    /* 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--;
        }
    }
Esempio n. 2
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:	(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);
    }
Esempio n. 3
0
    /*
     * addAfter will make a new polygon and add it right after the node being passed in
     * Parameter:	(AIPolygon)polygonToAdd is the polygon for the new node
     *              (AIFringeSearchNode)parentNode is the node that will be the parent of this node
     *              (float)gCostToAdd is the cost to get to this node
     * Return:	none
     */
    public void addAfter(AIPolygon polygonToAdd, AIFringeSearchNode nodeToAddAfter, float gCostToAdd)
    {
        AIFringeSearchNode tempNode = new AIFringeSearchNode(polygonToAdd, nodeToAddAfter, gCostToAdd, goalPosition);

        tempNode.setNextNode(nodeToAddAfter.getNextNode());
        nodeToAddAfter.setNextNode(tempNode);
        numberOfNodesHeld++;
    }
Esempio n. 4
0
    /*
     * popNode will remove a node from the front of the the list
     * Parameter:	none
     * Return:	(AIFringeSearchNode)
     *              the node that was removed from the front of the list
     */
    public AIFringeSearchNode popNode()
    {
        AIFringeSearchNode temp = frontOfList;

        frontOfList = temp.getNextNode();
        numberOfNodesHeld--;
        return(temp);
    }
Esempio n. 5
0
    /*
     * getNodeAtIndex method will get a node at a certian index in the list
     * Parameter:	(int)index is the index in the list that the caller wants the node of
     * Return:		(AIFringeSearchNode)
     *                  the node that was at the index being passed int
     */
    public AIFringeSearchNode getNodeAtIndex(int index)
    {
        if (index == 0)
        {
            return(frontOfList);
        }
        AIFringeSearchNode temp = frontOfList;

        for (int count = 0; count < index; count++)
        {
            temp = temp.getNextNode();
        }
        return(temp);
    }
Esempio n. 6
0
    /*
     * pushAtTheEnd method will take a node and push it at the back of the lsit
     * parameter:	(AIFringeSearchNode)nodeToPush is the node the caller wants at the back of the list
     * Return:	none
     */
    public void pushAtTheEnd(AIFringeSearchNode nodeToPush)
    {
        if (frontOfList == null)
        {
            nodeToPush.setNextNode(frontOfList);
            frontOfList = nodeToPush;
            numberOfNodesHeld++;
            return;
        }
        AIFringeSearchNode tempNode = getNodeAtIndex(getSize() - 1);

        nodeToPush.setNextNode(tempNode.getNextNode());
        tempNode.setNextNode(nodeToPush);
        numberOfNodesHeld++;
    }