mwg API
    Preparing search index...

    Function chooseMove

    • Picks the move whose type is most effective against opponentTypes, ties keeping the first candidate; null for an empty list.

      Type Parameters

      • M extends { type: string }

      Parameters

      • moves: readonly M[]
      • matrix: TypeMatrix
      • opponentTypes: readonly string[]
      • score: (move: M, opponentTypes: readonly string[]) => number = ...

      Returns M | null

      import { chooseMove, chooseSwitch, TypeMatrix } from '@datamoc/mw_games/battle';

      const matrix = new TypeMatrix();
      matrix.set('fire', 'grass', 2);

      const moves = [{ type: 'fire' }, { type: 'normal' }];
      const best = chooseMove(moves, matrix, ['grass']); // the fire move

      const bench = [{ types: ['water'] }, { types: ['grass'] }];
      const swapTo = chooseSwitch(['grass'], bench, matrix, ['fire']); // index of the water one