public static class ArrayListGrid.Unbounded extends Grid
ArrayListGrid.Unounded object is an unbounded
two-dimensional container data structure implemented as
an ArrayList of the objects it contains. It can contain
any kind of object that can be modeled using an extension of the
GridObject class. For example, a bounded grid could
be used to model a board for a tic-tac-toe or chess game, an
environment of fish for a marine biology simulation, etc.
ArrayListGrid.Unbounded methods have the
following time and space characteristics:
| numObjects | O(1) | |
| allObjects | O(n) | |
| isEmpty, objectAt | O(n) | |
| add | O(1) [amortized] | |
| remove | O(n) | |
| space | O(n) |
n is the number of objects in the grid.Grid.BoundedGridValidityChecker, Grid.InternalRepresentation, Grid.UnboundedGridValidityChecker, Grid.ValidityCheckerincludeDiagonals, internalRep, UNBOUNDED| Constructor and Description |
|---|
Unbounded()
Constructs an empty ArrayListGrid.Unbounded object.
|
Unbounded(boolean includeDiagonalNeighbors)
Constructs an empty ArrayListGrid.Unbounded object.
|
| Modifier and Type | Method and Description |
|---|---|
int |
numCols()
Returns number of columns in this grid.
|
int |
numRows()
Returns number of rows in this grid.
|
add, allObjects, getDirection, getNeighbor, isEmpty, isValid, neighborsOf, numAdjacentNeighbors, numObjects, objectAt, randomDirection, remove, remove, removeAll, toStringpublic Unbounded()
rows > 0 and cols > 0.)public Unbounded(boolean includeDiagonalNeighbors)
includeDiagonalNeighbors parameter. If
includeDiagonalNeighbors is true,
a cell's adjacent neighbors include the cells to its north,
south, east, and west and the cells on the diagonals, to
the northeast, southeast, northwest, and southwest. If
includeDiagonalNeighbors is false,
a cell's adjacent neighbors include only the four cells to
its north, south, east, and west.
(Precondition: rows > 0 and cols > 0.)includeDiagonalNeighbors - whether to include the four
diagonal locations as neighbors