A* Search


In my implementation of the A*, every index on the board is set to be a node. All nodes are then connected together by finding their neighbor's and setting the relationships. All nodes that are walls are not added to the graph. Before the neighbor's are set every node is given a heuristic cost (hCost).
The heuristic cost is how far the point is from the target. Therefore we need to find the euclidean distance between every single point x,y to the target.
Each node has an hCost, gCost and fCost.
The gCost is the cost of moving to the neighbor. Diagonals cost 1.4 and horizontal and vertical movements have a gCost of 1. This is calculate using Pythagoras theorem. The fCost is the gCost + hCost.

A* search works by having an open list and a closed list.
In my implementation I have used a priority queue for the open list.  The priority queue takes in a comparable that places nodes with the smallest fCost at the front of the queue.
On each iteration of the search, if the current node is not the target node, all its neighbor's are placed in the open list and it is placed in the closed list. All the neighbor's are organized by priority in the queue and the neighbor with the smallest fCost becomes the current node. This continues until either the target is found or the queue is empty. If the target is found a list of the shortest path is returned.
Then the pursuer follows this path.




I was able to implement the A* search by following tutorials by Seyedali Mirjalili on Udemy and theCherno on YouTube.