UNPKG

goap-oriented

Version:

A TypeScript implementation of Goal-Oriented Action Planning

76 lines (75 loc) 2.71 kB
import { WorldState, Action, Goal } from './types'; /** * Goal-Oriented Action Planning (GOAP) implementation for automated planning and problem solving. * This planner uses A* search with custom heuristics to find optimal action sequences. */ export declare class GOAPPlanner { private actions; private maxIterations; private resourceKeys; /** * Adds a new action to the planner's available action set. * @param action The action to add */ addAction(action: Action): void; /** * Removes an action from the planner's available action set. * @param actionName The name of the action to remove */ removeAction(actionName: string): void; private evaluateStateProgress; private projectFutureCosts; /** * Finds an optimal sequence of actions to achieve the specified goal from the initial state. * Uses A* search with custom heuristics for efficient planning. * @param initialState The starting world state * @param goal The goal conditions to achieve * @returns An array of actions that achieve the goal, or empty array if no solution is found */ findPlan(initialState: WorldState, goal: Goal): Action[]; private calculateHeuristic; private getStateHash; private calculateActionCost; /** * Marks a state key as representing a consumable resource. * Marked resources will be tracked for consumption status. * @param key The state key to mark as a resource */ markAsResource(key: string): void; /** * Clears all resource tracking markers. */ clearResourceTracking(): void; /** * Applies a sequence of effects to a world state. * @param state Current world state * @param effects Array of effects to apply * @returns New world state after applying effects * @private */ private applyEffects; /** * Checks if all preconditions are satisfied in the given state. * @param state Current world state * @param preconditions Array of preconditions to check * @returns True if all preconditions are satisfied * @private */ private checkPreconditions; /** * Checks if a single precondition is satisfied in the given state. * @param state Current world state * @param condition Precondition to check * @returns True if the precondition is satisfied * @private */ private checkPrecondition; /** * Checks if the current state satisfies all goal conditions. * @param state Current world state * @param goal Goal to check * @returns True if all goal conditions are satisfied * @private */ private satisfiesGoal; }