/** * Chess bot — basic random / tactical bot. */ import type { Rng } from "@3miz/game-server-sdk"; import { isValidMove, type State } from "./game.ts"; export function decideBot(s: State, seat: number, rng: Rng): { fromIdx: number; toIdx: number } | null { const player = s.players[seat]; if (!player) return null; const color = player.color; const moves: { from: number; to: number }[] = []; for (let i = 0; i < 64; i++) { const piece = s.board[i]; if (!piece || piece.color !== color) continue; for (let to = 0; to < 64; to++) { if (isValidMove(s, i, to, seat)) { moves.push({ from: i, to }); } } } if (moves.length === 0) return null; const pick = moves[rng.int(moves.length)]; return { fromIdx: pick.from, toIdx: pick.to }; }