import Cell from '../entities/Cell'; import Agent from '../entities/Agent'; import { Numbers } from '../main'; export type BoundaryCondition = 'finite' | 'periodic'; export type CellFactory = (location: [number, number]) => T; export type CellGridConstructor = { width: number; height?: number; cellFactory: CellFactory; boundaryCondition?: BoundaryCondition; }; export default class CellGrid { cells: T[][]; width: number; height: number; boundaryCondition: BoundaryCondition; static default(width: number, options?: { height?: number; boundaryCondition?: BoundaryCondition; }): CellGrid; constructor(opts: CellGridConstructor); [Symbol.iterator](): Generator; map(callback: (cell: T, i: number) => U): U[]; forEach(callback: (cell: T) => void): void; filter(callback: (cell: T) => boolean): T[]; reduce(callback: (accumulator: U, cell: T) => U, initialValue: U): U; /** * Gets the cell at the set's [x,y] location. * Returns undefined if the location is out of bounds. */ getCell(location: [number, number]): T | undefined; /** * Gets the cell nearest to the given location. * * There are two boundary conditions: * - **FINITE** Returns undefined if the location is out of bounds. * - **PERIODIC** Returns the cell at the periodic location. */ getCellNearest(location: [number, number]): T | undefined; /** * Picks a cell at random from the cell set. */ random(rng: Numbers.RandomGenerator): T; /** * Picks N random cells from the cell set without replacement */ randomSample(rng: Numbers.RandomGenerator, N: number): T[]; /** * Returns true if the given location is within the grid bounds. */ isInBounds(location: [number, number]): boolean; insertAgent(agent: T): void; }