Grid Projection
A 2D lattice projection: each agent in the context occupies an integer-coordinate Cell. The grid has fixed columns and rows; cells are addressed by (col, row) with col ∈ [0, columns) and row ∈ [0, rows).
Occupancy semantics:
GridOccupancy.MULTIPLE (default) — multiple agents may share a cell. Typical for swarm / crowd / movement models.
GridOccupancy.SINGLE — at most one agent per cell. placeAt throws if the target cell is already occupied by a different agent; use tryPlaceAt for the conditional case.
Boundary semantics:
Bounded (default) — coordinates outside
[0, columns) × [0, rows)throw. Cells near the edge have fewer neighbors.Torus (
torus = true) — coordinates wrap; the top-left and top-right cells are neighbors. Useful for finite-but-edge-free models (Game of Life, infinite-plane approximations).
Spatial queries — neighborsOf, agentsAt, cellsWithin — do linear scans over the occupancy map. Performance is fine for typical agent counts; a future spatial index could swap in without changing this class's public API.
Constructors
Types
Mutable global defaults for GridProjection queries.
Functions
All agents currently in cells within radius of cell under metric. Excludes occupants of cell itself unless includeCenter is true.
All cells within radius of cell under the given metric. Excludes cell itself unless includeSelf is true. Cells outside the bounds are dropped for non-torus grids.
The 8 cells in the Moore neighborhood (Chebyshev distance 1) around cell. If includeSelf is true, cell is included. Cells outside the bounds are dropped for non-torus grids; for torus grids the full 8 (or 9 with self) are always returned.
Called by the AgentModel.Context when agent leaves. Default no-op — projections that track per-agent state (positions, edges) typically override to drop their bookkeeping for the departing agent.
Conditional placement for single-occupancy grids: returns true if the cell was free (or already held this agent) and the placement succeeded; false if the cell was occupied by another agent. Always succeeds for multi-occupancy grids.
The 4 cells in the Von Neumann neighborhood (Manhattan distance