GOAP: A Basic AI Tutorial

Game development specific discussions.
leopardpm
Posts: 1795
Joined: Feb 28, 2009 20:58

Re: GOAP: A Basic AI Tutorial

Post by leopardpm »

well, working on getting the Actions Coded

So far:
Pick Berries
Eat Berries
Go To Sleep
Chop Tree
Put Wood in Firepit
Light Campfire
Move


still need:
Get Axe
Get Matches
Get Pick
Get Magic Wand
Make Magic campfire
Make Axe
Collect Branches
Mine Iron Ore
Smelt Iron Ore/Make Iron Bar

and about 3,000 other actions.....

see bottom of first post to access all updated files....
Boromir
Posts: 463
Joined: Apr 30, 2015 19:28
Location: Oklahoma,U.S., Earth,Solar System
Contact:

Re: GOAP: A Basic AI Tutorial

Post by Boromir »

This is fun. It took me a bit to realize I had to face the tent to eat and sleep.
Can I recommend changing the console hider to this ... that way it will still compile on linux.

Code: Select all

#If Defined(__FB_WIN32__)
declare function hideConsoleWindow alias "FreeConsole"() as long
hideConsoleWindow
#End If
Alternately you could compile with "-s gui" to hide the console window.
leopardpm
Posts: 1795
Joined: Feb 28, 2009 20:58

Re: GOAP: A Basic AI Tutorial

Post by leopardpm »

Boromir wrote:This is fun. It took me a bit to realize I had to face the tent to eat and sleep.
Yeah, its just for testing right now, but I got a bit carried away... and now I have used up all my goblin animations! Already using the 'Death Blow' animation to sleep with! I am thinking just flashing an Icon over top the gobby to indicate what he is doing, like eating, or picking berries... cuz I don't have any animations and things need to be communicated to the viewer else they wonder what in the world is going on!!!

I need to start making some sort of GUI with buttons et al so we can more easily play with the GOAP aspects (once THAT gets hooked up...blah)
Can I recommend changing the console hider to this ... that way it will still compile on linux.
as you wish... I have no idea about how to accommodate linux folks... so any hints are very much appreciated!
leopardpm
Posts: 1795
Joined: Feb 28, 2009 20:58

Re: GOAP: A Basic AI Tutorial

Post by leopardpm »

argh... keep procrastinating and playing with graphics, just a waste of time... sorry...

had to adjust mapsize and now comma and period keys iterate through different sprites.... only gobby has animations though... need to re-write a bunch of this stuff, is just cobbled together..... the google drive link in first post will always have the latest updated code...
BasicCoder2
Posts: 3906
Joined: Jan 01, 2009 7:03
Location: Australia

Re: GOAP: A Basic AI Tutorial

Post by BasicCoder2 »

leopardpm wrote:... and now I have used up all my goblin animations!
Perhaps use still images of the actions like those little figures in the image,

"sample of possible Agetn graphics...about 48x48 each.png"

Kind of a long title!

When I try and compile GOAP Map Test v005.bas all I get is,
Compiler output:
C:\FreeBasic\bin\win32\ld.exe: cannot open output file C:\FreeBasic\Leopardpm\GOAP Map Test v005.exe: Permission denied

GOAP Map Test v004.bas compiles and runs but all I get is the black console window, a beep, and then it exits.

All those files and options on github I find annoying. It is like working with an untidy desk with papers everywhere.

I downloaded a "zip it all thingy" but although the compiled program, GOAP Map Test v002.bas runs there is no keyboard responses.

Have been very busy over the xmas break and have yet to find time to sit down for some serious coding on the project.
leopardpm
Posts: 1795
Joined: Feb 28, 2009 20:58

Re: GOAP: A Basic AI Tutorial

Post by leopardpm »

BasicCoder2 wrote:
leopardpm wrote:... and now I have used up all my goblin animations!
Perhaps use still images of the actions like those little figures in the image,
yeah.... since I will definitely not have all the animations for all the possible different actions, I will use a blinking icon overtop the sprite to indicate what they are trying to do...

