mwg API
    Preparing search index...

    Function selectDistinctCells

    • Picks count distinct cells out of candidates without replacement, falling back to however many exist when fewer are available rather than throwing or looping forever - a crowded region just gets fewer placements, the same "fail gracefully, place fewer" shape generateDungeonGraph's own room placement already uses. Pure: nothing is placed or marked taken until the caller acts on cells itself (typically FeatureLayer.place, or folding cells into the next call's own occupied set). trace is plain, JSON-safe data a game can push straight into DungeonArtifacts.content for a parity check, or persist across save/load the same way any other roll trace does.

      Composes with candidateCells and cellsNear for the three shapes a regional generator needs: several neighbouring items (cellsNear around one anchor, intersected with a terrain/occupancy pool, then selected from), scattered decorations across a whole region (candidateCells with a large within, then selected from with a larger count), and a single branch or room reward (candidateCells scoped to one room, count: 1).

      Parameters

      • candidates: readonly number[]
      • count: number

      Returns PlacementResult

      import { candidateCells, cellsNear, selectDistinctCells } from '@datamoc/mw_games/roguelike';

      declare const level: import('@datamoc/mw_games/roguelike').Level;
      const FLOOR = new Set([1]);

      // scatter 3 decorations anywhere on the floor
      const pool = candidateCells(level, { terrain: FLOOR });
      const { cells: decorations, trace } = selectDistinctCells(pool, 3);

      // then release 2 more items clustered around one of those cells
      const nearby = cellsNear(level, decorations[0], 2).filter((c) => pool.includes(c));
      const { cells: cluster } = selectDistinctCells(nearby, 2);