UNPKG

agentjs-core

Version:

A comprehensive agent-based modeling framework with built-in p5.js visualization

138 lines 3.97 kB
/** * Abstract base Agent class for all agent types in the framework */ import { EventEmitter } from 'eventemitter3'; import type { AgentId, Position, PropertyValue, AgentProperties, AgentState } from '../../types/core'; /** * Abstract Agent class - foundation for all agent types * * Provides core functionality: * - Unique identification * - Property management with validation * - Position tracking with events * - Lifecycle management * - Event emission for state changes * * Educational Context: Represents individual community members * with properties that can change through interactions and * environmental influences. */ export declare abstract class Agent extends EventEmitter { /** Unique identifier for this agent */ readonly id: AgentId; /** Current agent state */ protected state: AgentState; /** Agent properties with type-safe access */ protected properties: Map<string, PropertyValue>; /** Current position in environment */ protected _position: Position; /** Creation timestamp */ readonly createdAt: number; /** Last update timestamp */ protected lastUpdated: number; constructor(id?: string | AgentId, initialProperties?: AgentProperties, initialPosition?: Position); /** * Abstract step method - must be implemented by subclasses * Called once per simulation step to update agent state */ abstract step(): void; /** * Get agent property with type safety */ getProperty<T extends PropertyValue>(key: string): T | undefined; /** * Set agent property with validation and event emission */ setProperty<T extends PropertyValue>(key: string, value: T): void; /** * Get all agent properties as an object */ getProperties(): Record<string, PropertyValue>; /** * Get all properties as readonly record */ getAllProperties(): Readonly<Record<string, PropertyValue>>; /** * Check if agent has a specific property */ hasProperty(key: string): boolean; /** * Remove a property from the agent */ removeProperty(key: string): boolean; /** * Get current position */ get position(): Position; /** * Get current position (method form for compatibility) */ getPosition(): Position; /** * Set position with validation and event emission */ setPosition(newPosition: Position): void; /** * Translate position by offset */ translate(dx: number, dy: number): void; /** * Get current agent state */ get currentState(): AgentState; /** * Activate agent (make it active in simulation) */ activate(): void; /** * Deactivate agent (remove from simulation but keep in memory) */ deactivate(): void; /** * Destroy agent (mark for removal from simulation) */ destroy(): void; /** * Check if agent is active */ isActive(): boolean; /** * Check if agent is destroyed */ isDestroyed(): boolean; /** * Serialize agent to JSON for persistence */ toJSON(): Record<string, any>; /** * Get string representation of agent */ toString(): string; /** * Validate property value before setting * Override in subclasses for custom validation */ protected validateProperty(key: string, value: PropertyValue): void; /** * Validate position before setting * Override in subclasses for custom validation */ protected validatePosition(position: Position): void; /** * Validate initial agent state */ protected validateInitialState(): void; /** * Emit property changed event */ private emitPropertyChanged; /** * Emit position changed event */ private emitPositionChanged; /** * Emit lifecycle event */ private emitLifecycleEvent; } //# sourceMappingURL=Agent.d.ts.map