Mythruna
August 21, 2019, 11:39:19 AM *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
News: Welcome to the new forums. See "Announcements" for a note for new users.
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: The preborn AI is already hacking my game...  (Read 14586 times)
pspeed
Administrator
Hero Member
*****
Posts: 5567



View Profile
« on: May 17, 2012, 09:36:24 PM »

As some of you may already know, last weekend and in my off time this week, I've been working on the beginnings of Mythruna's AI system.  This is tapping into knowledge that I haven't used heavily since the 1990s when I did some expert system work.

The general idea is that you define a bunch of operations/actions that an AI can perform.  Each of these has a set of conditions that must be met before it can be run and a set of effects that happen when it is performed.  So, for example, an "eat" action might require that the NPC be holding food first and the effect is that the NPC's hunger level changes.

From these simple actions and their pre-conditions and effects, the real meat of the AI can work: the planner.  The planner is responsible for chaining effects and preconditions together to achieve some goal.  The hows and whats of this are probably too low level to get into here but suffice it to say that it tries to find the shortest plan of actions to meet some goal.

An example shows how this might work.  Let's say you have the "eat" action is described above.  To this we will add an "equip" action that removes an item from inventory and holds it.  For brevity's sake, we will also add a "buy" action that buys an item from a NPC merchant (way oversimplified) and a "move to" action that walks to some target.

A goal for the NPC might be "reduce my hunger level".  The planner scans through the available actions and finds the "eat" action that will satisfy that goal.  But in order for the "eat" action to run, the NPC needs to be holding food.  Both "equip" and "buy" can make the NPC hold food.  "equip" requires food in inventory and maybe the NPC has none.  "buy" requires that the the NPC be next to a merchant.  Since neither "buy" nor "equip" resolved on their own the planner will try another step and sees that the "move to" action can move the player to a merchant.  The planner has found the best plan and then it's just a matter of executing those steps.

The nice thing about a system like this is that actions are relatively easy to create.  In many of the above examples they are just shifting resources around... pretty straight forward stuff.  You can also give actions a "cost" which might lead the NPC to pick one over another, all things being equal.  So in the above example, maybe there is food laying on the table already and the "buy" action has a higher cost than the "pick up" action.  But I digress...

The real clever works is done in the planner and a particular NPC may have a different set of available actions and costs than another and that's what will make it really  interesting.


Anyway, in order to test the planner, I've been using a really simply artificial scenario.  There are some stacks of lettered blocks (A, B, C, etc.) in a certain starting configuration.  The actions are "stack" and "unstack"... basically, put a block down or pick a block up.  I enter a goal of the way I'd like the blocks stacked and the planner tries to find a way to do that.

So if I had something like:

Code:
C
A   B

And wanted to get to:
Code:
A
C
B

Then the planner will figure out:
-unstack C
-stack C on B
-unstack A
-stack A on C

...and a variety of other starting and ending conditions will find the appropriate sequence of events.

The interesting part is that I'm watching the different things that the AI tried to do and failed... and it's already hacking this simple setup.

Since this is not a real game or even real code, I've left the "world state" simple.  We see a nice picture above but the computer sees that starting state as "C on A", "A on ground", "B on ground" basically.

What the AI planner figured out is that there is nothing preventing it from stacking "C on C" to move it out of the way.  Those paths never resolve because it can never pick up C again... at least they never resolve because I always included "C" in my goal.

Still, I find it interesting how close an eye I will have to keep on how the world is represented and managed... not just because players will exploit it but because my AI certainly will.
Logged
SleeperCell #42
Global Moderator
Sr. Member
*****
Posts: 265


Ask me... I DARE you.


View Profile WWW
« Reply #1 on: May 18, 2012, 12:49:12 AM »

Has no one here seen terminator? -.- KILL IT! KILL IT WITH FIRE!
jkz I've never tried learning how do to AI... is it just a more complex version of "if, else, elseif?
Logged

As a Modern Warfare 2 fan I am obligated to call you a fa***** and tell you to commit suicide for the blasphemy you just wrote
pspeed
Administrator
Hero Member
*****
Posts: 5567



View Profile
« Reply #2 on: May 18, 2012, 02:06:04 AM »

Has no one here seen terminator? -.- KILL IT! KILL IT WITH FIRE!
jkz I've never tried learning how do to AI... is it just a more complex version of "if, else, elseif?

