add live game UI with board rendering, timers, and SAN move list
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
export function formatClock(ms) {
|
||||
if (!Number.isFinite(ms) || ms < 0) {
|
||||
return "--:--";
|
||||
}
|
||||
|
||||
const totalSeconds = Math.floor(ms / 1000);
|
||||
const minutes = Math.floor(totalSeconds / 60);
|
||||
const seconds = totalSeconds % 60;
|
||||
return `${String(minutes).padStart(2, "0")}:${String(seconds).padStart(2, "0")}`;
|
||||
}
|
||||
|
||||
export function parseFenBoard(fen) {
|
||||
const boardPart = (fen || "").split(" ")[0] || "8/8/8/8/8/8/8/8";
|
||||
const rows = boardPart.split("/");
|
||||
const board = {};
|
||||
|
||||
for (let r = 0; r < 8; r += 1) {
|
||||
let file = 0;
|
||||
for (const fenChar of rows[r]) {
|
||||
const num = Number(fenChar);
|
||||
if (!Number.isNaN(num)) {
|
||||
file += num;
|
||||
continue;
|
||||
}
|
||||
const square = `${"abcdefgh"[file]}${8 - r}`;
|
||||
board[square] = fenChar;
|
||||
file += 1;
|
||||
}
|
||||
}
|
||||
|
||||
return board;
|
||||
}
|
||||
Reference in New Issue
Block a user