Author Topic: Monster/NPC AI.  (Read 1555 times)

lyistra

  • Hydlaa Resident
  • *
  • Posts: 79
    • View Profile
Monster/NPC AI.
« on: January 06, 2005, 08:09:10 pm »
One of my biggest peeves on any game is bad monster/NPC ai.  I hate being able to go into a room on most muds, kill a guard, and have four other guards stand around and look at me, saying \'hi\' and silly things like that.

So, in this thread, I\'ll discuss pros/cons/caveats of npc AI, potential methods for achieving a decent level of intelligence within the system, and means for achieving the goal.

While more or less a novice programmer (programming in LPC for a mudlib I wrote) I have studied extensively on various AI methods, from genetic programming to neural networks.  In addition, I have a fairly decent background in psychological phenomena, (emergent phenomena versus inherent) and motivation/thought processes.


I tried this post once before, so I\'m trying again.  Here are the things that I feel are vital for a good A.I.  These will be broken down in either subsequent postings, or this posting itself, and potentially I will offer some observations/ideas for creating the systems themselves, should anyone be interested, though I\'d prefer to do that via private message.

1:  Responsiveness.
2:  Planning
3:  Motivation
4:  Pathfinding
5:  Entropy


The first point was raised in the introduction to this paragraph.  Nonresponsive NPCs, that don\'t respond to outside events.   The simplest of the responsive NPCs I\'ve programmed rely on catching events in the surroundings, and simple pattern matching (via regexp or sscanf) similar to how I imagine the query functions for Planeshift NPCs work.  This is ok to a point, but usually there is little that actually can be programmed this way, and it can only respond to things within the devisor\'s programming.

2: Planning.  
A sticking point for 99% of AI everywhere I\'ve seen.  Rather than sending in an overwhelming mob, most AI allows defeat in detail, due to poor planning/terrain control/pathfinding.   Planning is one of the most complex systems within A.I, as it has to determine the current \'state\' of the system, then interpolate how to get from point A to point B.  This is one of the things that I have been working hardest on in my own work.   It comes down to a problem of both semantics and conceptualization.  Often things that can be conceptualized cannot be brought into words, and vs/vs.  Semantics often don\'t translate into concepts via noise in the communication, as well.  In addition, our current understanding of though processes themselves is lacking.  This can actually be either moved to its own forum, or perhaps worked through in private message, as it\'s a fascinating field for me.  More or less, to sum this up, it\'s not a problem of getting from point A to point B, it\'s a problem of the sequence of steps from point B to backwards chain to point A.   Probably most of this could be accomplished by creating binary trees for object locations, and treating objects as attachments to nodal points on the trees using a weighted djikstra algorithm to allow for planning for the best means of getting there.

3: Motivation
The motivation of the A.I. can\'t be understated either.  The simplest motivation system is a simple bit, that says \'this monster is aggressive\' or turned off, not so.  A more complex version might say that \'this monster is aggressive to \'.  A far more complex version might be \'this monster is aggressive to unless is present, and when the time is .\"  the one I\'m after, and have been working on, actually allows the creature itself to learn, to some extent.  This would be an excellent place to attempt to test the conceptualization and attempt implementation, really, of the idea.  

I.e. Monster behaves in way towards when the emotion flags read with a 45% entropic modification, because he is insane.  However, with approach is done, modifies its behavior.

Motivation is complex, and can be accomplished several different ways.  In \'the sims\', not to bring up a relatively pointless product, but to illustrate a point, they have happiness/sadness/etc indicators, which help determine the personality.  Using these as a seed for the algorithm, as nearly as I can tell it can modify the values directly.  To speed this problem up, binary trees could definitely be used, or perhaps hashes.  really hard to tell what would be most efficient in this instance.  (I know the simple multiple array one of my friends was using is very inefficient for it, especially in an interpreted (bytecode) language).

A modification of this could actually be fear, interest, or even, should you go so far, desire, jealously, and lust.

