Initial Commit

This commit is contained in:
ar_rezaei
2026-10-09 16:46:29 +03:30
commit bc5783145b
23 changed files with 2512 additions and 0 deletions
+24
View File
@@ -0,0 +1,24 @@
/**
* 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 };
}