agentscape
Version:
Agentscape is a library for creating agent-based simulations. It provides a simple API for defining agents and their behavior, and for defining the environment in which the agents interact. Agentscape is designed to be flexible and extensible, allowing
54 lines (53 loc) • 1.98 kB
TypeScript
import Cell from '../entities/Cell';
import Agent from '../entities/Agent';
import { Numbers } from '../main';
export type BoundaryCondition = 'finite' | 'periodic';
export type CellFactory<T extends Cell> = (location: [number, number]) => T;
export type CellGridConstructor<T extends Cell> = {
width: number;
height?: number;
cellFactory: CellFactory<T>;
boundaryCondition?: BoundaryCondition;
};
export default class CellGrid<T extends Cell> {
cells: T[][];
width: number;
height: number;
boundaryCondition: BoundaryCondition;
static default(width: number, options?: {
height?: number;
boundaryCondition?: BoundaryCondition;
}): CellGrid<Cell>;
constructor(opts: CellGridConstructor<T>);
[Symbol.iterator](): Generator<T, void, unknown>;
map<U>(callback: (cell: T, i: number) => U): U[];
forEach(callback: (cell: T) => void): void;
filter(callback: (cell: T) => boolean): T[];
reduce<U>(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<T extends Agent>(agent: T): void;
}