Grid<T extends Object> class
A generic grid class that holds a 2D list of objects of type T
.
Constructors
Properties
- columns → int
-
Returns the number of columns in the grid.
no setter
- hashCode → int
-
The hash code for this object.
no setteroverride
- initialValue → T
-
The initial value for the grid cells.
final
- rows → int
-
Returns the number of rows in the grid.
no setter
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- size → ({int columns, int rows})
-
Returns the size of the grid as a map with keys
rows
andcolumns
.no setter -
vector
→ Vector2D<
T> -
Returns the _vector
no setter
Methods
-
copyWith(
{Vector2D< T> ? vector}) → Grid<T> -
Creates a copy of the grid with the option to replace the
vector
values. Ifvector
is provided, it will be used to create the new grid. -
fillCells(
List< GridCell> cells, T state) → void -
Fills the specified
cells
with the givenstate
. -
filledCells(
bool filter(T state)) → List< GridCell> -
Returns a list of GridCells that match the given
filter
function. -
filledCellsCount(
bool filter(T state)) → int -
Returns the count of cells that match the given
filter
function. -
filter(
GridCell cell, bool filter(T state)) → bool -
Applies the
filter
function to the cell at the givencell
position. -
filterCells(
List< GridCell> cells, bool filter(T state)) → bool -
Applies the
filter
function to all the specifiedcells
. Returnstrue
if all cells match the filter, otherwisefalse
. -
firstWhereOrNull(
bool predicate(T state)) → GridCell? -
Returns the first GridCell that matches the given
predicate
function, ornull
if none found. -
getNeighbourPositions(
GridCell cell) → Map< String, GridCell?> -
Returns a map of neighboring positions for the given
cell
. The keys areabove
,below
,left
, andright
. -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
resetCells(
List< GridCell> cells) → void -
Resets the specified
cells
to the initial value. -
toString(
) → String -
A string representation of this object.
inherited
-
validPosition(
GridCell cell) → bool -
Checks if the given
cell
position is valid within the grid boundaries.
Operators
-
operator ==(
Object other) → bool -
The equality operator.
override
-
operator [](
GridCell cell) → T -
operator []=(
GridCell cell, T value) → void