Add and remove runtime cells
When to use
Add or remove runtime cells when a live board must grow or shrink after its definition is frozen.
Before you start
Start from a ready runtime board created by the beginner path or the code-owned board workflow.
Use a live GridBoardState and a coordinate compatible with its topology. Decide what should happen if a removed cell is occupied; the default is rejection.
Procedure
Excerpt — add and remove runtime cells through actions. Tested using public APIs.
public static CellMutationResult AddAndRemoveRuntimeCell()
{
using GridBoardState state = CreateProgrammaticBoard();
GridCoordinate coordinate = new SquareGridCoordinate(4, 0);
GridActionResult added =
GridActionRunner.Apply(state, GridActions.AddCell(coordinate));
bool presentAfterAdd = state.ContainsCell(coordinate);
GridActionResult removed =
GridActionRunner.Apply(state, GridActions.RemoveCell(coordinate));
return new CellMutationResult(
added.Success,
removed.Success,
presentAfterAdd,
state.ContainsCell(coordinate),
state.Revision);
}
Preview when the operation is driven by uncertain input. For an occupied cell, explicitly choose the occupied-cell removal mode only if removing its occupants is the intended game operation.
Result
The added cell exists after revision 1; it is absent after revision 2. Each commit publishes a
separate event batch. The immutable board definition remains unchanged.
Troubleshooting
| Symptom | Check |
|---|---|
| Add reports that the cell already exists. | Choose a coordinate not present in the current state. |
| Remove reports that the cell is missing. | Read the current state and create a fresh request. |
| The coordinate is rejected by the topology. | Construct and normalize it through the board's coordinate system. |
| An occupied cell cannot be removed. | Move or remove its occupants first, or deliberately choose the occupied-cell removal mode. |