Enemy AI: chasing a player without Navigation2D or A* pathfinding
A fascinating AI technique is used in one of the best roguelikes, Brogue. The author called it &quot;Dijkstra Maps&quot;. Basically it&#x27;s about generating a heatmap for all the squares on the level. You can start with 0 at player position, and from that point use a simple floodfill algorithm, putting down increasing numbers with each step. Then a monster simply examines all adjacent squares and selects the one with lowest number. This has at least two notable advantages:<p>1. You only need to do the path generation once, and it scales very well with the number of monsters.
2. It&#x27;s really good at combining several concerns, because you can generate a couple of heat maps for different concerns and add them up. For example one heat map is about proximity to player. Another could be about proximity to health pickups, or proximity to cover, or proximity to open space if a monster likes to keep distance and shoot. If a gas trap is triggered, you can use a &quot;danger&quot; heat map. Then a monster can easily get closer to player and at the same time choose the path which has fewer harmful effects.<p>That&#x27;s why centaur archers in Brogue are so annoying, monsters avoid traps intelligently, monster groups avoid wasting their numerical advantage by chasing player through a corridor.<p>He described it in detail in this article:
<a href="http:&#x2F;&#x2F;www.roguebasin.com&#x2F;index.php?title=The_Incredible_Power_of_Dijkstra_Maps" rel="nofollow">http:&#x2F;&#x2F;www.roguebasin.com&#x2F;index.php?title=The_Incredible_Pow...</a><p>And in case you&#x27;re wondering, Brogue source code is licensed on AGPLv3.