Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I'm currently developing a GOAP system in Java. An explanation of GOAP can be found at http://web.media.mit.edu/~jorkin/goap.html. Essentially, it's using A* to plot between Actions that mutate the world state.

To provide a fair chance for all Actions and Goals to execute, I'm using a heuristic function to estimate the cost of doing something. What is the best way to estimate this cost so that it is comparable to all the other costs?

As an example, estimating the cost of running away from an enemy versus attacking it - how should the cost be calculated to be comparable?

share|improve this question
    
We're using GOAP for our RTS game and will be posting more tutorials like this one soon: indiedb.com/games/attack-of-the-gelatinous-blob/news/… –  Erlend Dec 10 '12 at 17:49

1 Answer 1

up vote 3 down vote accepted

To make all the costs comparable, you only need to use the same heuristic for all actions. For example, all actions have a list of potential outcomes and all outcomes have a certain value to the entity.

For example, there's a deep pool with water, and the entity is thirsty. So we look at an action the pool has available to satisfy that need:

First the entity priorities associated with these places, you could call these the modifiers. Some of these will change with time and depend on the entity. For example an ant might worry less about staying alive and more about colony concerns. Or if an entity has gone a while without drink, the satisfy thirst priority may override others.

Entity priorities:

Satisfy thirst: 40
Stay dry: 10
Stay alive: 100

Then what the location represents:

Location: Pool
Action: Collect water
*Potential outcomes: *:
Satisfy thirst - (-95)
Get wet - 10
Drown - 1

So we could calculate that action cost at: (40*-95) + (10*10) + (100*1) = -3600

Where collecting water from a raging river might look like:

Location: Raging river
Action: Collect water
*Potential outcomes: *:
Satisfy thirst - (-95)
Get wet - 90
Drown - 60

(40*-95) + (10*90) + (100*60) = 3100

So it's clearly a better choice to collect water from the pool. Maybe if the raging river was the only choice the entity would wait until its satisfy thirst priority went very high before trying the river.

You may want to keep things much simpler starting out. Just have a few variables that can apply more globally. Like staying alive, satisfy needs. In your fight or flight example, you'd need to give each entity a combat rating, so they could effectively rank themselves against the other entity for score purposes.

share|improve this answer
    
Thanks a lot! Predicating on all potential outcomes sounds like a better idea than what I had. –  fullwall Dec 11 '12 at 2:36

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.