• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
alexzzzz

GOAP and integer state variables instead of booleans

1 post in this topic

I'm writing a village simulator where virtual people live their virtual lives. Eat, sleep, hunt, gather resources, etc. I'd like to use a goal-oriented action planner to give some brains to my sims, so they could think ahead and plan their actions.

 

I wrote a planner that uses boolean values to represent the world states, and uses regressive search to form the plans. The rules it uses look like these

 

rule 1: "go to the forest"

condition: "the sim's location != the forest"

effect: "the sim's location := the forest"

 

rule 2: "get wood"

conditions: "the sim's location == any forest", "the sim has no wood"

effects: "the sim has wood"

 

rule 3: "craft fishing rod"

conditions: "the sim has wood"

effects: "the sim has no wood", "the sim has a fishing rod"

 

rule 4: "go to the lake"

conditions: "the sim's location != the lake"

effects: "the sim's location := the lake"

 

rule 5: "get water"

conditions: "the sim's location == any lake", 'the sim has no water"

effects: "the sim has water"

 

rule 6: "get fish"

conditions: "the sim's location == any lake", "the sim has a fishing rod", "the sim has no fish"

effects: "the sim has a fish"

 

etc

 

If I give a sim a goal "to have some water", he goes to a nearest lake and takes some water. If a give him a goal "there's a fish in the forest", he goes to a nearest forest, takes a piece of wood, crafts a fishing rod, goes to a nearest lake, catches a fish, goes to the forest that I specified in the goal, and drops the fish there. Works excellent!

But I have no idea how to modify the planner the way it could work with integer values. What if I want a sim to be able to have one, two or more pieces of wood?

 

Let's make a rule

 

rule "get an extra piece of wood"

conditions: "the sim's location == any forest", "there's a room in the sim's inventory"

effects "increment amount of wood in the sim's inventory", "decrement amount of wood in the forest"

 

then set amount of wood in the sim's inventory to zero, and set a goal "the sim has two pieces of wood".

 

The planner looks for a rule that has an effect "has two pieces of wood" (since it is our goal and the first condition to satisfy), and founds nothing. The rule we've made would fit only if the sim already had one piece of wood, but he doesn't.

0

Share this post


Link to post
Share on other sites
The easiest possible solution I came up with, is to automatically unroll any condition like "to have N items of something" into a set on conditions:
- to have N items,
- to have N-1 items,
...
- to have 1 item.
 
Will try it later to see if there are any pitfalls.


PS
 
It works!
 
When I get a condition like "to have 3 items"  I convert it to three conditions "to have 1 item", "to have 2 items", "to have 3 items". And when I get a sequence of actions "take 1 item" -> "take 1 item" -> "take 1 item" I convert it back to "take 3 items".
 
NUMBER OF RULES: 37

GOAL CONDITIONS:
    1) Forest has 1 Fish
    2) Forest has 2 Fish
    3) Forest has 3 Fish


-----------------------------------------------------------------------------------------------
1 - | Cost 0 + penalty 3000000 = 3000000

    2 - drop 1 Fish at Forest | Cost 1 + penalty 2200000 = 2200001

-----------------------------------------------------------------------------------------------
2 - drop 1 Fish at Forest | Cost 1 + penalty 2200000 = 220000

    3 - goto Forest -> drop 1 Fish at Forest | Cost 51 + penalty 2100000 = 2100051
    4 - catch 1 fish -> drop 1 Fish at Forest | Cost 2 + penalty 2200000 = 2200002
    5 - drop 2 Fish at Forest | Cost 1 + penalty 1300000 = 1300001

-----------------------------------------------------------------------------------------------
5 - drop 2 Fish at Forest | Cost 1 + penalty 1300000 = 1300001

    6 - goto Forest -> drop 2 Fish at Forest | Cost 51 + penalty 1200000 = 1200051
    7 - catch 1 fish -> drop 2 Fish at Forest | Cost 2 + penalty 1300000 = 1300002
    8 - drop 3 Fish at Forest | Cost 1 + penalty 400000 = 400001

