/* 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); if (frontOfList == null) { newSearchNode.setNextNode(frontOfList); frontOfList = newSearchNode; numberOfNodesHeld++; return; } AIAgentAStarSearchNode tempFront = frontOfList; if (tempFront.compareTo(newSearchNode.getTotalCost()) > 0f) { newSearchNode.setNextNode(tempFront); frontOfList = newSearchNode; numberOfNodesHeld++; return; } AIAgentAStarSearchNode tempBack = tempFront.getNextNode(); while (tempBack != null && tempBack.compareTo(newSearchNode.getTotalCost()) < 0f) { tempFront = tempBack; tempBack = tempFront.getNextNode(); } newSearchNode.setNextNode(tempFront.getNextNode()); tempFront.setNextNode(newSearchNode); numberOfNodesHeld++; }
/* 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) { AIAgentAStarSearchNode tempFront = frontOfList; if (frontOfList != null) { if (doesIDMatch(frontOfList.getPolygon().getID(), idToDelete) == true) { frontOfList = frontOfList.getNextNode(); numberOfNodesHeld--; return; } AIAgentAStarSearchNode 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--; }
/* popNode removes and returns the node at the front of the list (node with lowest fToatlCost value) * Parameter: none * Return: (AIAgentAStarSearchNode) * node that was removed from the front of this list */ public AIAgentAStarSearchNode popNode() { if (frontOfList == null) { return(null); } AIAgentAStarSearchNode tempNode = frontOfList; frontOfList = tempNode.getNextNode(); numberOfNodesHeld--; return(tempNode); }