Game Development Community

Persistent World Rountable: Artificial Intelligence...

by Ted Southard · in Technical Issues · 09/08/2004 (4:44 pm) · 12 replies

Been a month or two since I started up one of these threads, but here we go...

This one is about the AI techniques that can make or break a Persistent World. What are you looking for in AI for these games? What techniques are you exploring to bring about the changes you want to see? This is a thread for everyone to bounce ideas off of each other and walk away a little wiser.

As always, I'll start off with some of the things being done in Epic Frontiers. As of right now, the state of AI in Epic Frontiers is at about the level of every other Persistent World out there: MOB's wander aimlessly until you attack them, and then they turn around and open variable-sized cans of whup-ass on you. Where I'm looking to take my AI, however, is a different story:

1) "Life Schedules": I avoiding using the term "Life Cycle" because that means dying, and that would not be accurate, in that the MOB's don't die in my game unless they're killed. What I mean by the term is that the MOB's in the game go about daily activities such as eating, drinking, sleeping, wandering around, crafting, etc. You can even hook the stats used to govern these actions into combat and such, so that the first thing a victorious MOB does is heal himself, and then go rest.

2) Artificial Emotion: AE is something that I think will be coming out in a lot of games soon, or else all of the research papers I've read on the subject haven't made any impact, which I don't believe. AE is not a replacement for AI, but a compliment to it, and those who I talked to about this at last year's IGC know what I have planned. Emotional traits that can be influenced by actions of players and the environment in the game world that can have effects on the decision making process of the NPC's. This gives the NPC's greater depth of character, and helps draw players in. The state of this code is that it needs a few tweaks, but it's in it's third generation and it needs to be implemented in a bot and tested in the "wild".

I know others have AI ideas, concepts, and implementations that they'd like to talk about, or other games that they'd like to point out as having good AI, so let's hear about it!

#1
09/08/2004 (10:15 pm)
One thing I think would be really cool is if you could make the "life schedules" and NPC ai actually have an impact on the game's economy.

Basically, not only would the NPCs walk around and look busy during the day, but they could actually move money and goods around too. For instance, every few days, each npc could take a trip to the store and exchange some money for some food, take the food home and put it in a chest or something, and gradually eat it over the course of a few days. A hunter NPC might go out to the woods every day, kill some goons, bring back meat and skins and sell them to a shopkeeper.

Something like this would be fun to interfere/interact with. For instance, if you killed the hunter NPC, the shopkeeper wouldn't be able to restock his supply of skins and meat, so prices would go up and he'd eventually run out. You could then sell the meat you've gathered for a much better price.

This pretty far fetched, but I'd like to see someone give it a try some day. I certainly don't have the resources or experience to pull it off :)

On another topic entirely, one thing that always bugged me about Gothic 2 and Morrowind was the fact that when i killed someone, the authorities would immediately know about it. I guess in the next Gothic game they're actually trying to model a flow-of-information type system to address issues like that. Basically, information about your deeds is passed around when NPCs come into contact with each other. So if you kill someone in secret or you kill someone out in the open and then kill all the witnesses, no one will ever know it was you.

That could get pretty complex pretty fast, but a very simplified version could probably be pulled off pretty easily.
#2
09/09/2004 (2:43 pm)
I've never played Morrowind or Gothic but I reckon that would get pretty damn annoying have someone magically know you killed them.

One thing we simulated with Operation Flashpoint was "Kill Mr. Big" the whole mission was for four players showing up without knowing the others were there to do the same job. You were given a $5000 dollars and an schedule of Mr. Big's movements, you buy weapons and explosives, transportation, plan your hit etc etc.

But also every NPC had a "Knowsabout script", if they saw something strange they would avoid you. Or if they saw something really strange (Like you were carrying a gun down the street) they would report you too the police. Then every police man on the island would be keeping an eye out for you. Hell if you drew too much attention they even called in a chopper.

Ofcourse you could get rid of people that saw you before they made a statement too the police but then you had to dispose of the body (we had a script to do that too!). It was heaps of fun to play. The scripting wasn't that hard so I'm suprised more games don't follow this path. We had 20 - 30 civillians occupying most of the towns on the island and it seemed to run fine.
#3
09/09/2004 (3:54 pm)
Brad: I like that idea. Passing little snippets of data from NPC to NPC about things they saw is a nice touch, especially for games that are related to stealth or spy games.

In Splinter Cell, there was a slightly similar system(doesn't seem to be as robust as the one mentioned for the other games) where people would run away from you in a panic if they saw you(well, you were dressed like a ninja, it made sense), and the alert levels would go up depending on what you did.
#4
09/10/2004 (2:08 pm)
The LifeLink AI and World Management System that is in development is addressing all the issues listed here and much more.

www.lifelinkai.com
#5
09/10/2004 (2:35 pm)
...
#6
09/10/2004 (3:02 pm)
It's still under construction, but you can e-mail me directly for any questions you may have. The site will have more details in the near future. My e-mail is tscott@magiqueproductions.com
#7
09/14/2004 (7:42 am)
@Ted: What you describe is the concept of Motivation. For those not familiar with AI i will elaborate and try to explain what i know and what i decided to use for our project. The AI can be broken down into 3 parts.

1.) Locomotion: Very basic motor skills. I know this might sound very simple but it is essential that the NPC knows how to walk, run, turn, jump, duck and cover. This can be further enhanced by things like using vehicles or giving types of NPC's a different set of motor skills. Examples could be that a farmer would not be able to use a vehicle or jump as high as a police officer can.

2.) Steering: This is where it gets more complicated and alot of games already fail. How to get from point A to B avoiding obstacles, other NPC's or threats (animals, swamps etc.). Those of you who played Command & Conquer know what i am talking about. There are several ways to solve this and given the surroundings some are better than others.

For outdoor levels the concept of Potential Functions is widely known to produce very good results. Unfortunately, it fails miserably indoors. It's very simple to implement. Starting with the ideal path (straight line from A to B) the NPC tries to avoid obstacles like trees by adjusting it's direction vector based on how close an obstacle is. The closer the more it will deviate from the ideal path.
A modified version of this can be seen in Far Cry. The NPC's will move to the closest obstacle on the ideal path to the player and hide behind it, shoot a few times from cover and then move on to the next one. Simple but effective. The problem is that it fails if you have a U-shaped obstacle. Taking this into account while designing the level should be easy though.

For indoor levels the Dijkstra algorithm seems to be a good solution. It's based on the weighted, directed graph theory. Nodes contain locations or states you like to reach, edges are bridges from one node to another. Each edge has a value that describes the cost to travel across the edge, and is unidirectional. All based on the assumption that we have a level with convex cells connected by portals. Sounds familiar? Of cause, that is what is used in most 3d games level design, well, you need a few more portals than you will most likely put into your levels. A search on the internet should give you alot of starting points. For those more adept with coding, here is a pseudo code listing of the algorithm:

struct node
vector< edge > edges
node parent
real cost

struct edge
node dest
real cost

while( priority_queue is not empty )
node curr = priority_queue.pop
for( all edges leaving curr )
if( edge.dest.cost > curr.cost + edge.cost )
edge.dest.cost = curr.cost + edge.cost
edge.dest.parent = curr


3.) Motivation: This is the most fascinating aspect, at least for me. The idea is for the motivation engine to decide on a very high level what the NPC should do. Examples can be: 'get health', 'attack nearest enemy', 'get food' or 'get sleep' (the last one written on a sticky note of my monitor to trigger my motivation engine while i am programming ;-). There are several solutions to code a motivation engine. I decided to go for the rule-based solution as it seems to be a good balanced solution. Here are some of the solutions i investigated:
#8
09/14/2004 (7:43 am)
... continued

NFA's (Non-Deterministic Finite Automata): Very popular and widely used. In fact, i bet every one who is reading this has used an NFA based engine. Search engines or the unix grep command use it. I won't elaborate as you can surely find alot of resources by using a well known NFA called google.

Rule-Based AI: I especially like this solution as it seems to fit nicely into the design process of a game. It's based on the fact that the world is governed by a set of rules. Rules control everything from the rising and setting of the sun to the way a car works. You define a set of rules that govern how things in your world work. This is very similar to the design process you go thru while defining how your game works and how you build levels. Alot of the rules can even be automatically generated or already put into a database while designing the game and levels. Here is an example:

Motivation: 'Get health'

IF [Health_Room == Visitable]
THEN [Health == Gettable]
IF [Security_Door == Door_Open]
THEN [Health_Room == Visitable]
IF [Today == Sunday]
THEN [Tacos == 0.49]
IF [Creature_Health < 0.25]
THEN [Creature_State = FindGettableHealth]
IF [Creature_Position NEAR Security_Console]
THEN [Security_Console_Usable]
IF [Security_Console_Usable] AND [Security_Door != Door_Open]
THEN [Creature_Use(Security_Console)]
IF [Security_Console_Used]
THEN [Security_Door == Door_Open]
IF [Creature_Move_To(Security_Console)]
THEN [Creature_Position NEAR Security_Console]

