Best way of defining NPC behaviour

Started by
41 comments, last by C-Junkie 19 years, 8 months ago
Quote:Original post by OmniBrain
Glad you see it the same way like me. Personally I HATE NPCs doing their scripted business and never care about changed environment.

Agreed. I mean, if your shop is on fire, you don't just keep on trying to sell your wares.
Quote:
And as a plus I like to play my own game and being surprised about the action of the NPCs. Giving them just a goal and some behavior parameters and finally watch this turn out into actions I didn't think about is almost a game itself to me.

Heh, that's the nice thing about a suitably developed goal oriented AI, it's behavior should change from run to run, but should stay relatively consistant globaly.
Quote:
Probably the control of a single agent is the same like playing a complete army in an RTS.
In a RTS you as the comander have global GOALS (usually survive and destroy the enemy). You pick some STRATEGIES for your army that are fit to help you getting closer to your GOAL, and on the lower level you have to pick some TACTICS that help you to perform your STRATEGY.

Hrm, about the only RTS, or RTT games that actually allowed for that are the total war games. The rest mostly rely on building up a massive army and then just using overwhelming force (very boring)
Quote:
Now how can this mapped to NPC behavior?
As there are multiple layers of comand in military, there are multiple layers of decision finding with agents:
An agent has GOALS (survive, become rich, kill the murders of his parents).

So, we have agents that represent a general character or set of characters? Now, when i say set of characters, think of a kingdom that is being invaded... Each person in the kingdom will have goals. However the kingdom as a whole has some overwhelming goals.
Quote:
To survive, the STRATEGY is to stay away from danger, and drink/eat regulary.
To drink regulary the agents TACTIC may be to stay close to a river.
The goal of "become rich" will make the agent move to locations with much business, or to areas with resources that can be sold for a good price elsewhere.

hrm...i think we need a better set of terminology than strategy and tactics.
Quote:
(The "kill murder of parents" goal for agents is really a big task and I probably have reached goal "become rich" when I can code this behavior in a few lines of code with taking less than 1% of CPU time. :)

Remember, he did say that he was targetting platforms of the future, so we can imagine that CPU power is not an issue.

In time the project grows, the ignorance of its devs it shows, with many a convoluted function, it plunges into deep compunction, the price of failure is high, Washu's mirth is nigh.

Advertisement
Well I think the problem might be simpler if put in 'layers'

