Sunday, February 1, 2009

Simple AI design

Because I have several C++ projects that I'm going to need to develop AI for, I might as well begin working through some code design.

As far as game engines go, the singleton manager paradigm is pretty useful (though only in specific scenarios). With an AI system, this manager needs to keep track of all scene objects using AI, the AI itself, and information used by each agent. To me, this means that I can create some grouping for particular sets of AI functions and for each scene object requiring AI control I just need to know what set of functions I'm using. The information, or knowledge base, for each AI/object pair doesn't need to be anything fancy, so a struct will do fine. This leaves me with three components; the AI Manager, the AI Controllers, and a knowledge struct.

The manager is a singleton (no need for several managers in one running engine) that allows adding/removing of AI to scene objects, and provides a means to update all objects in batch. Keeping track of these mappings is sufficient to be a linked list of structs containing a pointer to the object, some identifier for type of AI used, and a knowledge object. More functionality may be needed, but for now this is all I should have to worry about.

The AI Controller types need to be able to support multiple AI paradigms. Initially I was thinking about keeping the knowledge separate from the controllers. Though this forced me to limit the types of AI that I would be using. It would either have to deal with complete information or incomplete, fuzzy or crisp, etc.. Instead of that, I'm better off keeping the knowledge within each controller. Though I'll still define a struct for the different types of data that I'll deal with.

As a base for the knowledge struct I'm including the following;
  • player position
  • player health
  • own position
  • own health
  • # proximal friendlies
  • list of identified projectiles and percieved tragectories (more intelligent agents)
I have listed two fields that are redundant as each controller would have access to it's object's health and position. Though this data may not be in some particular format which the AI functionality would prefer. So I'm listing them here anyway.

Put together, I have a manager which will create an AI control object when given a new scene object to manage. The control object will construct a knowledge set updated by perceptional utilities on the scene object and use this to make decisions for that scene object.

This design is incomplete, but I'm listing it now as an initial design.

No comments: