working on useScore

This commit is contained in:
2025-10-15 19:02:22 +01:00
parent 2dd317e0dc
commit 800d9d083f
2 changed files with 39 additions and 9 deletions
+8
View File
@@ -1,3 +1,4 @@
import { useEffect } from "react";
import { useGame } from "../../src/useGame/useGame";
import { useKeyBindings } from './useKeyBindings';
import { useMounted } from './useMounted';
@@ -18,12 +19,19 @@ export default function App() {
initGame,
solveBoard,
scoreManager,
boardManager,
keyLog,
gameStatus,
} = useGame(useKeyBindings);
const { timeValue, finalScore } = scoreManager;
const stringed = boardManager.boardToString(true);
useEffect(() => {
console.log(stringed);
}, [stringed]);
return (
<div style={{ padding: 16 }}>
<h1>VIMazing Sudoku</h1>
+22
View File
@@ -41,6 +41,27 @@ export function useBoardState(cursorManager: UseCursorType) {
}
}, [board]);
const boardToString = useCallback((human: boolean = false) => {
// Computer-optimized: compact 81-character string
if (!human) {
return board;
}
// Human-readable: formatted grid with 3x3 box separators
let result = "";
for (let r = 0; r < 9; r++) {
for (let c = 0; c < 9; c++) {
const idx = r * 9 + c;
result += board[idx] === "." ? "." : board[idx];
if (c === 2 || c === 5) result += " | ";
else if (c < 8) result += " ";
}
result += "\n";
if (r === 2 || r === 5) result += "------+-------+------\n";
}
return result;
}, [board]);
return {
board,
initialBoard,
@@ -49,6 +70,7 @@ export function useBoardState(cursorManager: UseCursorType) {
erase,
reset,
solveBoard,
boardToString,
};
}