Souls and AI


What is a Soul?

All objects are inherently inanimate. Even creatures are pretty much lumps of matter with no will of their own. In the White Orb world, all active objects are controlled by a soul. So if the character Fred moves north, Fred was not really the one that decided to move north - it was Fred's soul. Yup.

This means that the behaviour, personality, and skills of a creature are not really attributes of the creature himself, but rather his soul. This also means that swords, potatoes, chairs, and mirrors can also have souls - that's the fun part. It also means you can switch souls, so that Fred might get possessed or hypnotized so that someone else controls his actions.

The soul receives all events that its body receives, processes them, and creates new actions when applicable.  Most souls are limited by the sensory perception of the body, ie even if a sound event "reaches" the body the soul will only detect if the body has good enough hearing ability.  This is reflected using the Senses object.

There are two fundamental subclasses to Soul:

An Account acts as a gateway to a real, live human being sitting on a computer somewhere in the world running the White Orb client. All events reaching the soul will be forwarded to the client (who in turn will describe it to the player, using either graphics or text), and all actions initiated by the player using the White Orb client will be forwarded to the Soul, who will create the Action object and schedule it in the Clock.

An NPCSoul is much more complicated, and there will be many subclasses to NPCSoul representing different personality types and things like that. This is where all AI stuff needs to be added. When an NPCSoul receives an event it will process it and, depending on things like it's current state, it's personality, it's "memory", and things like it may or may not schedule a new action. See the Souls & AI document for more details about this.

Thus there is no real difference (from the body's point of view) between a computer controlled creature and a player controlled creature - they just have different souls controlling them. It's almost religous, isn't it? One thing that's nice about this project is that it allows us to experiment with philosophy :o)

What makes those pesky NPCs live ?

The purpose of the AI framework is to provide souls (that may be connected to whatever object) with a possibility to interact with their surroundings, like players or other NPCs.  They can react on incoming events with a series of actions, or act goal-driven.  To allow a flexible behaviour, we must have an easy way to specify rules that NPCs are following.  NPCs normally will obey to a rule set that uses a prioritizing scheme to find the current rule that delivers actions. See below for a further discussion about rules.

NPCs also must have some kind of brain to memorize things. An NPC should know, where his home is, for example, or where to go to get some beer. This is static information given the NPCs beforehand, before the birth I might say. However, NPCs can also memorize things that happen in their life. The hostility of  a certain player, or a safe route to the next village, the location of dungeons, information given by players in conversations, etc. We will provide a knowledge base (KB) for this. The KB will allow for insertions of facts about the world it is in. Special rules can infer on this knowledge and  (hopefully) create an emerging behaviour. The KB will also serve to keep track of quests to solve or tasks that were given to the player by those unavoidable agicians that lost the ring of ultimate-destruction and want you to bring it back (but DON'T use it :)

Another aspect of the framework that is most crucial to a rich virtual world is of course communication. As you all know, creating a realistic conversation with a NPC is very hard to accomplish and we are still discussing, whether we should use a real natural language parser (which is something, a lot of scientists try to figure out) or a keyword based system or a menu driven system. A hybrid system of the above is also possible. Please mail us, if you'd like to tell us of the best communication system you have encountered so far.

Rules rule !

The very heart of a NPC is the rule-driven action system. A NPC starts out with a set of rules, that consist of the following parts: If the precondition holds true, i.e. it fires, the action part is asked to deliver GameEvents to the NPCSoul.

What about the priority ?

Imagine your NPC walks to near forest to cut some wood (A CutSomeWood rule would deliver the actions to do so). Suddenly two fearsome darkwood boars jump out of nearby bushes and have this god-am-I-hungry look on their face. A reasonable NPC wouldn't just stand there and cut some more wood, while he gets nibbled by the two boars. He would of course run away or use his double-handed axe to fight. A natural solution would be to allow for certain rules to be more important than others. So a rule with a higher priority is allowed to interrupt the current rule. The current rule gets informed about the interruption and can decide to resume, if the interrupting rule has finished. In our example, CutSomeWood says that it would like to carry on after the fight and gets pushed on a rule stack. The FightTilTheEnd rule would drop in and do whatever its action part says. After that CutSomeWood is taken from the rule stack and resumes actions.

Of course, you can do a lot of fancy things with the rules and the rule set. Rules can insert new rules in the rule set or delete rules from it. They can arrange that they are deleted automatically, if they fire or change their priorities. Special time table rules allow to specify the general daytime behaviour of NPCs
and for special occasions like combat or communication the ruleset can be exchanged.

Rules everywhere

In addition to determine the behaviour of NPCs, rules can also be used by players, for example in a combat situation. Inanimated objects, like a magic spring, can have a soul attached with rules to fill it with live. Later incarnations of NPCs will use more sophisticated rules that use the KB and learning
algorithms to really grow up, develop and reproduce !

Status of development

We have now a working  all purpose rule-driven NPCSoul, that can be subclassed to create different kinds of NPC and some all-purpose rules.
There are also routines for finding paths in an environment and some higher level methods to simplify some aspects of NPC programming.



Henrik Kniberg & Jochen Bedersdorfer

Last updated: