agentjs-core
Version:
A comprehensive agent-based modeling framework with built-in p5.js visualization
152 lines • 4.43 kB
TypeScript
/**
* InteractionEngine - Manages agent-to-agent interactions
*/
import { EventEmitter } from 'eventemitter3';
import type { Agent } from '../agents/Agent';
import type { Environment } from '../environment/Environment';
import type { PropertyValue } from '../../types/core';
/** Interaction type definitions */
export interface InteractionType {
readonly id: string;
readonly name: string;
readonly range: number;
readonly canInitiate: (initiator: Agent, target: Agent) => boolean;
readonly execute: (initiator: Agent, target: Agent, context: InteractionContext) => InteractionResult;
readonly priority: number;
}
/** Interaction context */
export interface InteractionContext {
readonly environment: Environment;
readonly distance: number;
readonly timestamp: number;
readonly metadata: Record<string, any>;
}
/** Interaction result */
export interface InteractionResult {
readonly success: boolean;
readonly effects: InteractionEffect[];
readonly message?: string;
readonly metadata: Record<string, any>;
}
/** Interaction effect */
export interface InteractionEffect {
readonly targetAgent: Agent;
readonly property: string;
readonly oldValue: PropertyValue;
readonly newValue: PropertyValue;
readonly effectType: 'set' | 'add' | 'multiply' | 'min' | 'max';
}
/** Interaction configuration */
export interface InteractionConfig {
readonly enableInteractions: boolean;
readonly maxInteractionsPerStep: number;
readonly interactionCooldown: number;
readonly enableCollisionDetection: boolean;
readonly collisionRadius: number;
}
/**
* InteractionEngine - Manages all agent interactions
*
* Features:
* - Proximity-based interaction detection
* - Configurable interaction types
* - Collision detection and resolution
* - Interaction cooldowns and rate limiting
* - Effect application with validation
*
* Educational Context: Facilitates communication,
* resource exchange, and social dynamics between
* community members in various scenarios.
*/
export declare class InteractionEngine extends EventEmitter {
/** Registered interaction types */
private interactionTypes;
/** Agent interaction cooldowns */
private interactionCooldowns;
/** Interaction configuration */
private config;
/** Interaction statistics */
private stats;
constructor(config?: Partial<InteractionConfig>);
/**
* Register a new interaction type
*/
registerInteraction(interaction: InteractionType): void;
/**
* Remove an interaction type
*/
unregisterInteraction(interactionId: string): boolean;
/**
* Process interactions for all agents in environment
*/
processInteractions(environment: Environment): void;
/**
* Get interaction statistics
*/
getStats(): typeof this.stats;
/**
* Get current configuration
*/
getConfig(): InteractionConfig;
/**
* Update configuration
*/
updateConfig(newConfig: Partial<InteractionConfig>): void;
/**
* Get all registered interaction types
*/
getInteractionTypes(): ReadonlyArray<InteractionType>;
/**
* Get interaction type by ID
*/
getInteractionType(id: string): InteractionType | undefined;
/**
* Reset statistics
*/
resetStats(): void;
/**
* Find potential interactions for an agent
*/
private findPotentialInteractions;
/**
* Execute a specific interaction
*/
private executeInteraction;
/**
* Apply interaction effects to agents
*/
private applyInteractionEffects;
/**
* Apply a single effect to an agent
*/
private applyEffect;
/**
* Process collision detection and resolution
*/
private processCollisions;
/**
* Resolve collision between two agents
*/
private resolveCollision;
/**
* Check if agent is on interaction cooldown
*/
private isOnCooldown;
/**
* Set interaction cooldown for agent
*/
private setCooldown;
/**
* Clear expired cooldowns
*/
private clearExpiredCooldowns;
/**
* Get maximum interaction range from all registered types
*/
private getMaxInteractionRange;
/**
* Register built-in interaction types
*/
private registerBuiltInInteractions;
}
//# sourceMappingURL=InteractionEngine.d.ts.map