AI part 1:General concept

  • Post category:Baneshifter

First of all a bit of my background. I have worked as an game AI programmer for almost 8 years. Now I’m working on other things but the game AI remains one of my favorite topics. So I’ll be more technical this time in hope that somebody may find my notes useful in the future.

An AI entity in my game is called AI actor. That name is fitting nicely since the only purpose of the game AI is to entertain the player. I’ll try to make it look as smart as possible not to be smart. That’s a huge difference especially in a game viewed from a first person perspective. Just one example: a damaged enemy retreats from a fight to heal himself. It is smart? Yes. Does it look smart? Yes but only if the player can see/hear the actual healing process. In other case it looks almost like a bug.

Let’s start with the top level structure of the AI actor. I’ve bet on pretty standard architecture that I’ve already successfully used multiple times. In short, every system is independent and can possibly work in parallel if needed. Senses checks everything around and store results into a memory. A brain is processing data in the memory and translates them to commands for a controller. All of that can be tuned by a database of constants. Simple.

Top level general concept. Arrows represent the data flow.

When I split the structure to actual subsystems in my code it looks just a bit more complex.

More granular general concept. Arrows represent the data flow.

My AI has three types of senses: sight, hearing and spatial awareness. The last one is just a lookup to the game data rather than a ‘real’ sense.

The brain consists of four subsystems: a target selector for selection of the best target from available options, a standard behavior tree, a decision engine that controls the main flow in the behavior tree and finally a navigation for all pathfinding and pathing stuff. The details will be described in next parts.

The memory is a standard class that consists of many fields and some support functions. It is serialized together with the whole game state so the AI remembers everything necessary when the game is saved and loaded later.

That’s all for today. Next part will be about senses and let’s hope it will make sense. 🙂