by David Bennett
NPCs are a very important part of most muds, they are one of the central figures of player interaction with the coded elements of the game. In most cases NPCs are also pretty stupid, they do not do particularly logical things and usually just hang around and let themselves be beaten up. Why is this? Well, doing intelligent NPCs is quite a difficult task. I will attempt to outline a couple of methods of achieving more intelligent NPCs in this article.
What often happens on muds is that NPCs are intelligent in isolated spots, everyone writes their own little bit of intelligence code that is not connectable to anyone else's, but their particular NPC does some bright things. An obvious extension to this is to enable some sort of system which will handle adding small event driven hooks onto NPCs and creating a standard library to handle often used forms of intelligent interaction. This is quite nice and reasonable first step, it means that people writing their NPCs do not need to reinvent the wheel every time they want to add in some functionality.
And we call ourselves intelligent?
User Friendly © Illiad, used with permission.
Putting decent hooks into your NPCs to allow says and emotion commands to be easily trapped and dealt with is another important point. Too many NPCs on muds do not even respond to simple greetings, people almost always respond to greetings in some way. From bowing respectfully, to saying hello back or even turning away from the person. Just adding this level of responses to your NPCs will make them seem a lot more real and add a definite element to your gaming world.
This does not solve the total problem though, it allows your NPCs to be far more reactionary but it still does not resolve more complicated things like NPCs which track down players and kill them, or NPCs that have specific goals. The problem is the interaction between the different event based hooks, you need some sort of governing body to sort out the interactions. This means you still need to write a lot of the NPCs intelligence directly into the main source code.
People have been working on different forms of Artificial Intelligence for a while in this sort of arena, there are people looking at muds and at things like interactive fiction. It is from one of the interactive fiction efforts that I will base some of the idea presented here to handle more intelligent NPCs
The thing about NPCs is they do not need to really understand what is going on to appear intelligent, they only need a very shallow understanding and can in most cases be totally reactive or event driven. This gives them a very shallow level of intelligence but it is enough to make the NPC far more interesting and to get it to interact with the game world in a more intelligent manner.
If you think about how most people work or how things appear to be intelligent, you can see that you can divide it down into high level goals. These goals are like a governing body for the event driven hooks described above. Goals are things like 'staying alive' or 'making lots of money' or 'getting drunk'. Each goal has a priority and higher priority goals would over ride low ones, if the need arises. For a goal to complete it would have a number of strategies, each strategy would be a lower level more precise event. Things like 'Run away' or 'Heal myself' would be strategies.
How does this all tie together? Well, when an NPC receives an event of some form it would ask all the goals if they want to deal with it, each goal would then determine which (if any) strategy is most approriate. An event might be of the form: 'lost huge numbers of hit points' or 'was healed some'. The strategy which is setup by the goal gets the priority of the goal and is added to the strategy queue on the NPC. The NPC will only ever have one strategy activated at any one time (mostly because it is easier that way) and the highest priority strategy would be the one activated. So if a new strategy comes along and it is higher priority, the old one is suspended and the new one is activated.
That is the mechanics of the system, what does this mean in practice? Consider an NPC who has a goal of getting rich, this NPC happens to be a thief. The NPC will wander around the world and attempt to steal things off people it considers in its potential stealing range, once it has stolen an item it will take it to a store and sell it and then take the money to the bank and put it away for later use. There is only one goal here, the goal being to make money. There are several strategies involved in the sequence, the first one is a stealing strategy. Once the stealing strategy has finished an event is generated which corresponds to the NPC getting hold of an item (this could also happen if you give something to the NPC). The goal will then trigger the sell item strategy since it has something to sell, along the way other potential steal victims might appear in which case the NPC might attempt to steal off them too (depending on how your strategies are setup). Once the item is sold the NPC has cash, which would be notified by another event so the NPC would initiate the bank money strategy. If on the way to the bank the NPC is attacked, the stay alive goal would kick in and the NPC would attempt to stay alive, the strategies generated from this goal will be higher priority than the making money ones so the NPC will always act on those first.
By using a combination of high level goals and lower level strategies to make up the system, quite complicated NPC behavior can be generated using relatively simple techniques.
January 1999 Imaginary Realities, the magazine of your mind.
© Copyright Information