Pathfinding, A*

In my line of interesting programming projects I have made an attempt at implement an A* pathfinding algorithm.

The area is randomly generated and the algorithm starts at the blue square (Somewhere in the top left quarter) and tries to find a path to the red one (Bottom right quarter).

The button under the grid area allows you to toggle weather the algorithm considers the distance it already walked, when deciding where to go next. Pr. default the traveled distance is considered, which makes the algorithm slower in this perfectly laid out grid where all the steps have the same length.

When toggled the algorithm only considers which step has the shortest direct distance to the target. This seems much faster in this scenario, but if each step had a different weight, then the most direct route might not be the “cheapest”.

There are many optimizations that could be made to the algorithm, I’m sure. And even more optimizations to the simulation and the controls could make a much smoother experience. This is, however, only a proof of concept, and optimizations are not planned at this time.