Expand description
Goal-Oriented Action Planning (GOAP).
§Overview
GOAP lets an AI agent automatically figure out how to reach a goal by searching for the cheapest sequence of actions that transforms the current world state into the goal state.
§Core types
| Type | Role |
|---|---|
WorldState | Named boolean + float condition map |
Action | Preconditions, effects, cost, duration |
GoalStack | Priority-ordered goals for one agent |
GoapPlanner | A* plan search |
PlanExecutor | Runs a plan, detects state drift, replans |
§Example
ⓘ
let mut state = WorldState::new();
state.set_bool("has_weapon", false);
state.set_bool("enemy_dead", false);
let pick_up = Action::new("pick_up_weapon", 1.0)
.require_bool("has_weapon", false)
.effect_bool("has_weapon", true);
let attack = Action::new("attack_enemy", 2.0)
.require_bool("has_weapon", true)
.require_bool("enemy_dead", false)
.effect_bool("enemy_dead", true);
let mut goal = WorldState::new();
goal.set_bool("enemy_dead", true);
let plan = GoapPlanner::plan(&state, &goal, &[pick_up, attack], 10);
// plan == Some(["pick_up_weapon", "attack_enemy"])Structs§
- Action
- A GOAP action that an agent can execute.
- Action
Effects - The effects portion of an
Action, separated out so thatWorldStatecan apply them without borrowing the whole action. - Action
Library - A named, searchable collection of
Actions. - Goal
- A named goal with a desired
WorldStateand a priority. - Goal
Stack - A priority-ordered collection of goals for one agent.
- Goap
Agent - A self-contained GOAP-driven agent that combines a goal stack, an action library, and a plan executor.
- Goap
Planner - Stateless A* GOAP planner.
- Plan
Executor - Drives execution of a GOAP plan, applying each action’s effects to the simulated world state, and replanning when the actual state diverges from the expected state.
- Plan
Step - Runtime state of one action being executed.
- Preconditions
- The preconditions an action requires to be applicable.
- World
State - A set of named conditions describing the current state of the world from one agent’s perspective.
Enums§
- Executor
State - The overall state of the plan executor.
- Plan
Error - Plan
Step Status - The status of a single step in a running plan.