From point A to B with obstacles in the way

This is exactly how the A* pathfinding works; it goes from point to point evaluating the best options and pursuing the shortest path until it reaches the final destination. The earlier example was simple, and now we are going to make it more interesting to see how it works if we add obstacles to the map.

Using the same map, we have painted some squares in black, representing that those positions can't be used. Now, it starts getting slightly more interesting, because if we try to guess what the best path to take would be, we might be wrong. Once again, let's calculate what the best options are, as ...

Get Practical Game AI Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.