4:  pathfinding.
Extremely annoying is the fact that monsters aren\'t bright enough to *not* walk off cliffs/platforms, and then disappear off the map. *chuckles*  Simplest way to do this, is to create a set of nodes throughout yklaum, in the main pathway areas, and safe traversal areas.  This could be done in the database, likely with xy coordinates, and a node connected by a pathway at each point.  This pathway could be modified in a number of ways for the conditions, which means that it could be extremely flexible.  Using djikstra, you can calculate any given path, and get the set of all paths between all points (a  lengthy  calculation given the potential number of nodes, just in the city)  But the best part of this is,  you can cache the results, use the nodal set as a container class, then move objects between nodal areas, or even between active nodes.  The paths could be complicated greatly by simply setting up a certain amount of randomness in the paths of the nodes, and a certain amount of deviation from the node path, itself. (i.e. an algorithm designed to allow the NPC to \'wander\' between certain guidelines)

5:entropy
Discussed in several of these points, the inherent randomness of the system.  It allows NPCs to do more realistic behaviours by not following rigidly set paths.  And allowing them to make \'bad\' decisions.

6: cooperation
This one is a fun one... you see a single gobble out in the middle of the sewers.. then all the sudden you\'re ambushed by them all.  Or you kill someone in city limits, and the guards seal the exits, and start a search through the city, only allowing others to escape.. but perhaps there\'s a secret exit in one of the labyrinth paths....


Many ways to set up cooperation, the simplest is with just messaging between NPC objects, with a \'master\' object coordinating it.  I.e. the \'leader\'.  Recognize and kill the leader, and they become a rabble, and much easier to eliminate.

However, sometimes the leader isn\'t what they seem...

Any and all points in this can be discussed at length.  And examples given of potential code to accomplish some of it.  A lot of what I\'m thinking of may involve caching results from background computations, and recombining it with others, creating a viable path, which will accellerate things substantially. (cached data being far faster than recalculating the dataset).  At that point, it mostly involves adding nodal points into the mapping.    The biggest caveat of this system is simply that it grows very complex, and the complexity grows exponentially, though the computation may not have to, using djikstra.  Part of it involves testing with genetic algorithms, part involves caching, and part involves psychological phenomena.

Considerably more than .02 tria...

Lyistra.

dimaq

  • Hydlaa Resident
  • *
  • Posts: 87
    • View Profile
all is talk
« Reply #1 on: January 10, 2005, 02:03:02 pm »
now if you wrote a plugin for planeshift (difficult), or a standalone NPC library (you might be capable of it you never know), I\'m sure the devs would appretiate!

if you want a practical test - try scripting a character to go aroung Yiliakim and gaining exp and money and convering them to predefined skills at least.

Count

  • Traveller
  • *
  • Posts: 20
    • View Profile
(No subject)
« Reply #2 on: January 10, 2005, 05:26:47 pm »
@lyistra:

This all sounds fine, but it would be very difficult (if not even impossible) to implement all this in PlaneShift. Remember that the game world will not remain in it\'s current state but become bigger and bigger, and so there will be more and more monsters and NPCs that afford A.I.-computations.

Nevertheless, I think the waypoint-system is a good idea and should not be too complicated to be implemented in one of the next versions. It  will not consume too much memory or need to much computation time.

From my point of view, responsiveness is a \"must-have\" in such a complex game. I would propose an approach like in \"Neverwinter Nights\" from Bioware. There, every Monster and NPC is assigned to a \"faction\", and each faction has values which represent the relationships with other factions. Single PCs, character groups and guilds could all be represented by own factions, and if a member of a faction starts a fight with a member of another one / steals from another faction / whatever bad thing you can think of, the two factions get more hostile towards each other, so that at some point, members of both factions attack each other on sight.
That was just an example for relations getting worse. If a member of faction A helps a member of faction B with something, relations could get better, to give an example for the other side.

lyistra

  • Hydlaa Resident
  • *
  • Posts: 79
    • View Profile
(No subject)
« Reply #3 on: January 13, 2005, 10:21:26 pm »
A good set of points.  However, with the system I propose, cache recalculations are done (in worst-case scenarios) when the server is down, or within a background process.

In addition, not all NPCs can (or should) have an advanced AI.  Simple responsive AI (or rather pattern matching) is more than enough for rats and the like, depending on the vision of the designers.  And, as per the prior point, I\'m working on a module for some of this, as soon as the darned Gentoo install completes. *chuckles* (easier by far to get compilation programs for Linux, than paying through the nose to Micro$lop.)

At any rate, I\'m glad to see at least some interest in the idea.  Part of what I\'m seeing is that actual recalculation of the entire cache will be extremely expensive (cpu/memory wise) however adjusting nodal links is less so. (pointer reallocation, with garbage collection for unreferenced pointers).  At this point changes within the game itself simply patch the current midpoint goal with a precached secondary goal.  I.e. your goal is \'open the lock\' so you have to \'get the key\'.  The \'key\' is in the \'chest\'.  Each of these are nodes.  If a player, which is an additional, nonreferenced object node within this plan, picks up the key, the \'key\'s location is updated to the player, then the player becomes a midpoint goal in order to get the key.  The most complex version of this AI system will require further research.  I may go ahead and write this up as a thesis paper later, but it\'s an interesting phenomenon.  Allowing a certain amount of genetic recombination for entropy (relatively simple, simple bit of randomness within result sets) will be necessary.  Looping is another major problem, i.e. inclosed mid-term goals, or self-referencing goals.  Lots to think on, so I\'m going to work on that in a bit.

Alphi

  • Hydlaa Resident
  • *
  • Posts: 66
    • View Profile
Re: Monster/NPC AI.
« Reply #4 on: April 29, 2006, 10:46:56 pm »
I read somewhere that the NPCs are controlled by a seperate APP..
theres absolutely no reason why AI logic cant be distributed across many machines..

it would have no effect on the server if an NPC (or batch of smart NPCs) was controlled by another computer similar to the way each of us controls our character...

infact parallel processing is excellent for controlling large batches of individual AI threads.
even if you didnt have the resources to add additional servers for AI logic.
you could farm it out to the players pcs by incorporating the logic into the client app..

ie the client app could control the users Character and also and additional NPC somewhere else in the game world.

there would only be a few draw backs for this technique

1) a slight increase in trafic between the client and the Server... (as you would need to piggyback the movements of an additional NPC onto the existing characters packets)

2) the controlled NPC would cease to be smart as soon as the player disconnects... for monsters this is no big deal.. for other NPCs this could be problematic.. however a counter measure could be that if an NPCs AI is stops responding then the NPCs AI logic is re spawned onto another client pc.... so at worst the NPC would stop responding for a few seconds...

this way you could have LIMITLESS processing power for AI... as more people join Planeshift more processing power is instantly available for AI.....

I dont know of this idea being used in any other games... but I've seen it being used very effectively in the SETI online project.
you might even be able to patent it for gaming...




steuben

  • Veteran
  • *
  • Posts: 1834
    • View Profile
    • Myspace
Re: Monster/NPC AI.
« Reply #5 on: April 29, 2006, 11:01:35 pm »
two words. hacked client.

and distrubuted works best when the clients don't have to communicate with each other. ith a distributed npc ai client each critter will have to comminicate with each other, especially if you want them to do anything more creative then follow a line.
may laanx frighten the shadow from my path.
hardly because the shadow built the lexx.
the shadow will frighten laanx from my path.

Alphi

  • Hydlaa Resident
  • *
  • Posts: 66
    • View Profile
Re: Monster/NPC AI.
« Reply #6 on: April 29, 2006, 11:40:31 pm »
they dont...

the mmorg is client server model not peer2peer...

anything that I can do on my pc to interact with the other creatures in the game.. an AI program can also do.
all it takes is additional local processing power and band width thats it..

if you can hack that AI you can also hack the existing client app to benefit your character...

I'm not suggesting any logic to do with creation or generation of NPCs or Items be done on the Client Machine...
none of that has to...

all I am suggesting is that the Decision making logic for NPCs ie walking around who they are going to fight etc is done in a distributed way..


if your suggesting somehow someone could hack into the AI and make a monster become a virtual drone and succumb to their will.. then yes I suppose that is possible... but what good is that when the drone is on the other side of the game area...

