Pseudo code for A* Node Class: A class used to store data about nodes (possible waypoints on the path) position = the location of the node parent = the node that leads to this node costSoFar = stores the distance to this node from the start distanceToEnd = distance "as crow flies" to the target destination totalCost = distanceToEnd + costSoFar findPath method: openList = list of possible nodes closedList = list of disregarded nodes currentNode = the node being examined currently SET currentNode to node at starting location ADD currentNode to openList WHILE openList is not empty sort openList, from lowest totalCost to highest totalCost of the node SET currentNode to first element in openList, i.e. on first run the start node IF currentNode's position = goal THEN the path has been found path = list of nodes that make up path WHILE currentNode is not start node ADD currentNode to path SET currentNode to currentNode's parent RETURN path IF path hasn't been found THEN remove currentNode from openList and add to closedList FOR adjacent nodes: READ tile at the node's position IF tile is solid or not valid THEN skip this node SET nodes's costSoFar to (currentNode's costSoFar + distance to target from currentNode's position)*movement cost at node IF node is in closedList and you moving away from the goal THEN skip this node IF node is not in openList and moving closer to target THEN add node to openList
© Copyright 2026 Paperzz