Depends on the type of AI.  Neverwinter Nights used a scripted AI based on perception events and a "heartbeat" script that ran every 5 seconds.  But the scripts that handled those events were pretty much huge (pages and pages) of nearly just "if, else, elseif" types of logic.

Mythruna's approach will be different because that type of AI is problematic for a few reasons.

If you really want to fall of the deep end sometime this might be some interesting reading:
http://web.media.mit.edu/~jorkin/goap.html

You could also look up STRIPS planning... GOAP is a form of that.

I have played with expert systems and fuzzy logic before and plan to attempt to tie it all together into something interesting... but basically just extending a GOAP style system.
Logged
Teknonick
Sr. Member
****
Posts: 438


View Profile
« Reply #3 on: May 18, 2012, 10:01:06 AM »

So your saying, you AI will be alot simpler and easyer to add things to? And not just pages and pages of stuff just to move Block B around C then place it on A and then break C and place A on B and and and EXPLODE...

Just Simpler and Easyer... Cheesy I like it! I wish I could understand it a bit better though xD!
Logged
pspeed
Administrator
Hero Member
*****
Posts: 5567



View Profile
« Reply #4 on: May 18, 2012, 10:14:15 AM »

So your saying, you AI will be alot simpler and easyer to add things to? And not just pages and pages of stuff just to move Block B around C then place it on A and then break C and place A on B and and and EXPLODE...

Just Simpler and Easyer... Cheesy I like it! I wish I could understand it a bit better though xD!

Yeah, the bulk of the work comes in properly implementing the actions... making sure their preconditions and effects are listed properly, etc..  There will also be some feature available in the actions to have them prioritize differently based on "fuzziness"... for example, certain personalities could consider some things more costly than others.  Like a thief would have no problem stealing an item to get it but a law-abiding citizen might still have that action but at a really high "cost" in the AI system.

Setting up a particular NPC is then just a matter of giving them the list of possible actions and setting up their over-all goals properly (and any personality traits I specify for the "fuzziness" mentioned above).  Some NPCs will also have a sort of higher-order goal selector so that it can more intelligently pick goals or somehow coordinate goals in a larger group.
Logged
Teknonick
Sr. Member
****
Posts: 438


View Profile
« Reply #5 on: May 18, 2012, 04:30:17 PM »

So your saying, you AI will be alot simpler and easyer to add things to? And not just pages and pages of stuff just to move Block B around C then place it on A and then break C and place A on B and and and EXPLODE...

Just Simpler and Easyer... Cheesy I like it! I wish I could understand it a bit better though xD!

Yeah, the bulk of the work comes in properly implementing the actions... making sure their preconditions and effects are listed properly, etc..  There will also be some feature available in the actions to have them prioritize differently based on "fuzziness"... for example, certain personalities could consider some things more costly than others.  Like a thief would have no problem stealing an item to get it but a law-abiding citizen might still have that action but at a really high "cost" in the AI system.

Setting up a particular NPC is then just a matter of giving them the list of possible actions and setting up their over-all goals properly (and any personality traits I specify for the "fuzziness" mentioned above).  Some NPCs will also have a sort of higher-order goal selector so that it can more intelligently pick goals or somehow coordinate goals in a larger group.

Yep, awesome! So... A really stupid person (NPC) might need some food, and is hungry, and has some in his pantry, but becuase they are random, and that he is stupid, would run to the store and buy more bread, rather than eating the stuff in his pantry. Yet his wife would eat rotten bread found under the floor boards, before going to the store to buy some. (Just really over the top examples...) But I'm sure they won't go THAT extreme.

It seems like a really neat, simple, and modify-able way to do the AI!

So adventure maps and that sort will be easy to set up!
Logged
pspeed
Administrator
Hero Member
*****
Posts: 5567



View Profile
« Reply #6 on: May 20, 2012, 06:20:48 PM »

I posted this link to the jMonkeyEngine forums and through discussion there ended up following up with this:
http://jmonkeyengine.org/groups/mythruna/forum/topic/mythruna-ai-semi-funny-story/#post-176145

Goes a little into my software development background and tries to respond to the question on how one should get started writing games/software.  Might be interesting to some of you and the link is easier for me to find if I post it here. Smiley
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.20 | SMF © 2013, Simple Machines Valid XHTML 1.0! Valid CSS!