When I try and compile GOAP Map Test v005.bas all I get is,
Compiler output:
C:\FreeBasic\bin\win32\ld.exe: cannot open output file C:\FreeBasic\Leopardpm\GOAP Map Test v005.exe: Permission denied
looks like you need to set the access permissions of the leopardpm folder to allow the compiler to create a new file
GOAP Map Test v004.bas compiles and runs but all I get is the black console window, a beep, and then it exits.
weird
All those files and options on github I find annoying. It is like working with an untidy desk with papers everywhere.
yup. me too - I do like using the Google Drive deal... it seems that we could actually have multiple computers snched to same folder then all coders would be working on latest versions...kinda...
I downloaded a "zip it all thingy" but although the compiled program, GOAP Map Test v002.bas runs there is no keyboard responses.
I don't understand why things won't run for you....
Have been very busy over the xmas break and have yet to find time to sit down for some serious coding on the project.
I keep trying to make time, but its hard, and I get distracted (again) doing the graphics and also sitting thinking about how to reformat the program so it is much better layout and flow.... right now its just cobbled together and as I think of something 'fun', I hack it in and, though it works, it is a mess to unravel when I want to change things etc.... Right now I am considering re-doing the whole draw screen/animation portion because the z-order drawing is bugging me...but, again, this is a distraction from showing GOAP...lol
Boromir
Posts: 463
Joined: Apr 30, 2015 19:28
Location: Oklahoma,U.S., Earth,Solar System
Contact:

Re: GOAP: A Basic AI Tutorial

Post by Boromir »

BasicCoder2 wrote:When I try and compile GOAP Map Test v005.bas all I get is,
Compiler output:
C:\FreeBasic\bin\win32\ld.exe: cannot open output file C:\FreeBasic\Leopardpm\GOAP Map Test v005.exe: Permission denied

GOAP Map Test v004.bas compiles and runs but all I get is the black console window, a beep, and then it exits.
The beep means fbsound failed to initiate. Do you have the runtime libraries coied out of the "put these in same folder as the BASIC program" folder?

Code: Select all

dim shared as boolean ok
ok=fbs_Init()
if ok=false then
  ? "error: fbs_Init() !"
  ? FBS_Get_PlugError()
  beep:sleep:end 1
end if
leopardpm
Posts: 1795
Joined: Feb 28, 2009 20:58

Re: GOAP: A Basic AI Tutorial

Post by leopardpm »

Boromir wrote:The beep means fbsound failed to initiate. Do you have the runtime libraries coied out of the "put these in same folder as the BASIC program" folder?
good catch!

Both BasicCoder2 and I have issues dealing with libraries and such - I think he hates them almost as much as I do.... since we are 'intermittent' programs and old schoolish, we kinda hafta re-learn how to do libraries whenever we get back into coding (every few months?)
BasicCoder2
Posts: 3906
Joined: Jan 01, 2009 7:03
Location: Australia

Re: GOAP: A Basic AI Tutorial

Post by BasicCoder2 »

Boromir wrote: Do you have the runtime libraries copied out of the "put these in same folder as the BASIC program" folder?
Yes. It still brings up a console window, beeps, the console window vanishes and I have just noticed that the FBIDE menu Run list is faded out and unusable meaning I guess a program is still running unseen. When I exit FBIDE and then restart FBIDE the menu is still faded out. I have to turn off the computer to reset everything. When I get time I might look at at the source code and perhaps delete the sound parts.
Image
leopardpm
Posts: 1795
Joined: Feb 28, 2009 20:58

Re: GOAP: A Basic AI Tutorial

Post by leopardpm »

you can try commenting out lines 17-20 - this is the hide console trick

Code: Select all

#If Defined(__FB_WIN32__)
declare function hideConsoleWindow alias "FreeConsole"() as long
hideConsoleWindow
#EndIf
I also notice that ALL files are in the main directory.... i think the program requires the sub directory: data, then the two sub-sub directories in data: "graphics" and "sounds"... pretty sure now that this is the issue... if you take out the hiding of the console window, then you will see the fbsound error message in the console window which will prob say something like "error: fbs_Load_WAVFile() !'

are you able to copy the whole Google drive directory (with all the sub-directories) over to your hard drive? That was what I was trying to do to make it easy....
leopardpm
Posts: 1795
Joined: Feb 28, 2009 20:58

Re: GOAP: A Basic AI Tutorial

Post by leopardpm »

the PNG file "sample of possible Agent graphics...about 48x48 each.png" was just a game I came across that had pretty neat, but simple agent graphics, something that someone with a bit more graphical aptitude than I might be able to replicate with animations.... I like how they are small, perhaps too small though. But even as small as they are, he is able to show different weapon types held and various animations....

Image
leopardpm
Posts: 1795
Joined: Feb 28, 2009 20:58

Re: GOAP: A Basic AI Tutorial

Post by leopardpm »

