feat : add click on engine lines

This commit is contained in:
GuillaumeSD
2025-05-11 18:21:45 +02:00
parent 74a2adbb7d
commit 6535fce2f4
22 changed files with 285 additions and 156 deletions

View File

@@ -67,7 +67,7 @@ export const useChessActions = (chessAtom: PrimitiveAtom<Chess>) => {
[copyGame, setGame]
);
const makeMove = useCallback(
const playMove = useCallback(
(params: {
from: string;
to: string;
@@ -92,6 +92,18 @@ export const useChessActions = (chessAtom: PrimitiveAtom<Chess>) => {
[copyGame, setGame]
);
const addMoves = useCallback(
(moves: string[]) => {
const newGame = copyGame();
for (const move of moves) {
newGame.move(move);
}
setGame(newGame);
},
[copyGame, setGame]
);
const undoMove = useCallback(() => {
const newGame = copyGame();
const move = newGame.undo();
@@ -127,9 +139,10 @@ export const useChessActions = (chessAtom: PrimitiveAtom<Chess>) => {
return {
setPgn,
reset,
makeMove,
playMove,
undoMove,
goToMove,
resetToStartingPosition,
addMoves,
};
};