-----------------------------------------------------------------------------------------------
8 - drop 3 Fish at Forest | Cost 1 + penalty 400000 = 400001

    9 - goto Forest -> drop 3 Fish at Forest | Cost 51 + penalty 300000 = 300051
    10 - catch 1 fish -> drop 3 Fish at Forest | Cost 2 + penalty 400000 = 400002

-----------------------------------------------------------------------------------------------
9 - goto Forest -> drop 3 Fish at Forest | Cost 51 + penalty 300000 = 300051
    
    11 - catch 1 fish -> goto Forest -> drop 3 Fish at Forest | Cost 52 + penalty 266666 = 266718

-----------------------------------------------------------------------------------------------
11 - catch 1 fish -> goto Forest -> drop 3 Fish at Forest | Cost 52 + penalty 266666 = 266718

    12 - goto Lake -> catch 1 fish -> goto Forest -> drop 3 Fish at Forest | Cost 152 + penalty 250000 = 250152
    13 - craft 1 FishingRod -> catch 1 fish -> goto Forest -> drop 3 Fish at Forest | Cost 53 + penalty 275000 = 275053
    14 - catch 2 fish -> goto Forest -> drop 3 Fish at Forest | Cost 52 + penalty 166666 = 166718

-----------------------------------------------------------------------------------------------
14 - catch 2 fish -> goto Forest -> drop 3 Fish at Forest | Cost 52 + penalty 166666 = 166718

    15 - goto Lake -> catch 2 fish -> goto Forest -> drop 3 Fish at Forest | Cost 152 + penalty 150000 = 150152
    16 - craft 1 FishingRod -> catch 2 fish -> goto Forest -> drop 3 Fish at Forest | Cost 53 + penalty 175000 = 175053
    17 - catch 3 fish -> goto Forest -> drop 3 Fish at Forest | Cost 52 + penalty 66666 = 66718

-----------------------------------------------------------------------------------------------
17 - catch 3 fish -> goto Forest -> drop 3 Fish at Forest | Cost 52 + penalty 66666 = 66718

    18 - goto Lake -> catch 3 fish -> goto Forest -> drop 3 Fish at Forest | Cost 152 + penalty 50000 = 50152
    19 - craft 1 FishingRod -> catch 3 fish -> goto Forest -> drop 3 Fish at Forest | Cost 53 + penalty 75000 = 75053

-----------------------------------------------------------------------------------------------
18 - goto Lake -> catch 3 fish -> goto Forest -> drop 3 Fish at Forest | Cost 152 + penalty 50000 = 50152

    20 - craft 1 FishingRod -> goto Lake -> catch 3 fish -> goto Forest -> drop 3 Fish at Forest | Cost 153 + penalty 20000 = 20153

-----------------------------------------------------------------------------------------------
20 - craft 1 FishingRod -> goto Lake -> catch 3 fish -> goto Forest -> drop 3 Fish at Forest | Cost 153 + penalty 20000 = 20153

    21 - take 1 Wood at Forest -> craft 1 FishingRod -> goto Lake -> catch 3 fish -> goto Forest -> drop 3 Fish at Forest | Cost 154 + penalty 16666 = 16820

-----------------------------------------------------------------------------------------------
21 - take 1 Wood at Forest -> craft 1 FishingRod -> goto Lake -> catch 3 fish -> goto Forest -> drop 3 Fish at Forest | Cost 154 + penalty 16666 = 16820

    22 - goto Forest -> take 1 Wood at Forest -> craft 1 FishingRod -> goto Lake -> catch 3 fish -> goto Forest -> drop 3 Fish at Forest | Cost 154 + penalty 0 = 154



FINAL PLAN:
    1) goto Forest
    2) take 1 Wood at Forest
    3) craft 1 FishingRod
    4) goto Lake
    5) catch 3 fish
    6) goto Forest
    7) drop 3 Fish at Forest
The log shows regressive A* search iterations. The planner takes a plan with the lowest "cost+penalty" value from the sorted list, inserts some actions in the beginning and places it back to the list. The plan's "cost" is a sum of all its action costs, the "penalty" is a sum of penalties for all unsatisfied conditions (conditions that are closer to the end of the plan have higher penalties.)
0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0