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
70 lines (69 loc) • 2.63 kB
TypeScript
import { CellGrid } from '../structures';
import Agent from './Agent';
import { Color } from '../numbers';
/**
* Derive a value from a function of the cell's current state
* instead of storing it as a constant.
*/
export declare function Dynamic<T extends Cell, V>(f: (cell: T) => V): (target: T, propertyKey: string) => void;
export type CellConstructor = {
/**
* The [x,y] location of the cell in the grid beginning at [0,0].
*/
location: [number, number];
color?: Color;
strokeColor?: Color;
energy?: number;
};
/**
* A cell in a grid. The basic unit of space for a model.
* May be used as-is or extended to include additional properties.
*
* The default cell has a `location`, `color`, and `energy`. Only the `location` is required.
* The default color is white and the default energy is 0.
*
* Additionally, a cell has a set of `tenantAgents` which are agents that occupy the cell
* at the current time step.
*/
export default class Cell {
location: [number, number];
tenantAgents: Set<Agent>;
color: Color;
strokeColor: Color;
energy: number;
constructor(opts: CellConstructor);
/**
* Gives the distance between this Cell and another Cell or Agent.
*/
distanceTo<T extends Cell | Agent>(world: CellGrid<Cell>, other: T, options?: {
metric?: 'euclidean' | 'manhattan';
}): number;
/**
* Gets all Cells within a given square radius.
*/
getNeighborsInRadius<T extends Cell>(world: CellGrid<T>, options?: {
includeSelf?: boolean;
radius?: number;
}): Array<T>;
/**
* Diffuses a property to neighboring cells.
* The property function should return a number for each cell.
* The cell diffuses equal shares of `rate` percentage of the property to each neighbor.
*/
diffuse<T extends this>(world: CellGrid<T>, property: (cell: T) => number, setter: (cell: T, value: number) => void, rate: number, range?: number): void;
/**
* Performs a 2D convolution on the cell's neighbors using the given kernel.
* The kernel is a 3x3 matrix of numbers.
* The property function should return a number for each cell. *
*/
getNeighborConvolution<T extends Cell>(world: CellGrid<T>, kernel: number[][], property: (cell: T) => number): number;
/**
* Gets the four neighbors of the cell.
* Optionally includes the four diagonal neighbors and this cell.
*/
getNeighbors<T extends Cell>(world: CellGrid<T>, options?: {
includeDiagonals?: boolean;
includeSelf?: boolean;
}): Array<T>;
toJSON(): object;
}