Enemy Movement ============== Roguelikes often like to model complex enemy behavior. Some examples are: - The enemy comes close to the player, steals on object and then runs back to its nest to store it. The player can kill the creature to recover her stolen property or find the nest - Enemies continually patrolling some specific areas - Creatures can have a role associated to them and act based on that role unless disturbed. Cogmind is a great example of this In addition to this "high level" behavior, there is also the fact that enemies need to be able to maneuver their way around the player in order to surround her: no one likes to see enemies lining up like idiots waiting to be shot down. For Caves Of, I'm focusing mostly on this "low level" behavior since it has a bigger impact on the gameplay. The original implementation of enemies movement was just to have them converge on the player if they were in range. As you can imagine, this works well when you have 1-2 enemies in range, but when you have 5 or 6 they really don't make good use of the free space they have. After studying the issue for some time, I ended up implementing "Dijkstra Maps". Details on how this algorithm works can be found on roguebasin.com. It really works wonders and now enemies spread properly and go around the player trying to surround her. The drawback is that even a 7x7 map takes some time to be computed (each enemy needs to recompute it) and this makes the player movement a little sluggish. I'm not too concerned at the moment since this is a turn based game supposed to be played slowly. The camera is also pretty zoomed in, so the player is not supposed to run blindly into unexplored parts of the map. I'll probably introduce some kind of visual clue to help the human player understand the computer is "thinking". I suspect there are also ways to optimize my Dijkstra Map algorithm. Finally, I can also reduce the size of the map to 5x5 and have enemies getting closer just by general direction when they are farther than three tiles from the player.