layer 1 : basic human instincts, like survival (dont stand in a burning building, or fight or flight reactions

layer 2 : basic needs based on percents of importance food, drink, sleep

layer 3 : small goals like open shop, or take flowers to girlfriend

layer 4: grand goals like rule city, become king, take over world

something like that with layer 1 being most important and the latter layers being less, of course this would be based on a npc's 'character' greedy, frinedly, power hungry and so on.

also if the different attributes of an npc, such as personality are modeld off of real people who can be categorized into groups that could simplify things,
like you have the politician type, poet love child type, angry violent type, crazy programmer type. These would all have similar goals and needs.

I remember back when I played Ultima 7, and I got into the debugger, and it listed what the npc's were supposed to do at any certain time in the day. This is of course a perdictable and unchangeable thing, but it made them seem so much more lifelike than most npc's i see in modern games. Even modern rpg's the npcs just seem to stand around. Looks like more games could at least use a list or somthing to make things a little more realistic.
Quote:Original post by SelethD
layer 1 : basic human instincts, like survival (dont stand in a burning building, or fight or flight reactions

layer 2 : basic needs based on percents of importance food, drink, sleep

Ok, these two should really tie into each other, the goals at layer 2 should be dictated by the needs of layer 1.
Quote:
layer 3 : small goals like open shop, or take flowers to girlfriend

layer 4: grand goals like rule city, become king, take over world

In this case however, i would think that layer 4 would dictate layer 3s goals. Because the over arching goals should be powered by the smaller goals. So each smaller goal should be a step on the road torwards achieving a grand goal.
Quote:
something like that with layer 1 being most important and the latter layers being less, of course this would be based on a npc's 'character' greedy, frinedly, power hungry and so on.

Only problem I have with this is that layer 1 being the most important would perclude heros. As survival would end up preventing the hero from stepping into situations where he will most likely die.
Quote:
also if the different attributes of an npc, such as personality are modeld off of real people who can be categorized into groups that could simplify things,
like you have the politician type, poet love child type, angry violent type, crazy programmer type. These would all have similar goals and needs.

ugh, real people are so shallow...who would want to mold game characters after them. However, the grouping idea would give some idea as to what initial weights each of the goals should be given, and then with minor randomization, it would be adjusted to make the characters unique.
Quote:
I remember back when I played Ultima 7, and I got into the debugger, and it listed what the npc's were supposed to do at any certain time in the day. This is of course a perdictable and unchangeable thing, but it made them seem so much more lifelike than most npc's i see in modern games. Even modern rpg's the npcs just seem to stand around. Looks like more games could at least use a list or somthing to make things a little more realistic.

Yeah, even in mmogs. Of course, the real problem is managing all of that information. Even for a relatively small number of NPCs, building a system like what we are discussing, and keeping it stable is not easy. That is perhaps the hardest part, keeping it stable, as most cases will degenerate fairly rapidly, or oscillate between two or more degenerate states.

In time the project grows, the ignorance of its devs it shows, with many a convoluted function, it plunges into deep compunction, the price of failure is high, Washu's mirth is nigh.

since we are wasting imaginary processing power anyway...

each NPC could also have a set of beliefs/morals, which could help dictate how they try to accomplish their goals. for example, say two NPCs are starving and poor; one might go beg or find any crappy job (cleaning stables? not too bad if you need the cash) to earn some money, whereas another might turn to a life of crime. this would help give more diversity to the behaviors, i think.

i could ramble on, but i'd rather just toss that in and watch some more. :)

EDIT: the thing that made me say this (and which i forgot to include at first) was Washu's comment about there being no heros. there still could be, for those NPCs whose beliefs included helping the innocent, saving the world, and always doing the right thing, even at the expense of their own personal safety and well-being.

mmmm... although, this could possibly be simulated just by adjusting the weights of those goals and such anyway...
--- krez ([email="krez_AT_optonline_DOT_net"]krez_AT_optonline_DOT_net[/email])
Quote:Original post by krez
each NPC could also have a set of beliefs/morals, which could help dictate how they try to accomplish their goals. for example, say two NPCs are starving and poor; one might go beg or find any crappy job (cleaning stables? not too bad if you need the cash) to earn some money, whereas another might turn to a life of crime. this would help give more diversity to the behaviors, i think.

Hm, if I haven't mentioned it before I should jump on now.
You have goals on the different layers, and there are rules how to transpose the goals from layer to layer. These rules now define the way how an agent will solve any problem/goal.
Either you only activate some rules for a lawful character on how to get money, or you define the rules more complex to fire different unlawful ways to get hands on money if a "morale" attribute is low enough.

So from top to down a character would decide for a solution to reach a given goal, and this will set up new goals on the next layer.

Just as example:
goal:Survive (rule:eat regulary) -> goal:get food (rule:go to public food storages) -> goal:head to apple trees ==>> result: char moves to closest apple tree

a less lawful NPC could fire (rule: burglarize into food shop)


the trick now is to decide which goal on each layer you want to follow, or do it the fuzzy way and calculate the strongest goal on the lowest layer to perform it (a goal on the lowest layer should result in an easy, single action).
-----The scheduled downtime is omitted cause of technical problems.
A whil back I did get quite a way in designing a system like this. From my experience, I had quite a bit of difficulty creating a usable knowledge-base for the NPCs - not so much of a problem if you don't allow for 'false beliefs', but less realistic obviously.

But what really stopped me was when I realised I'd have to implement a natural language parser to allow the NPCs to communicate with PCs. Because if they can't express themselves, I suspect their intelligence will go mostly unnoticed.

If I can dig the code up (Java), I'll document the design and post it.
Quote:Original post by Spalaen
A whil back I did get quite a way in designing a system like this. From my experience, I had quite a bit of difficulty creating a usable knowledge-base for the NPCs - not so much of a problem if you don't allow for 'false beliefs', but less realistic obviously.



As mentioned before, I am working on such kind of system actually. (So far the knowledge only holds geographical information (knowledge about locations), but it works pretty well).

I don't see the problem with "false beliefs" you spoke about. If our agent believes there is gold at a certain location because someone told him (and he trusts the source of this information) he just can add this information to his knowledge. Maybe he will not weight this information that strong as he would when he had observed the treasure himself.

This way I (the player) can go to a NPC and tell him about a big treasure in that cavern behind the hills. The greedy NPC will follow his goals to become rich, not knowing about the dragon guarding the treasure. The dragon eats the NPC, and I got rid of that stinking NPC.


Quote:Original post by Spalaen
But what really stopped me was when I realised I'd have to implement a natural language parser to allow the NPCs to communicate with PCs. Because if they can't express themselves, I suspect their intelligence will go mostly unnoticed.

It is pretty easy to build up a way to bring the knowledge into natural language, so the NPCs can tell the player what they believe. For the localized knowledge for example check if the location you want to talk about is close to a well known mark (e.g. "the dead hills") or pick your actual location to refer. Now you can determinate the direction and the distance and transform it into text.
As directions you have some words like "south", "where the sun is closest to the sky" ...
distance is "XXX Miles", "XXX hours riding a horse", "XX hours hard walk" and so on.
Add this up you get stuff like:
"From <<the dead hills>> heading <<south>>, <<3 hours of a mans walk>> you can find <<plenty of treasure>>."
"From <<here>> heading <<to the sun's highest mark>>, <<2 hours riding your horse>> you can find <<wealth never seen before>>"

Telling NPC's some stuff they shall add to their knowledge is somewhat harder, but if you present some clever way to describe the same keys as above (reference location, direction, distance) you can do it with simple mouse clicking. For sure typing in the information and the NPC parse it and add it to his knowledge would be much more fun, but (actually) not realistic at all.

-----The scheduled downtime is omitted cause of technical problems.
Quote:Original post by Spalaen
A whil back I did get quite a way in designing a system like this. From my experience, I had quite a bit of difficulty creating a usable knowledge-base for the NPCs - not so much of a problem if you don't allow for 'false beliefs', but less realistic obviously.

No real reason to disallow false beliefs. Also, each character should have a database of information that they have heard or otherwise learned about. This information should age, and the older it gets, the harder it is to retrieve from the NPC. This way we can simulate forgetfulnes that results in sparks of inspiration (a conversation triggering a memory)
Quote:
But what really stopped me was when I realised I'd have to implement a natural language parser to allow the NPCs to communicate with PCs. Because if they can't express themselves, I suspect their intelligence will go mostly unnoticed.

If I can dig the code up (Java), I'll document the design and post it.

Depends, I mean if you restrict the grammar somewhat severely, then you can build a fairly decent natural language parser without much dificulty. I think the biggest problem is just the sheer number of exceptions in the english language. It makes writing more complex parsers very hard.

In time the project grows, the ignorance of its devs it shows, with many a convoluted function, it plunges into deep compunction, the price of failure is high, Washu's mirth is nigh.

Didn't it start with Ultima 5? You know, the NPCs having "jobs" and "homes". If you entered their house at night, they'd be in the bed, asleep. If you went inside their house in the day, they'd be gone to their job. They would also move to and from their homes and jobs.

Well, ever since then I've wanted to do something similar if I ever get to that point in my game(s). And the things you guys are discussing are really exciting.

It would be neat to make a test bed consisting of a game engine like U4 or U5, or maybe even simpler, where for starters the NPCs are given "homes" and "jobs". They are told where they can "eat" and "sleep" and "work". Once a small village is up and running, the methodologies could be enlarged to include several villages, then cities, until thousands of NPCs are being modelled in real time as the player goes about his business. Additional goals/needs could also be added as desired, once the basics are implemented successfully.

It would have to be time sliced of course, where a batch of NPCs are operated on at a time until all of them are covered. Some kind of prediction/interpolation could be used as well, but may not be necessary.

The immediate goal would of course be to get a basic working simulation up and running as opposed to trying to implement realistic human behavior. I mean, in the early Ultimas all you could do was ask the NPCs their names, health, job, and tell 'em bye, and a few other keyed pieces of info. It would be awesome just to get a working village up and running where the NPCs did as mentioed above: slept, worked, and ate. After that add some memory, so they could remember who they saw each day and some basic things that happened or were going to happen.

In other words, keep it simple. Right?

On that note, does anyone plan on actually coding a test bed?

Take care.
Florida, USA
Current Project
Jesus is LORD!
The way I was thinking of NLP to get information into NPC's was quite simple really. The NPC's of a certain world speak a language that is based very strictly on rules. In their own language you can only really be able to say something in one way. As for the language semantics I am still fleshing those out, but that is really beyond the realms of this discussion.

Morals are a perfect layer... First you have the needs layer which of course makes decisions as what you need to do in the moment. The morality layer guides what actions the NPC should take upon these needs. Upon that, Goals should also be guiding the process at the next layer so that steps can be taken towards this goal that are at one or at least not at odds with the direct need.

So how exactly do we go about defining a goal? What exact way should we be able to break down goals to steps in our games? Goals as locations are usually easy to incorporate, but anything more vague than a direct location becomes a design issue to implementation. Sure a goal could be an action against either a location or a person, either way this is a specific target, but what if the goal is more of a general feeling? How would you go about defining a goal as something like "I want my village to be safe"?

We could think about safety of the village as safety of each of its inhabitants (or at least a majority of its inhabitants). But then what if the village is divided about a topic, and the goal is more specific than just safety of the village. Say the village is in fear of an unknown evil and you need to destroy that evil, even though half the village want to destroy the other half of the village?

Sounds outrageous? Well, probably, but we should think of different kinds of methods of defining our goals, needs and morals.

This topic is closed to new replies.

Advertisement