The goal would be [Health == Gettable], therefor the rule [Health_Room == Visitable] must be true. I think you get the point. AI like this is really nice because with a simple motivation like 'get healt', the NPC figures out how to get it all by it's own. If you encode all the rules necessary to do anything in your world then the NPC will be able to accomplish whatever goals it wanted. Like i mentioned before, i really like this cause alot of the rules can be automatically generated and it seems to fit nicely into the overall design process. The challange is of cause how to effectively encode the information or even let the NPC develop it's own rules as it goes along.

Neural Networks: This is definately the most complex of the solutions. Combined with good path finding and genetic algorithm to evolve the network, this could really kick-ass (excuse the language). It is really a nice idea to have a small town and let the AI just go along and evolve with the sole purpose of surviving. Some will go hunting, some plant crops, some will open shops to make a living. The successfull survive and get better at what they do. Could be really fun to watch how they evolve and what happens if a foreign influence (the player) enters this system and throws it off balance. Of cause they would evolve and mutate every day to make it efficient. Unfortunately i have to say that this is way over my head at the moment and too time consuming to implement.


For those who came this far, thanks for reading and i hope this helps you to decide how you going to solve the AI problem. This turned out to be a bigger response than i intended. Anyway, for our project i decided to use Potential functions and Dijkstra for path finding and rule-based AI for the motivation and problem solving.

For those interested in my progress, i will create a .plan in the next few days with updated information on the subject. I am not sure though if non torque owners are able to see the plans.

I am really looking forward on hearing your comments on this subject.

Regards,

Sascha
#9
09/14/2004 (2:53 pm)
@Sascha: Great information. I'm indeed using a rules-based approach for my bots, and you can get a lot done with if-then statements. Of course, on top of that will be a fuzzy-logic layer dealing with emotions to help things along. I think we're going to be seeing a lot of mixed AI techniques in games as time goes by, until something better comes along of course ;)

As far as path-finding goes, I think I'll have to look into those algorithms you talked about, since I don't have much experience with that.

Something I didn't mention was an idea I'd like to try with simulating a vision system for the bot in regards to pathing, and I'd like to hear people throw stuff at it so I can see if it's usable or not before I even put much effort in it? Here goes...

Basically, the bot will cast about 9 rays (3 high, 3 mid-level, 3 low) straight out ahead of the bot as it travels, and returns whether it hits an object or not. Now, the use of 9 rays is to see if the rays on either side come up "blank", and that will influence if the bot can turn left or right. If they all come up as hits(like in the case of a long wall), the bot would look both ways to see which direction is better to go. This is less for getting from point A to point B, but for realistic movement of bots that don't know everything about the area it's in. And I don't see it translating to interiors either. So does it have any merit at all, or was my crack dose way too high the day I thought of it?
#10
09/16/2004 (8:43 am)
Hiya Guys.. Been a bit busy to post, but I have been working on the AI and mapping while trying to take of real life problems as well. I ran into this and thought I could throw in my "Two Cents" worth as well.

Before I picked up the Engine here I had been testing some AI functions using "Wolfpack", (A little hunting and you'll find it's an Emulator for UO). I was not impressed with the ridiculously simple AI in it and new I needed a better one for my own game at some point. So being a Medieval setting I implemented a combination using the Following:

Creature AI's had the following System:
1:Level of Intelligence. (Smart Dumb Mindless, etc..)
2:Alignment (Good, Neutral, Evil, Animal)
3:Behaviour type (Hunter, Prey)

I then used a system that checked for surrounding creatures, This included players. It then went through a test to check if any creatures were of interest. They were added to an array if they were in range. Then a sub test for most desireable target, modified by intelligence. Then it tested for Range. The closest most desireable target was chosen and attacked.

I had quite a bit mopre then that involved, such as Certain Intelligent Creatures were more prone to attack different classes if it had a choice, (Made Wizard class a bit dangerous in some cases).

This worked well as Good wouldn't attack Good and Evil usually didn't attack Evil (Except in certain instances such as Animals attacking).

It was amazing how this fairly simple system made the game so much better. The only bad part was it could get very intensive in CPU useage at first. It took a bit of struggling to reduce the code to a more practical system that kept as much variety while working quickly.

It still had problems in large crowds. The basic concept is good, but I have to move it over to my Non-Linear concept instead of the original linear system that I had to deal with at the time. By moving away from Linear processing it will reduce a large amount of the Lag time as I can then process this mess in parellel instead.

This basic system is a good starting point though for some and can easily be modified to any game system.

mythic
#11
09/17/2004 (8:36 am)
@Ted, It depends alot on how complex your AI is going to get. I am sure that alot can be done in script with simple ray casting and some if statements. This is going to have an impact on performance pretty soon, if you think about a small town with alot of NPC's going about their daily activities.

