I’m still working on smarter enemy AI. It’s been challenging. The more sophisticated the AI becomes, the more sophistication it requires. For example, adding fleeing raises a number of questions: where to flee to, what path to take when fleeing, what to do when fleeing into a corner, etc. As the rules accumulate, the more fragile the logic becomes. And for utility AI that calculates scores by summing various factors (in cover, low health, etc.), it’s difficult to tune the individual weights to ensure that the final scores are correctly ranked.
Hierarchical Utility AI
Enemies now determine an intent (fight, survive, etc.), a plan (attack, close distance, flee), and an action, replacing a large, flat collection of scoring rules that had become very difficult to maintain and troubleshoot. I’m still working through some incorrect behaviors.
Enemy AI Testing/Debugging Tools
I added some testing/debugging tools to help troubleshoot unexpected behaviors. These tools were immensely helpful, enabling me to find and fix a few significant bugs that have been around for literally years!
The cells an actor can see, hear, or shoot at can now be highlighted with a key press.
Actor action history is now recorded. For each action record, a summary of the reasoning that led to the selection of the action is also stored. This allows me to view an enemy’s action sequence and understand why it performed those actions.
Bug Fixes
There have always been issues with field of view and projectiles rooted in the grid traversal. They all got fixed this week thanks to the addition of sight/hearing/shooting highlighting. There were two root causes. One issue was asymmetry. Sometimes, an enemy would be able to shoot at the player, but the player couldn’t shoot back from the same position, and vice versa. This happened because the cells a line passed through in one direction differed from the cells the same line going in the opposite direction passed through. I fixed this by ordering the line’s start and end coordinates so that the player and enemy use the same line. The other root cause was using the wrong grid traversal algorithm in some cases (there are two, one permissive and one restrictive).
Next week, I’ll continue working on enemy AI. My goal is to complete the AI by year end.

