Lost Lily/Grid ToolkitDocs 1.0
Table of Contents

Build selections and custom filters

When to use

Build a selection when gameplay needs a topology-aware, immutable set of candidate cells before previewing or applying an action.

Before you start

Start with a board definition, a valid origin coordinate, and one of Single, Radius, Ring, Line, or Offsets.

Procedure

Excerpt — filter a selection with current board state. Tested using public APIs.

public static GridSelection SelectNearbyCells()
{
    GridBoardDefinition definition =
        SquareGridBoardFactory.CreateRectangle(width: 5, height: 5);
    GridSelection nearby = GridSelectionPatterns
        .Radius(maxDistance: 2)
        .Select(definition, new SquareGridCoordinate(2, 2));

    return nearby.Where(coordinate =>
        coordinate is SquareGridCoordinate square &&
        (square.X + square.Y) % 2 == 0);
}

Call Where(...) on GridSelection to create another detached, immutable selection. Keep topology traversal in the pattern and game-specific eligibility in the predicate.

When eligibility depends on live board data, filter against a current read-only state view after creating the logical pattern result.

Result

The result is deduplicated, ordered, and contains only definition cells. It does not reserve cells, change visual state, or mutate the board.

Troubleshooting

Symptom Check
The pattern uses the wrong coordinate system. Normalize the origin and offsets through the definition topology.
A radius, ring, or line is clipped near an edge. Patterns return only cells that exist in the definition.