Let's stick with the Town concept for simplicity, since in most cases you wan't those townsfolk to stay inside the town anyway:

The engine does all that neat lightmapping (once) before you can play a level. This is done for all Static Shapes and interiors. Basically exactly what we need. Everything that is static in the world we don't have to find in realtime.
The idea is to create a map of the area/level and store that once. Take the mission area, get the bounding boxes (for simplicity) of all Static objects and create convex cells around them to fill the mission area. Encode the map in an efficient way (if someone has a bright idea let me know) I was thinking about a binary tree...
The NPC knows what cell he is in checks if in that direction is an adjacent cell and moves straight to that cell. Very simple and effective. Since you already know all adjacent cells immediately anyway.
Obviously this is a very stupid NPC as he will run into a dead end and then suddenly realizing he has to go back. In reality you would check a few cells ahead and avoid the dead end unless that is where his goal is (if he has one).
I am sure you get the idea, no ray casting necessary at runtime, just simple math.

@John, great stuff for a medieval rpg. Assuming that a NPC knows the attributes of the other NPC's (he sees different sets of attributes based on his intelligence) you could apply a simple rule based system. This would also have the neat side effect that more intelligent NPCs will run away or try to find health, whereas stupid orcs would just defend themselves as they won't know that the attacker is stronger/has more life. This has to be fine tune becuase as you already mentioned, the smartest will kick everyone's butt pretty quick. Put a smart Wizard into an orc village with some re-spawning healt and he will wipe them out pretty quick. Could be interesting to watch.


Since Oktoberfest is starting in Munich this weekend and i avoid it like the plague, i have alot of time to test some of the ideas. Wish me luck, this could be a rough ride.

Sascha
#12
10/26/2004 (9:46 am)
Here are some things that I'd look at:

Hierarchical Task Network
The Sims 2

When you look at The Sims
You have:
individual personality profiles (neat/sloppy, nice/grouchy, etc)
skills (cleaning, cooking, etc -- these slowly improve)
statistics (hunger, energy, etc -- constantly changing up and down)
aspirations (I want to be a business mogul,etc -- more fixed)
wants (I want a promotion, I want a new TV,etc -- fairly fluid)
fears (a fire, losing my job, etc -- fairly fluid)

The individual attributes can be used to derive aspirations/wants/fears.
The HTN is one way that can be used for the AI to plan to get the results.

i.e. if you want to be a business mogul you should be working in the business field.
In order to become the mogul you want a promotion.
In order to achieve a promotion you need to make friends, increase skills, etc.

Artificial Emotion also comes into play in The Sims 2.
You have ratings for each and every sim a sim is aware of.

Any interaction that can be executed could/should touch on all of the pieces for the 2 (or more) sims involved.
These interactions could also pass the bits of information the sims know about.. i.e. I saw bob with a gun.. Or I saw bob kill dave, etc.

In the hunter selling to the shopkeeper example:
hunter gets killed..
For the people the shopkeeper meets he passes on the info that he is buying skins and meat.
Eventually some other NPC in town will decide in order to earn money he should become a hunter and sell to the shop keeper.
Which would then set that NPC down the path to becoming a more skillful hunter.

The problem with a fully dynamic system is that all the mobs/npcs start becoming *too* powerful.
That lvl 5 hunter might be lvl 20 after a week.

The birth/life/retirement/death cycle in the sims is interesting.. But if the player is on the same cycle that doesn't help the too powerful npc/mob problem.

But if when the hunter got too powerful he moved to a new area (i.e. a larger town) and an apprentice replaced him..
But eventually your going to end up with alot of powerful npcs/mobs hanging around somewhere.
Which may or may not be a problem depending on your game.

One of the things to remember is that an AI entity does not have to be an actual NPC.
For example a town can be an AI entity.
It wants to have x number of residents.
It wants x blacksmiths.
It wants x hunters, etc.

A state can have X towns underneath it.
A country can have X states underneath it.

That's where the HTN really shines..
You have different types of tasks at each level.. which generate lower level tasks and feed higher level tasks.
The attributes of the entity and the environment determine which tasks get choosen.

The town knows that the hunter was killed. Since the town is a lawful town:
It can choose to put up a reward for information.
It can choose to send out search parties.
those are all done by adding the task to one of the town residents.
i.e. put in the sheriffs tasks that a reward or search parties should be sent out.
If a corpse is found the sheriff would probably decide to put out more patrols, a bounty, etc.

this could also be done via the hunters wife.. i.e. she goes to the sherif, etc.
But the notion of the town as a collective noticing the loner hunter is pretty realistic and can be fairly easily done with a town entity.

-Jerry