it is far simpler to hack into the existing client and make my character sit at a spawn point and hack down and loot every single monster that appears 24 hours a day 7 days a week or make my character dig for gold constantly that it would be to hack the AI of a random NPC monster... and it would also be more effective..

Distributed AI would definately give this MMORPG a huge advantage over other games as the potential for the SMARTS behind each NPC would not be limited to processing power at the server..
 

steuben

  • Veteran
  • *
  • Posts: 1834
    • View Profile
    • Myspace
Re: Monster/NPC AI.
« Reply #7 on: April 29, 2006, 11:46:25 pm »
at best you are exchanging a lower server load for generally increased lag. any decision that the ai makes will have to be bounced through the server to other clients for update. or sent to directly to the other clients.
may laanx frighten the shadow from my path.
hardly because the shadow built the lexx.
the shadow will frighten laanx from my path.

Alphi

  • Hydlaa Resident
  • *
  • Posts: 66
    • View Profile
Re: Monster/NPC AI.
« Reply #8 on: April 29, 2006, 11:55:48 pm »
it would be no different to having a game where ALL of the players are User controlled characters.

if I talk to another character through my client is there lag ? degraded performance ?

if we replaced all NPCs with People would the games performance grind to a halt ?

client side distributed AI was only one option..

you could also have dedicated AI servers which are positioned in the same room as the Game server.. connected via a gigabit switch.. there would be absolutely NO LATENCY penalty..
infact the game would run smoother because a great deal of processing is offloaded to additional servers.

minetus

  • Hydlaa Citizen
  • *
  • Posts: 461
    • View Profile
Re: Monster/NPC AI.
« Reply #9 on: April 29, 2006, 11:56:21 pm »
Quote
2) the controlled NPC would cease to be smart as soon as the player disconnects... for monsters this is no big deal.. for other NPCs this could be problematic.. however a counter measure could be that if an NPCs AI is stops responding then the NPCs AI logic is re spawned onto another client pc.... so at worst the NPC would stop responding for a few seconds...

a solution to this could be perhaps..
when the client disconects.. the monster gets dumb.. and after a PC kills the monster it could just vanish and not respawn.

the whole concept looks awsome, were there would allways be enought NPC monsters for every one..

Alphi

  • Hydlaa Resident
  • *
  • Posts: 66
    • View Profile
Re: Monster/NPC AI.
« Reply #10 on: April 30, 2006, 12:08:27 am »
effectively if the pc disconnected then the game server would know this.. and activate the AI logic on another persons client to take over..

it would be as if you had disconnected your session and went over to your friends place and logged back in again..
you are exactly where you were when you logged out..
same would be true for client side AI controlled NPCs.
 

someone fighting an NPC moster at the time would notice for maybe a split second the character would pause. then attack again...

its a trade off ofcourse but the benefit is you get an NPC with the potential brain smarts you see when you play a game like Age of Empires against the computer..




dying_inside

  • Guest
Re: Monster/NPC AI.
« Reply #11 on: April 30, 2006, 12:23:47 am »
 I have heard that Pathfinding scripting is extremely bulky and can weigh the server down alot. I admit there should be a little bit more of some kind of reliability that they wont just run into a wall or somthing but for now as its just a Alpha test then i'm happy for the Devs to get the main functions of the game up before they branch out too much into detail on particular subjects.
I would also like to see co operation, this could simply be achieved by one NPC following another and another of they come withing certain ranges, they will then move and act as one. But like I said, seeing as this game is in Alpha I dont expect anything like this for a long time to come.
« Last Edit: April 30, 2006, 12:25:37 am by dying_inside »

Vengeance

  • Veteran
  • *
  • Posts: 1452
    • View Profile
Re: Monster/NPC AI.
« Reply #12 on: May 02, 2006, 04:42:12 am »
All of these are fine ideas I guess.  The question is how to implement them well and implement them efficiently within the game we have.  Saying "use dijkstra" to answer one of these posts is like telling a violinist to "play some Bach" to make a party more interesting.

