mwg API
    Preparing search index...

    Function rootSplits

    • Splits a search at the root: every legal move paired with the position it reaches, in the game's own stable order. A child must be plain structured-cloneable data to cross to a worker; a game whose states hold closures or class instances cannot split this way.

      Type Parameters

      • State
      • Move

      Parameters

      Returns RootSplit<State, Move>[]

      import { rootSplits } from '@datamoc/mwg/ai';

      const game = {
      currentPlayer: () => 1,
      moves: (state: number) => state < 2 ? [1] : [],
      apply: (state: number, move: number) => state + move,
      isTerminal: (state: number) => state >= 2,
      evaluate: (state: number) => state,
      };
      const splits = rootSplits(game, 0);
      console.log(splits.length, splits[0].child); // 1 1