đź“ťGoal-Oriented Action Planning

tags

§ Gamedev

GOAP is an AI engine architecture that plans multiple action path to satisfy a weighted set of goals and selects the plan with the minimum cost.

It operates on a world state—a set of facts about the world. Each action has a cost, preconditions, and post-conditions.

GOAP planner first translates a goal to a list of conditions (facts) that needs to be satisfied, and then searches backwards from the desired state through actions until all conditions are satisfied.

A* can be used to optimize the search (as the solution space can get quite large).

Example

Current world: {HasMeleeWeapon}

Goal: Kill X

Available actions:

ActionRequiresSatisfies
MeleeAttack XHasMeleeWeapon, AtTarget XAttacking X
RangedAttack XHasRangedWeapon, NearTarget XAttacking X
GotoTarget XAtTarget X, NearTarget X

The planner first translates Kill X into Attacking X, so the world starts as: has: {HasMeleeWeapon}, needs: {Attacking X}.

Planner then explores two actions that satisfy Attacking X: MeleeAttack and RangedAttack. MeleeAttack already has one condition satisfied (HasMeleeWeapon), so it has higher heuristic and is explored first.

The world state at this point is: has: {HasMeleeWeapon, Attacking X}, needs: {HasMeleeWeapon, AtTarget X}. Plan is [MeleeAttack X].

Now the planner picks GotoTarget X as it satisfies the needed condition.

The world state is now: has: {HasMeleeWeapon, Attacking X, AtTarget X}, needs: {}. Plan is [GotoTarget X, MeleeAttack X]. All required conditions are satisfied, so that’s a valid plan and can be followed.

Resources

Backlinks