I'm very new to game development, but an experienced software engineer. As an introduction to game dev, I'm making a 2D zombie game in Python, using pygame. The game is almost done, but I still have to write the AI for the other humans and the different zombies in the game.

Should I have a centralized AI module that looks for the position of each character and zombie and determines the best way to move each of them? Or should each instance of a zombie or human be responsible for its own behavior?

In my mind it is more straight forward to make each unit responsible of it's own behavior and I think that it would be easier to give them a more "natural" look implementing it this way. However it's probably a lot more inefficient in memory and processing time that a centralized one. Again, I'm super new to games so any example of how is the AI implemented in some major games would be appreciated.

I understand this is probably a very subjective question, but I'm looking for an answer that covers something like pros vs cons, industry standard or known cases of each one.

  • 3
    \$\begingroup\$ Make them a hive :) Did not read the whole document but it looks like it could help you: research.ncl.ac.uk/game/mastersdegree/gametechnologies/… \$\endgroup\$ Commented Jul 1, 2014 at 15:50
  • \$\begingroup\$ I'ld look into behaviour trees. \$\endgroup\$ Commented Jul 2, 2014 at 10:36
  • 1
    \$\begingroup\$ @Dominik I know about behavior trees, but that doesn't answer the question. I could still have one big tree or individual trees for each one of the NPCs. \$\endgroup\$
    – Topo
    Commented Jul 2, 2014 at 16:31
  • 1
    \$\begingroup\$ Rule of thumb: Whenever you have to decide between the straight forward solution and the maybe more efficient solution, you should always try the straight forward one first unless you know it will create a critical performance bottleneck. And in game development, the bottleneck is almost always the graphics. \$\endgroup\$
    – Philipp
    Commented Jul 9, 2014 at 12:53

3 Answers 3


If it were me I would give each NPC agency of their own - if each one has a simple goal ( get as far as possible from Zombies/get as close as possible to humans ) that they act on, you can get quite interesting behaviours from relatively simple inputs without too much processing.

The downside of this is that if you have a lot of them around you are going to need to do a lot of processing on each decision cycle so if you have large levels you may want to have an overview AI for the area outside of the user's viewport, just controlling how many NPCs are in the area and occasionally posting some new ones into view, and then the agent-based approach for those that are currently visible.

The best approach for your particular case will undoubtedly be to experiment with the options and find the simplest case that is fun. As a general rule, the more complexity you add the more frequently it will fail. Because AI tends to be non-deterministic it is way harder to validate its operation with automated tests, but fortunately manual tests are often either interesting or hilarious, so it has its merits.


The first decision has to come from what the gameplay requires. There are some behaviors that are going to require coordination, and will be easier and more efficient to implement in a centralized way.

To look at it from a purely performance/architecture point of view, let's assume that you want individual behavior. It's unlikely that you can reuse a lot of computation, as AI is usually very context-aware. You have to pathfind and cast rays from the position of each character, so the results will be different. Besides, unless required by the game design, if all characters react in the same way at the same time you'll get a very poor result, with everybody moving in perfect sync.

In practice then, the only CPU benefit you're going to get from running all the behaviors in a centralized way is saving the instruction cache. Because you're coding in Python, I'd say that's not a prime concern :)

In terms of memory, the best way to store the information is to split it between shared data and instance data. Shared data will include definitions, tuning, etc. If you use behavior trees, the behavior tree can probably be shared. Instance data is what relates specifically to that character: their position, their state, which BT node is active, etc. This will give you most of the savings you'd get from centralizing the AI.

Finally, when you need some coordination, look up Blackboard architectures. Create a common place where individual characters can add pieces of data to communicate with each other (for instance, if you only allow one character to attack the player at once, you could put a reserve token there).


In this article the autor is talking about Group behavior. Still I guess it depends on your requirements whether you decide to implement a centralized AI or not.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .