ブラウザ将棋(簡易版)

先手の番です
function cpuMove() { // 後手(g)の全合法手を集める const moves = []; for (let r = 0; r < SIZE; r++) { for (let c = 0; c < SIZE; c++) { const p = board[r][c]; if (p && p[0] === "g") { const legal = getLegalMoves(r, c); legal.forEach(m => { moves.push({ sr: r, sc: c, tr: m.r, tc: m.c }); }); } } } if (moves.length === 0) { alert("後手に合法手がありません。先手の勝ちです!"); return; } // ランダムで 1 手選ぶ const mv = moves[Math.floor(Math.random() * moves.length)]; movePiece(mv.sr, mv.sc, mv.tr, mv.tc); turn = "s"; updateInfo(); render(); checkGameEnd(); }