public static class ArrayListGrid.Bounded extends Grid
ArrayListGrid.Bounded object is a rectangular,
bounded 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.Bounded 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 |
|---|
Bounded(boolean includeDiagonalNeighbors,
int rows,
int cols)
Constructs an empty ArrayListGrid.Bounded object with the given
dimensions.
|
Bounded(int rows,
int cols)
Constructs an empty ArrayListGrid.Bounded object with the given
dimensions.
|
| 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 Bounded(int rows,
int cols)
rows > 0 and cols > 0.)rows - number of rows in gridcols - number of columns in gridjava.lang.IllegalArgumentException - if the precondition is not metpublic Bounded(boolean includeDiagonalNeighbors,
int rows,
int cols)
includeDiagonalNeighbors parameter. Cells along
the grid boundaries will have fewer than the maximum four or
eight neighbors. 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 neighborsrows - number of rows in gridcols - number of columns in gridjava.lang.IllegalArgumentException - if the precondition is not met