/* 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++; }
/* enqueue adds a node to the front of this list * Parameter: (AIAgentAStarSearchNode) nodeToAdd is the node to be added to the front of the list * Return: none */ public void enqueue(AIAgentAStarSearchNode nodeToAdd) { AIAgentAStarSearchNode newNode = new AIAgentAStarSearchNode(nodeToAdd.getPolygon(), nodeToAdd.getParentNode(), nodeToAdd.getGFromStartingNode(), goalPosition); newNode.setNextNode(frontOfList); frontOfList = newNode; }
/* 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--; }