BasicCoder2, were you able to run v005 now?
BasicCoder2
Posts: 3906
Joined: Jan 01, 2009 7:03
Location: Australia

Re: GOAP: A Basic AI Tutorial

Post by BasicCoder2 »

leopardpm wrote:BasicCoder2, were you able to run v005 now?
Haven't had time to modify the code as I have real life issues currently occupying my thoughts.

Leopardpm wrote:
This routine does not check for infinite loops which you can easily accidentally create by the way you define the actions effects & pre-conditions.

It seems to me that mistakes in what preconditions and effects are required for an action may become a real issue as it become more complex?

The first time I read about machines making plans was a program to plan to move blocks to change one layout to another. What if one of your agents was to be given a house plan and told to generate all the actions to build the house. A house could be thought of as a configuration of "blocks".
leopardpm
Posts: 1795
Joined: Feb 28, 2009 20:58

Re: GOAP: A Basic AI Tutorial

Post by leopardpm »

BasicCoder2 wrote:Leopardpm wrote:
This routine does not check for infinite loops which you can easily accidentally create by the way you define the actions effects & pre-conditions.
It seems to me that mistakes in what preconditions and effects are required for an action may become a real issue as it become more complex?
yes, exactly. But I am noticing as I read about other, professional, GOAP planners instituted in various games that the plans they generate tend to be very short - something like 3-4 actions total. If you think about all the possible plans made for a particular goal (the GOAP plan 'tree'), it tends not to be deep as much as it is wide. This is due to the fact that alot of the plans are just a rearrangement of the same actions done in a different order:

These are all 'valid' plans:
get Axe -> get Matches -> Chop Tree -> Make campfire
get Axe -> Chop Tree -> get Matches -> Make campfire
get Matches -> get Axe -> Chop Tree -> Make campfire

but it is important to test each of these because the order the actions are executed could easily affect the total plan cost due to travel time between the locations of objects. For instance, if the Axe and Matches were in the same area and far from the tree, then it would make sense to pickup the matches while getting the axe before walking over to the tree to chop it...

I think that at least some of the possible infinite loops (need to chop wood to make the axe so can chop wood) can be easily tested for and caught.

Ideally, I am thinking that I need to make a tool to easily create actions and be able to test them and the output of the tool would be a text file defining all the actions which then the game would read in instead of having set data statements, etc. But it is not necessary at this point yet.
The first time I read about machines making plans was a program to plan to move blocks to change one layout to another. What if one of your agents was to be given a house plan and told to generate all the actions to build the house. A house could be thought of as a configuration of "blocks".
yes. I am thinking of calling these predefined groups of actions either 'Recipes' or 'PreSet Plans' or 'Macro Actions' or something along those lines. I envision players and NPCS being able to create these plans (and possibly trade them to others), for instance a character with the Architect Skill is able to create simple House Plans with minimal square footage, whereas one with Master Architect Skill might be able to create 2-story structures or structures above a certain size... These 'PreSet Plans' could have a general total Prerequisite Amounts and skills to easily check before the planner even looks at them:

Recipe for Small Shack:
Needs 4 Walls, each needs 20 wood (80) (plus Carpentry Lvl 1)
Needs Roof needing 35 wood (plus Roof Making Lvl 1)
Needs Door needing 10 Wood (plus Carpentry Lvl 2)
Needs 2 Windows, each needing 4 Wood & 2 Glass panes (plus Window Making Lvl 1)
also would need an area defined of a certain size and location which would be free of obstacles (trees & rocks, etc)

So, total for Recipe might be: Wood = 133, Glass Panes = 2
And all the skills required would be: Carpentry Lvl 2, Roof Making lvl 1, Window Making Lvl 1
BasicCoder2
Posts: 3906
Joined: Jan 01, 2009 7:03
Location: Australia

Re: GOAP: A Basic AI Tutorial

Post by BasicCoder2 »

Really I think a simple code example of GOAP in action would have more tutorial value if it isn't clogged up with fancy graphics and the need for a dll to be included so that the code concentrates more on the mechanics behind the simulation. It can still have a simple graphics display as was done in this simple example for which maybe a FreeBASIC translation could be written?
https://medium.com/@vedantchaudhari/goa ... 035ed40d0b
When I get time to get back to the project I will use this simple display. The characters can be animated later in the meantime drawing a still image of them holding logs or an axe doing a chopping motions and so on shouldn't be hard rather than a descriptive text. As you know adding a more complex display can be done without changing the mechanics of the code.
Image
Post Reply