edu.kzoo.grid
Class ArrayListGrid.Unbounded
java.lang.Object
|
+--edu.kzoo.grid.Grid
|
+--edu.kzoo.grid.ArrayListGrid.Unbounded
- Enclosing class:
- ArrayListGrid
- public static class ArrayListGrid.Unbounded
- extends Grid
An 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) |
where n is the number of objects in the grid.
|
Method Summary |
int |
numCols()
Returns number of columns in this grid. |
int |
numRows()
Returns number of rows in this grid. |
| Methods inherited from class edu.kzoo.grid.Grid |
add, allObjects, getDirection, getNeighbor, isEmpty, isValid, neighborsOf, numAdjacentNeighbors, numObjects, objectAt, randomDirection, remove, remove, removeAll, toString |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
ArrayListGrid.Unbounded
public ArrayListGrid.Unbounded()
- Constructs an empty ArrayListGrid.Unbounded object.
A cell's neighbors include only the cells to its north, south,
east, and west, not the cells on the diagonals.
(Precondition:
rows > 0 and cols > 0.)
ArrayListGrid.Unbounded
public ArrayListGrid.Unbounded(boolean includeDiagonalNeighbors)
- Constructs an empty ArrayListGrid.Unbounded object.
Each cell in this grid will have at most four or eight
adjacent neighbors, depending on the value of the
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.)
- Parameters:
includeDiagonalNeighbors - whether to include the four
diagonal locations as neighbors
numRows
public int numRows()
- Returns number of rows in this grid.
- Specified by:
numRows in class Grid
- Returns:
- the number of rows, or UNBOUNDED if the grid is unbounded
numCols
public int numCols()
- Returns number of columns in this grid.
- Specified by:
numCols in class Grid
- Returns:
- the number of columns, or UNBOUNDED if the grid is unbounded