INNER CODE UNIT · TypeScript
aiMove
josefjadrny/js-chess-engine · src/index.ts:458
export function aiMove(config: BoardConfig | string, level: number = 3): HistoryEntry {
const game = new Game(config);
return game.aiMove(level);
}
/**
* Make an AI move and return both move and board state
*
* @param config - Board configuration or FEN string
* @param options - Optional configuration object
* @param options.level - AI difficulty level (1-5, default: 3)
* @param options.play - Whether to apply the move to the game (default: true). If false, only returns the move without modifying game state.
* @param options.ttSizeMB - Transposition table size in MB (0 to disable, min 0.25 MB). Default: auto-scaled by level (e.g., level 3: 2 MB Node.js, 1 MB browser)
* @returns Object containing the move and board configuration (current state if play=false, updated state if play=true)
*/
export function ai(
config: BoardConfig | string,
options: { level?: number; play?: boolean; ttSizeMB?: number; depth?: { base?: number; extended?: number; check?: boolean; quiescence?: number }; analysis?: boolean; randomness?: number } = {}