Mythruna

Development => Blog => Topic started by: pspeed on June 03, 2012, 02:36:38 PM



Title: The AI is the game...
Post by: pspeed on June 03, 2012, 02:36:38 PM
I apologize for being so quiet lately but rest assured that I am toiling away.

Lately, much of the work I've been doing is designing the AI.  Lots and lots of notes and technical documents with only random spurts of code.  I hope to have something to show for it soon but it's one of those things that pays to get right.

As I got deeper and deeper into the design of the AI, it was becoming clearer that this is essentially the core of the game.  Everything else is mechanical window dressing in comparison and any of it could be swapped out for simpler or more complicated systems if the AI is doing its job.  I mean, it's all important but the AI is what will make this RPG and not just a sandbox full of neat tools.

Physics, seasons, weather, even the magic system are such that if my best intents don't pan out then there are still pretty cool fallback positions... they just may mean more detail work for me.  I can always fall back on standard RPG tropes of pre-scripted built in items, scripted actions instead of physics, etc..  But if the AI is nothing more than growling heat seeking missiles (not to name names), then it's not really an RPG.  At least not the kind I want to write.

So, I'm left with making sure that my goal-oriented-action-planning system (GOAP) works like I want or I fall back on standard Neverwinter Nights style event-based decision tree scripting.  GOAP still looks promising and means that it will be really easy to make some very dynamic AI... even with NPC-specific random personalities.  Either way, though, there is a ton of work left.

I'm developing the AI inside of a simple test program that presents a simplified top-down 2D world.  I can place NPCs of various types into the world and tweak their goals and settings at runtime or give them specific commands.  With luck, this will get to the point where I can let others play with it and give them a glimpse of what I've been working on.  Hopefully some version in the next week or so.



Title: Re: The AI is the game...
Post by: FutureB on June 03, 2012, 02:58:47 PM
Paul that sounds great i really hope you are not forced to fall back on stamdard ai :]
good work


Title: Re: The AI is the game...
Post by: ayoriceball on June 03, 2012, 03:42:28 PM
Sounds like this will be what we want to show off, when it's ready :)


Title: Re: The AI is the game...
Post by: Teknonick on June 03, 2012, 06:10:14 PM
That sounds awesome! And I agree that the AI IS the game.... Its.. going... too.... be..... AWESOME!!!!!!


Title: Re: The AI is the game...
Post by: Ghelmaron on June 03, 2012, 08:53:43 PM
No problem Paul. One of the big problems of "big name" release games is the game being rushed out when more fine-tuning should have been done and players being angry about bugs and patches. It is good to get the kinks out ahead of time.


Title: Re: The AI is the game...
Post by: BenKenobiWan on June 03, 2012, 10:48:04 PM
I'd rather you take another year to get the AI done than just do some sloppy job of it. I hope for this game to be something special, something new, and I think the AI might be the main defining feature, as you said.
I myself haven't been active around here lately either. I hope to change that eventually, but I'm cramming school right now, so...

Anyway, keep it up!


Title: Re: The AI is the game...
Post by: Moonkey on June 05, 2012, 04:42:47 AM
Ooh. So, for example, when a wolf sees you when it is hungry/near den, it will stalk you in stealth looking for bushes etc. to hide in waiting for the right moment to strike? :3


Title: Re: The AI is the game...
Post by: pspeed on June 05, 2012, 07:49:37 AM
Ooh. So, for example, when a wolf sees you when it is hungry/near den, it will stalk you in stealth looking for bushes etc. to hide in waiting for the right moment to strike? :3

Heheh.  Something like that.  The bandit who hears you coming and must decide what to do about it is the example I've been using.  These are at the higher end of what I'd like to have.

Right now, I'll be happy if a mob is smart enough to figure out to pick up the key off the floor to open a door if his real goal is to get somewhere on the far side.


Title: Re: The AI is the game...
Post by: Moonkey on June 08, 2012, 03:45:23 AM
For example: NPC Finds locked door! It Looks around and finds 3 open barrels and 1 barrel closed in a square room the door is in. It searches the 3 open barrels and finds nothing its last option is to open the closed barrel; but It can't open it with its hands. So it uses a tool in return, like a sword if it had one. Once the closed barrel is open, it finds a key! It then uses the key to open the door. The door opens it walks inside and finds a chest. It walks towards the chest but doesn't notice a tripwire and poison arrows fly out of the walls! That's why awareness needs to be added. Oh how hard this all will be. :) But it would be so funny to see that happen in a game.


Title: Re: The AI is the game...
Post by: pspeed on June 08, 2012, 04:37:41 AM
For example: NPC Finds locked door! It Looks around and finds 3 open barrels and 1 barrel closed in a square room the door is in. It searches the 3 open barrels and finds nothing its last option is to open the closed barrel; but It can't open it with its hands. So it uses a tool in return, like a sword if it had one. Once the closed barrel is open, it finds a key! It then uses the key to open the door. The door opens it walks inside and finds a chest. It walks towards the chest but doesn't notice a tripwire and poison arrows fly out of the walls! That's why awareness needs to be added. Oh how hard this all will be. :) But it would be so funny to see that happen in a game.

The hard part is limiting awareness.  It's really easy to make the NPC know everything the game knows.


Title: Re: The AI is the game...
Post by: Ghelmaron on June 08, 2012, 05:14:05 PM
For example: NPC Finds locked door! It Looks around and finds 3 open barrels and 1 barrel closed in a square room the door is in. It searches the 3 open barrels and finds nothing its last option is to open the closed barrel; but It can't open it with its hands. So it uses a tool in return, like a sword if it had one. Once the closed barrel is open, it finds a key! It then uses the key to open the door. The door opens it walks inside and finds a chest. It walks towards the chest but doesn't notice a tripwire and poison arrows fly out of the walls! That's why awareness needs to be added. Oh how hard this all will be. :) But it would be so funny to see that happen in a game.

Hey, that sounds like the game is playing itself. Aren't the (human) players supposed to be doing stuff like that?  :D


Title: Re: The AI is the game...
Post by: randomprofile on June 08, 2012, 06:57:07 PM
Well, using this method right here...
(http://www.sauropodstudio.com/wp-content/uploads/2012/05/Schema-brixtron-segment.png)
Would it be hard to make it so the NPC can make it's own branches?


Title: Re: The AI is the game...
Post by: pspeed on June 08, 2012, 08:01:37 PM
That's a decision tree or state machine.  GOAP doesn't work like that.

You start with a goal, figure out what actions can satisfy that goal, figure out what actions can satisfy those actions' preconditions, etc... it's kind of like path finding except you are doing it through a state graph connected by possible actions.  The AI plans a set of actions (if possible) to reach some goal state.

This is why my AI figured out that it could cheat (in that other post).

You can find more than you ever wanted to know right here:
http://web.media.mit.edu/~jorkin/goap.html


Title: Re: The AI is the game...
Post by: Moonkey on June 09, 2012, 07:43:00 PM
That's a decision tree or state machine.  GOAP doesn't work like that.

You start with a goal, figure out what actions can satisfy that goal, figure out what actions can satisfy those actions' preconditions, etc... it's kind of like path finding except you are doing it through a state graph connected by possible actions.  The AI plans a set of actions (if possible) to reach some goal state.

This is why my AI figured out that it could cheat (in that other post).

You can find more than you ever wanted to know right here:
http://web.media.mit.edu/~jorkin/goap.html

Or Basicly: A
                 C
                 B :3. Something horrible like you said stacking a letter on a letter and getting rid of it forever might happen. Hungry? List:

            Eat Current bread
            Steal Bread
            Starve

 NPC Eats current bread and this happens:

                Steal Bread
                 Starve

NPC Steals bread since it has no money to buy bread and it is not on the list. (Hence no money cancels out buy bread since buy bread wasn't there in the first place) and then this:

                          Starve.

     NPC stacks Starve on Starve.

                 NPC no longer hungers. D: It breaks the hunger for the NPC! Sounds scary.


Title: Re: The AI is the game...
Post by: pspeed on June 09, 2012, 08:34:08 PM
Heheh.  The point was that if there is some way that the world state can be cheated then the AI is just as likely (in fact in some ways more likely) to find it as a player.  For certain kinds of state.

The AI will be working with a simplified version of the world, after all.  It might know all of the different ways that it can open a door but not realize that it will knock over a vase, for example.  But, if it turns out that you can open a door by bumping into it a few times or something then the AI would find bugs like that.


Title: Re: The AI is the game...
Post by: Moonkey on December 03, 2012, 11:15:58 PM
Heheh.  The point was that if there is some way that the world state can be cheated then the AI is just as likely (in fact in some ways more likely) to find it as a player.  For certain kinds of state.

The AI will be working with a simplified version of the world, after all.  It might know all of the different ways that it can open a door but not realize that it will knock over a vase, for example.  But, if it turns out that you can open a door by bumping into it a few times or something then the AI would find bugs like that.
(late response) So, your plan is to make a creative AI that will do things like hack (With an axe, not a computer) open a stuck/locked door to save his family?

Edit: From a fire or something. So you don't have an NPC stuck in a house yelling and burning alive without an idea of what to do.


Title: Re: The AI is the game...
Post by: pspeed on December 04, 2012, 12:00:04 AM
Heheh.  The point was that if there is some way that the world state can be cheated then the AI is just as likely (in fact in some ways more likely) to find it as a player.  For certain kinds of state.

The AI will be working with a simplified version of the world, after all.  It might know all of the different ways that it can open a door but not realize that it will knock over a vase, for example.  But, if it turns out that you can open a door by bumping into it a few times or something then the AI would find bugs like that.
(late response) So, your plan is to make a creative AI that will do things like hack (With an axe, not a computer) open a stuck/locked door to save his family?

Edit: From a fire or something. So you don't have an NPC stuck in a house yelling and burning alive without an idea of what to do.

If that is an action that the NPC has available to him then he will consider it in his planning process.


Title: Re: The AI is the game...
Post by: belgariad87 on December 04, 2012, 05:16:40 AM
Heheh.  The point was that if there is some way that the world state can be cheated then the AI is just as likely (in fact in some ways more likely) to find it as a player.  For certain kinds of state.

The AI will be working with a simplified version of the world, after all.  It might know all of the different ways that it can open a door but not realize that it will knock over a vase, for example.  But, if it turns out that you can open a door by bumping into it a few times or something then the AI would find bugs like that.
(late response) So, your plan is to make a creative AI that will do things like hack (With an axe, not a computer) open a stuck/locked door to save his family?

Edit: From a fire or something. So you don't have an NPC stuck in a house yelling and burning alive without an idea of what to do.

If that is an action that the NPC has available to him then he will consider it in his planning process.
if you can make an AI like that, why dont other games have such a thorough system?


Title: Re: The AI is the game...
Post by: pspeed on December 04, 2012, 10:56:29 AM
if you can make an AI like that, why dont other games have such a thorough system?

They kind of do.  GOAP (Goal Oriented Action Planning) is becoming more common.
http://web.media.mit.edu/~jorkin/goap.html

I don't know how strategic I'll be able to make it yet, but I've found it's mostly how the goals are encoded.  I kind of have a loose multi-layer design at this point.  It may be too slow and I'll fall back on more conventional high-level thinking with goap for the tactical level.  But we'll see.

Either way, if an NPC wanted to get into a house (the want already being decided in some way) and one of the actions he has available is "bash down the door" then that will be considered in his tactical planning.


Title: Re: The AI is the game...
Post by: G1ZMO on December 04, 2012, 01:39:08 PM
Do you plan to give the NCPs set tasks based on the time of day? (sleep, eat, hunt/search for food) and season (sunbathe/ski (jk lol))

Sounds great so far, can't wait for the next release!

Paul


Title: Re: The AI is the game...
Post by: belgariad87 on December 04, 2012, 01:56:05 PM
Do you plan to give the NCPs set tasks based on the time of day? (sleep, eat, hunt/search for food) and season (sunbathe/ski (jk lol))

Sounds great so far, can't wait for the next release!

Paul
hey yeahhh thats a good question! i remember in games like Skyrim and Radiata Stories people did things that made sense during certain times, like sleep at night and work and such.


Title: Re: The AI is the game...
Post by: pspeed on December 04, 2012, 02:32:49 PM
Do you plan to give the NCPs set tasks based on the time of day? (sleep, eat, hunt/search for food) and season (sunbathe/ski (jk lol))

Sounds great so far, can't wait for the next release!

Paul

Yes, NPCs will have a general daily schedule.  This is also how I will guess where they are when you come near a town that no player was near before, etc.


Title: Re: The AI is the game...
Post by: belgariad87 on December 04, 2012, 04:54:59 PM
Do you plan to give the NCPs set tasks based on the time of day? (sleep, eat, hunt/search for food) and season (sunbathe/ski (jk lol))

Sounds great so far, can't wait for the next release!

Paul

Yes, NPCs will have a general daily schedule.  This is also how I will guess where they are when you come near a town that no player was near before, etc.
why would you need to know that?


Title: Re: The AI is the game...
Post by: pspeed on December 04, 2012, 05:42:03 PM
Do you plan to give the NCPs set tasks based on the time of day? (sleep, eat, hunt/search for food) and season (sunbathe/ski (jk lol))

Sounds great so far, can't wait for the next release!

Paul

Yes, NPCs will have a general daily schedule.  This is also how I will guess where they are when you come near a town that no player was near before, etc.
why would you need to know that?

Because running the AI for 200,000+ NPCs is impossible.  But running the AI only for the NPCs that a player can interact with or can nearly interact with is possible.  When the player is not around, most NPCs will "go to sleep"... meaning they are just doing their "standard routine" and no calculations are required.  If you visit a town at night then Joe the Blacksmith is sleeping.  If you visit a town during the day then Joe the Blacksmith is working.  If you hang around in the town you can watch him go through his whole day but when you aren't in the town there is no reason the computer needs to keep track of Joe from minute to minute.


Title: Re: The AI is the game...
Post by: belgariad87 on December 04, 2012, 05:57:39 PM
Do you plan to give the NCPs set tasks based on the time of day? (sleep, eat, hunt/search for food) and season (sunbathe/ski (jk lol))

Sounds great so far, can't wait for the next release!

Paul

Yes, NPCs will have a general daily schedule.  This is also how I will guess where they are when you come near a town that no player was near before, etc.
why would you need to know that?

Because running the AI for 200,000+ NPCs is impossible.  But running the AI only for the NPCs that a player can interact with or can nearly interact with is possible.  When the player is not around, most NPCs will "go to sleep"... meaning they are just doing their "standard routine" and no calculations are required.  If you visit a town at night then Joe the Blacksmith is sleeping.  If you visit a town during the day then Joe the Blacksmith is working.  If you hang around in the town you can watch him go through his whole day but when you aren't in the town there is no reason the computer needs to keep track of Joe from minute to minute.
ohhh ok that makes sense


Title: Re: The AI is the game...
Post by: Teknonick on December 04, 2012, 06:14:35 PM
Do you plan to give the NCPs set tasks based on the time of day? (sleep, eat, hunt/search for food) and season (sunbathe/ski (jk lol))

Sounds great so far, can't wait for the next release!

Paul

Yes, NPCs will have a general daily schedule.  This is also how I will guess where they are when you come near a town that no player was near before, etc.
why would you need to know that?

Because running the AI for 200,000+ NPCs is impossible.  But running the AI only for the NPCs that a player can interact with or can nearly interact with is possible.  When the player is not around, most NPCs will "go to sleep"... meaning they are just doing their "standard routine" and no calculations are required.  If you visit a town at night then Joe the Blacksmith is sleeping.  If you visit a town during the day then Joe the Blacksmith is working.  If you hang around in the town you can watch him go through his whole day but when you aren't in the town there is no reason the computer needs to keep track of Joe from minute to minute.
ERROR, ERROR, ERROR!

WE NEED MORE CPU, FEED US CPU!!!


Title: Re: The AI is the game...
Post by: ayoriceball on December 04, 2012, 06:50:12 PM
Do you plan to give the NCPs set tasks based on the time of day? (sleep, eat, hunt/search for food) and season (sunbathe/ski (jk lol))

Sounds great so far, can't wait for the next release!

Paul

Yes, NPCs will have a general daily schedule.  This is also how I will guess where they are when you come near a town that no player was near before, etc.
why would you need to know that?

Because running the AI for 200,000+ NPCs is impossible.  But running the AI only for the NPCs that a player can interact with or can nearly interact with is possible.  When the player is not around, most NPCs will "go to sleep"... meaning they are just doing their "standard routine" and no calculations are required.  If you visit a town at night then Joe the Blacksmith is sleeping.  If you visit a town during the day then Joe the Blacksmith is working.  If you hang around in the town you can watch him go through his whole day but when you aren't in the town there is no reason the computer needs to keep track of Joe from minute to minute.

Soo looking forward to this. I believe TES Skyrim basically does the same thing, but Skyrim doesn't have a randomly generated world.


Title: Re: The AI is the game...
Post by: pspeed on December 04, 2012, 08:17:17 PM
Soo looking forward to this. I believe TES Skyrim basically does the same thing, but Skyrim doesn't have a randomly generated world.

Yeah, at some point it's the only way to do the AI because the scripting complexity explodes otherwise.  Even if only used at the tactical level (cannot shot bow unless I pick up arrows from over there then hold my bow... etc) it still simplifies a lot of stuff for an AI designer.


Title: Re: The AI is the game...
Post by: Michael on December 04, 2012, 08:55:11 PM
by the time mythruna is alpha, my computer will not be able to run mythruna :(


Title: Re: The AI is the game...
Post by: Moonkey on December 04, 2012, 10:34:48 PM
by the time mythruna is alpha, my computer will not be able to run mythruna :(
All you would need is a decent CPU. I'm guessing an AI complexity slider could help with performance on lower end computers. (Along with a setting for simple physics/basic water)


Title: Re: The AI is the game...
Post by: pspeed on December 04, 2012, 10:52:27 PM
The nice thing is that on multiplayer, the load will be on the server and not the client.  So even if for some reason a computer does not have enough CPU to run physics and AI (and I've done my job very poorly in that case) then it might still be able to connect to a server and play just fine.


Title: Re: The AI is the game...
Post by: belgariad87 on December 05, 2012, 05:13:12 AM
The nice thing is that on multiplayer, the load will be on the server and not the client.  So even if for some reason a computer does not have enough CPU to run physics and AI (and I've done my job very poorly in that case) then it might still be able to connect to a server and play just fine.
thats interesting.


Title: Re: The AI is the game...
Post by: Teknonick on December 05, 2012, 11:31:56 AM
by the time mythruna is alpha, my computer will not be able to run mythruna :(
By the time Mythruna is Alpha, people won't have to worry about 'optimizing' there games. :3


Title: Re: The AI is the game...
Post by: Sean on December 05, 2012, 12:56:02 PM
by the time mythruna is alpha, my computer will not be able to run mythruna :(
By the time Mythruna is Alpha, people won't have to worry about 'optimizing' there games. :3
"In Soviet Russia..."

...I hope I'll be able to buy alpha by the time it rolls around :)


Title: Re: The AI is the game...
Post by: Moonkey on December 05, 2012, 10:46:22 PM
by the time mythruna is alpha, my computer will not be able to run mythruna :(
By the time Mythruna is Alpha, people won't have to worry about 'optimizing' there games. :3
I wish technology advanced that fast. But people are too stubborn.


Title: Re: The AI is the game...
Post by: danny on February 12, 2013, 10:36:23 AM
if you can make an AI like that, why dont other games have such a thorough system?

They kind of do.  GOAP (Goal Oriented Action Planning) is becoming more common.
http://web.media.mit.edu/~jorkin/goap.html

I don't know how strategic I'll be able to make it yet, but I've found it's mostly how the goals are encoded.  I kind of have a loose multi-layer design at this point.  It may be too slow and I'll fall back on more conventional high-level thinking with goap for the tactical level.  But we'll see.

Either way, if an NPC wanted to get into a house (the want already being decided in some way) and one of the actions he has available is "bash down the door" then that will be considered in his tactical planning.

Based on my understanding of GOAP, either actions need to be mapped as relevant to a certain goal by the designer, or the NPC needs to discover the relvancy through testing a success.  For a FPS/TPS like F.E.A.R. this seems manageable because ultimately the actions of every enemy distills down to, kill the player.  So the designers were able to specifically map certain actions to tactical (shoot, move to nearest cover) or objective (attack, vacate compromised position) goals.

I imagine that the list of actions available to an NPC are enormous.  While preconditions can filter the list down, it's still an incredible feat to perform AI planning through a tangled web of destroying the door, finding a key, or even buying the services of a locksmith.  And then all the tactics to accomplish such objectives.

How are you programming the NPCs to negotiate through their available actions?  Are you limiting them to only certain sets of actions per goal?  Or is there a web of action and goal relationships with heuristic values to determine their cost and effectiveness?


Title: Re: The AI is the game...
Post by: pspeed on February 12, 2013, 02:30:16 PM
if you can make an AI like that, why dont other games have such a thorough system?

They kind of do.  GOAP (Goal Oriented Action Planning) is becoming more common.
http://web.media.mit.edu/~jorkin/goap.html

I don't know how strategic I'll be able to make it yet, but I've found it's mostly how the goals are encoded.  I kind of have a loose multi-layer design at this point.  It may be too slow and I'll fall back on more conventional high-level thinking with goap for the tactical level.  But we'll see.

Either way, if an NPC wanted to get into a house (the want already being decided in some way) and one of the actions he has available is "bash down the door" then that will be considered in his tactical planning.

Based on my understanding of GOAP, either actions need to be mapped as relevant to a certain goal by the designer, or the NPC needs to discover the relvancy through testing a success.  For a FPS/TPS like F.E.A.R. this seems manageable because ultimately the actions of every enemy distills down to, kill the player.  So the designers were able to specifically map certain actions to tactical (shoot, move to nearest cover) or objective (attack, vacate compromised position) goals.

I imagine that the list of actions available to an NPC are enormous.  While preconditions can filter the list down, it's still an incredible feat to perform AI planning through a tangled web of destroying the door, finding a key, or even buying the services of a locksmith.  And then all the tactics to accomplish such objectives.

How are you programming the NPCs to negotiate through their available actions?  Are you limiting them to only certain sets of actions per goal?  Or is there a web of action and goal relationships with heuristic values to determine their cost and effectiveness?

Every action has a set of prerequisites and net effects.  If you are looking for a desired effect then you start from all of the actions that can produce that effect... then use their prerequisites to look for actions that are either already satisfied or you look for actions that solve their prerequisites and so on.

It's basically a graph... so traversing it should not be too complicated.  It can also be tuned to never explore back up the chain too far... making the AI dumber but more responsive.  Though I doubt it will be re-evaluating its plan very often anyway.  As far as "dumber creatures" versus "smarter creatures" that will boil down to the actions they have available in the first place.

In any case, I will feel very lucky if NPCs are ever smart enough to hire a locksmith. :)