agentjs-core
Version:
A comprehensive agent-based modeling framework with built-in p5.js visualization
188 lines • 4.8 kB
TypeScript
/**
* BehaviorTree - Advanced agent AI system using behavior trees
*/
import type { Agent } from '../agents/Agent';
/** Node execution status */
export declare enum NodeStatus {
SUCCESS = "success",
FAILURE = "failure",
RUNNING = "running"
}
/** Behavior tree node context */
export interface BehaviorContext {
agent: Agent;
deltaTime: number;
blackboard: Map<string, any>;
[key: string]: any;
}
/**
* Base class for all behavior tree nodes
*/
export declare abstract class BehaviorNode {
protected name: string;
protected parent: BehaviorNode | null;
constructor(name: string);
/**
* Execute the node behavior
*/
abstract execute(context: BehaviorContext): NodeStatus;
/**
* Reset node state
*/
reset(): void;
/**
* Get node name
*/
getName(): string;
/**
* Set parent node
*/
setParent(parent: BehaviorNode): void;
}
/**
* Composite node that can have children
*/
export declare abstract class CompositeNode extends BehaviorNode {
protected children: BehaviorNode[];
/**
* Add child node
*/
addChild(child: BehaviorNode): this;
/**
* Remove child node
*/
removeChild(child: BehaviorNode): boolean;
/**
* Get all children
*/
getChildren(): ReadonlyArray<BehaviorNode>;
/**
* Reset all children
*/
reset(): void;
}
/**
* Decorator node that modifies behavior of a single child
*/
export declare abstract class DecoratorNode extends BehaviorNode {
protected child: BehaviorNode | null;
/**
* Set the child node
*/
setChild(child: BehaviorNode): this;
/**
* Get child node
*/
getChild(): BehaviorNode | null;
/**
* Reset child
*/
reset(): void;
}
/**
* Sequence node - executes children in order until one fails
*/
export declare class SequenceNode extends CompositeNode {
private currentIndex;
constructor(name?: string);
execute(context: BehaviorContext): NodeStatus;
reset(): void;
}
/**
* Selector node - executes children until one succeeds
*/
export declare class SelectorNode extends CompositeNode {
private currentIndex;
constructor(name?: string);
execute(context: BehaviorContext): NodeStatus;
reset(): void;
}
/**
* Parallel node - executes all children simultaneously
*/
export declare class ParallelNode extends CompositeNode {
private successThreshold;
private failureThreshold;
constructor(name?: string, successThreshold?: number, failureThreshold?: number);
execute(context: BehaviorContext): NodeStatus;
}
/**
* Inverter decorator - inverts the result of its child
*/
export declare class InverterNode extends DecoratorNode {
constructor(name?: string);
execute(context: BehaviorContext): NodeStatus;
}
/**
* Repeater decorator - repeats child execution
*/
export declare class RepeaterNode extends DecoratorNode {
private maxRepeats;
private currentRepeats;
constructor(name?: string, maxRepeats?: number);
execute(context: BehaviorContext): NodeStatus;
reset(): void;
}
/**
* Condition node - checks a condition
*/
export declare class ConditionNode extends BehaviorNode {
private condition;
constructor(name: string, condition: (context: BehaviorContext) => boolean);
execute(context: BehaviorContext): NodeStatus;
}
/**
* Action node - performs an action
*/
export declare class ActionNode extends BehaviorNode {
private action;
constructor(name: string, action: (context: BehaviorContext) => NodeStatus);
execute(context: BehaviorContext): NodeStatus;
}
/**
* Wait node - waits for a specified duration
*/
export declare class WaitNode extends BehaviorNode {
private duration;
private elapsedTime;
constructor(name: string | undefined, duration: number);
execute(context: BehaviorContext): NodeStatus;
reset(): void;
}
/**
* Behavior tree manager for an agent
*/
export declare class BehaviorTree {
private root;
private blackboard;
constructor(root?: BehaviorNode | any);
/**
* Set the root node of the tree
*/
setRoot(root: BehaviorNode): void;
/**
* Execute the behavior tree
*/
execute(agent: Agent, deltaTime?: number): NodeStatus | any;
/**
* Reset the behavior tree
*/
reset(): void;
/**
* Get blackboard value
*/
getBlackboardValue<T>(key: string): T | undefined;
/**
* Set blackboard value
*/
setBlackboardValue<T>(key: string, value: T): void;
/**
* Clear blackboard
*/
clearBlackboard(): void;
/**
* Create a behavior tree from JSON configuration
*/
static fromJSON(_config: any): BehaviorTree;
}
//# sourceMappingURL=BehaviorTree.d.ts.map