mwg API
    Preparing search index...

    Function searchAsync

    • Chooses a move the way search does, but scores each root move on a worker thread, so the 90 ms a depth-3 search costs (T161) does not drop the caller's frames. The split is synchronous and cheap; one threads.spawn task per root move carries the subtree, and ai.firstWins combines the scores in root order, so the choice is deterministic. Inside the node budget the move is exactly the one search returns: every subtree runs the same alpha-beta with a full window, and exact per-move scores in the same order pick the same winner. Past the budget, or when cancelled, this resolves { move: null } the way the synchronous search does.

      Parameters

      Returns Promise<ChessSearchResult>

      import { searchAsync, startingChess } from '@datamoc/mwg/board';

      const result = await searchAsync(startingChess(), { depth: 2 });
      console.log(result.move !== null); // true - the opening position always has legal moves