mwg API
    Preparing search index...

    Function firstWins

    • First-wins reduction over scored root moves: a strictly better score replaces the leader, a tie keeps the earlier move, so the same scores in the same order always choose the same move - the property that keeps a parallel root split deterministic.

      Type Parameters

      • Move

      Parameters

      • scored: readonly { move: Move; score: number }[]
      • maximizing: boolean

      Returns Move | null

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

      console.log(firstWins([{ move: 'a', score: 1 }, { move: 'b', score: 1 }], true)); // 'a'
      console.log(firstWins([{ move: 'a', score: 1 }, { move: 'b', score: 2 }], true)); // 'b'