UNPKG

agentjs-core

Version:

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

117 lines 3.57 kB
/** * Grid2D - 2D grid-based environment implementation */ import { Environment, SpatialQueryResult } from './Environment'; import type { Agent } from '../agents/Agent'; import type { Position } from '../../types/core'; import type { GridConfig, GridCoordinate, NeighborQueryOptions } from '../../types/spatial'; /** * Grid2D - Discrete grid-based 2D environment * * Features: * - Discrete cell-based positioning * - Moore and Von Neumann neighborhood types * - Configurable occupancy limits per cell * - Efficient neighbor queries using grid structure * - Grid-based pathfinding support * * Educational Context: Represents structured environments * like seating arrangements, organizational charts, * board games, or cellular automata simulations. */ export declare class Grid2D extends Environment { /** Grid configuration */ private readonly config; /** 2D grid of cells */ private readonly grid; /** Agent to grid coordinate mapping */ private readonly agentCoordinates; constructor(configOrRows: GridConfig | number, cols?: number, cellSize?: number); /** * Find neighbors within radius (in grid cells) */ findNeighbors(position: Position, radius: number, options?: NeighborQueryOptions): SpatialQueryResult<Agent>; /** * Get agents at specific position */ getAgentsAt(position: Position): ReadonlyArray<Agent>; /** * Get agents in specific grid cell */ getAgentsAtCell(coordinate: GridCoordinate): ReadonlyArray<Agent>; /** * Get grid coordinate for agent */ getAgentGridCoordinate(agent: Agent): GridCoordinate | undefined; /** * Get neighbors of a grid cell */ getCellNeighbors(coordinate: GridCoordinate): ReadonlyArray<GridCoordinate>; /** * Check if cell can accommodate more agents */ canPlaceAgent(coordinate: GridCoordinate): boolean; /** * Get empty cells in grid */ getEmptyCells(): ReadonlyArray<GridCoordinate>; /** * Get grid occupancy statistics */ getOccupancyStats(): { totalCells: number; occupiedCells: number; emptyCells: number; averageOccupancy: number; maxOccupancy: number; }; /** * Convert position to grid coordinate */ positionToGrid(position: Position): GridCoordinate; /** * Convert grid coordinate to position (center of cell) */ gridToPosition(coordinate: GridCoordinate): Position; /** * Calculate distance between grid coordinates */ gridDistance(a: GridCoordinate, b: GridCoordinate): number; /** * Get current grid configuration */ getGridConfig(): GridConfig; /** * Place agent at specific grid coordinate */ placeAgentAtCell(agent: Agent, coordinate: GridCoordinate): boolean; /** * Hook: Handle agent addition */ protected onAgentAdded(agent: Agent, position: Position): void; /** * Hook: Handle agent removal */ protected onAgentRemoved(agent: Agent): void; /** * Hook: Handle agent movement */ protected onAgentMoved(agent: Agent, _oldPosition: Position, newPosition: Position): void; /** * Initialize grid structure */ private initializeGrid; /** * Check if grid coordinate is valid */ private isValidCoordinate; /** * Remove agent from grid */ private removeAgentFromGrid; /** * Validate grid configuration */ private validateConfiguration; } //# sourceMappingURL=Grid2D.d.ts.map