mwg API
    Preparing search index...

    Function weightedFlood

    • Dijkstra-style weighted flood fill, independent of a particular board or game rule.

      Type Parameters

      • T
      • K

      Parameters

      Returns Map<K, WeightedCell<T>>

      import { weightedFlood } from '@datamoc/mw_games/core';

      const cells = weightedFlood(0, {
      key: (cell) => cell,
      neighbors: (cell) => cell < 3 ? [cell + 1] : [],
      cost: () => 1,
      maxCost: 2,
      });
      console.log(cells.get(2)?.cost); // 2

      The returned map includes start at cost 0. A game can use canEnter for blockers and stop for rules such as a zone-of-control boundary; neither callback is interpreted here. Equal-cost revisits are discarded, and the input cells are never mutated.