agentjs-core
Version:
A comprehensive agent-based modeling framework with built-in p5.js visualization
117 lines • 3.77 kB
TypeScript
/**
* Abstract Environment class - foundation for all spatial environments
*/
import { EventEmitter } from 'eventemitter3';
import type { Agent } from '../agents/Agent';
import type { Position } from '../../types/core';
import type { EnvironmentDimensions, NeighborQueryOptions } from '../../types/spatial';
export interface SpatialQueryResult<T> {
readonly items: ReadonlyArray<T>;
readonly distances: ReadonlyArray<number>;
readonly queryTime: number;
}
/**
* Abstract Environment class providing spatial context for agents
*
* Handles:
* - Agent placement and movement
* - Boundary conditions and wrapping
* - Spatial queries and neighbor finding
* - Distance calculations
*
* Educational Context: Represents the physical or social space
* where community members interact, with different boundary
* conditions affecting movement and interaction patterns.
*/
export declare abstract class Environment extends EventEmitter {
/** Environment dimensions */
protected readonly dimensions: EnvironmentDimensions;
/** Agents currently in this environment */
protected agents: Set<Agent>;
/** Agent position tracking */
protected agentPositions: Map<Agent, Position>;
constructor(dimensions: EnvironmentDimensions);
/**
* Add agent to environment at specified position
*/
addAgent(agent: Agent, position?: Position): void;
/**
* Remove agent from environment
*/
removeAgent(agent: Agent): boolean;
/**
* Move agent to new position within environment
*/
moveAgent(agent: Agent, newPosition: Position): void;
/**
* Get agent's current position in environment
*/
getAgentPosition(agent: Agent): Position | undefined;
/**
* Get all agents in environment
*/
getAllAgents(): ReadonlyArray<Agent>;
/**
* Get number of agents in environment
*/
getAgentCount(): number;
/**
* Check if position is within environment bounds
*/
isValidPosition(position: Position): boolean;
/**
* Apply boundary conditions to position
*/
applyBoundaryConditions(position: Position): Position;
/**
* Calculate distance between two positions
*/
distance(pos1: Position, pos2: Position): number;
/**
* Get environment dimensions
*/
getDimensions(): EnvironmentDimensions;
/**
* Abstract method: Find neighbors within radius
* Must be implemented by concrete environment types
*/
abstract findNeighbors(_position: Position, _radius: number, _options?: NeighborQueryOptions): SpatialQueryResult<Agent>;
/**
* Abstract method: Get agents at specific position
* Must be implemented by concrete environment types
*/
abstract getAgentsAt(_position: Position): ReadonlyArray<Agent>;
/**
* Hook for subclasses when agent is added
*/
protected onAgentAdded(_agent: Agent, _position: Position): void;
/**
* Hook for subclasses when agent is removed
*/
protected onAgentRemoved(_agent: Agent): void;
/**
* Hook for subclasses when agent is moved
*/
protected onAgentMoved(_agent: Agent, _oldPosition: Position, _newPosition: Position): void;
/**
* Validate environment dimensions
*/
private validateDimensions;
/**
* Validate position coordinates
*/
private validatePosition;
/**
* Apply periodic boundary conditions (wrap around)
*/
private applyPeriodicBoundary;
/**
* Apply reflective boundary conditions (bounce back)
*/
private applyReflectiveBoundary;
/**
* Apply absorbing boundary conditions (clamp to bounds)
*/
private applyAbsorbingBoundary;
}
//# sourceMappingURL=Environment.d.ts.map