Skip to main content

Module planner

Module planner 

Source
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

TypeRole
WorldStateNamed boolean + float condition map
ActionPreconditions, effects, cost, duration
GoalStackPriority-ordered goals for one agent
GoapPlannerA* plan search
PlanExecutorRuns 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.
ActionEffects
The effects portion of an Action, separated out so that WorldState can apply them without borrowing the whole action.
ActionLibrary
A named, searchable collection of Actions.
Goal
A named goal with a desired WorldState and a priority.
GoalStack
A priority-ordered collection of goals for one agent.
GoapAgent
A self-contained GOAP-driven agent that combines a goal stack, an action library, and a plan executor.
GoapPlanner
Stateless A* GOAP planner.
PlanExecutor
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.
PlanStep
Runtime state of one action being executed.
Preconditions
The preconditions an action requires to be applicable.
WorldState
A set of named conditions describing the current state of the world from one agent’s perspective.

Enums§

ExecutorState
The overall state of the plan executor.
PlanError
PlanStepStatus
The status of a single step in a running plan.