I'll address your post on two levels, since you have put a lot of thought into yours.  First, why exactly do the npc's need to be smart?  I get the "don't walk off cliffs" part, but why do they need motivations and fears and lusts?  They exist in the game to be obstacles to the player, nothing more.  They are cannon fodder.  If we make the npc's fight extremely smart, it means that players of the same level can't beat them like they used to, so they go find lower level ones to kill, and everyone moves down a notch.  In the end there is no difference, except that now the n00bs can't kill the rats either. :-)  It's like saying that the ghosts in Ms. Pac Man should be faster.  They exist only to provide a challenge, not to simulate real ghosts in a real maze.

Second, otoh, I'll contradict myself and say that our intent is definitely to make the npc's better.  Much of what you talk about is already implemented.  NPCs can have motivations and needs today.  We have a faction system which allows a rat to attack one person when he sees them and not to attack another person.  We don't use the faction system today but the game supports it.  Pathfinding is necessary but it is a LOT of work to make all the navigation nodes.  Someday we'll do it but right now we have other priorities.  The AI system is set up to be a separate and distinct executable from the server, so that it can be distributed across several machines.  We call one of these a 'superclient' because one program can manage 200 or 300 concurrent mobs the way you run one character in your client.  What's more, as long as you implement the network protocol the server is expecting, you can do the AI any way you want to.  Make one with pathfinding and another with random bouncing.  It doesn't matter.  I wrote the first superclient, called "npcclient", just to get us started and to serve as an example to other, bigger AI experts than me.  Others can write others and we can have all the npc's coexisting on one server.

Third, look at who is on the engine team and what they are working on.  Is making the rats smarter really the highest priority?  There are only about 5 active programmers and only a couple have experience with npcclient in particular.  What about crafting?  Should we fix magic?  What about guild houses and instanced dungeons?  We like combat but it is intended to be 10% of the game, not 99%.  This is not a stealth shooter where the intelligence of the npc's is paramount.  It is a virtual world for players to RP, socialize and adventure together in a number of ways.  And the few of us coders have to invent all these ways of interacting, not just combat.

Hope that helps you understand where things stand and what we as a team think about some of this...

- Venge

daraknor

  • Wayfarer
  • *
  • Posts: 3
    • View Profile
Re: Monster/NPC AI.
« Reply #13 on: January 20, 2007, 02:23:19 am »
Sorry if there is a policy against rezzing old threads. I was in a conversation with talad the other night.

Motivation should be a key factor in NPC behavior, but only has a limited role in NPC combat. If NPC are faced with Maslow's hierarchy of needs, then they should behave differently.

Second, AI can be a scalable experience. What is the fun in the strongest/smartest creature in the game behaving the same way a rat does? Most Combat AI is directly married to the game engine and game rules.

I'm not that interested in writing new Pathfinding AI. A* applied to groups seems good enough for now. A loose formation method can be applied on the agent level. Pathfinding for mobs is in CS anyway.

I'm very interested in talking with lystira, we have similar concepts even though I'm only hinting here. A little more than a hint would be bayesian measured subgoal systems rather than binary tree algorithms. Subgoal systems abstracted through associative databases.

Feel free to PM me, or IM me daraknor1 on YIM daraknor on AIM.
AI Developer, trying to make a world come alive.

Jeraphon

  • Hydlaa Notable
  • *
  • Posts: 717
    • View Profile
Re: Monster/NPC AI.
« Reply #14 on: January 20, 2007, 05:50:48 am »
Quote
If NPC are faced with Maslow's hierarchy of needs, then they should behave differently.

The same can be said of PCs. The game doesn't account for basic needs (yet.) They currently don't require food (no hunger/thirst) or shelter (no detrimental effects of weather/temperature) to survive, and their clothing needs are met (save the Kran who don't wear them but could wear armour.)

Given that the lowest level is a moot point, we shouldn't be looking at NPCs who have a hierarchy of needs, should we?

Yes, I get what you're saying. Smarter NPCs would be more fun. Heck, I'd settle for a monster that wouldn't chase you through all eight levels because you hit it once and realized you weren't strong enough to kill it. But there is such a thing as overcomplication. :)