feat : add minimum delay to engine next move in /play

This commit is contained in:
GuillaumeSD
2025-05-17 15:14:44 +02:00
parent 0e5939675b
commit b07a8e14c1
2 changed files with 8 additions and 0 deletions

View File

@@ -13,3 +13,6 @@ export const isInViewport = (element: HTMLElement) => {
rect.bottom <= (window.innerHeight || document.documentElement.clientHeight) rect.bottom <= (window.innerHeight || document.documentElement.clientHeight)
); );
}; };
export const sleep = (ms: number) =>
new Promise((resolve) => setTimeout(resolve, ms));

View File

@@ -15,6 +15,7 @@ import { uciMoveParams } from "@/lib/chess";
import Board from "@/components/board"; import Board from "@/components/board";
import { useGameData } from "@/hooks/useGameData"; import { useGameData } from "@/hooks/useGameData";
import { usePlayersData } from "@/hooks/usePlayersData"; import { usePlayersData } from "@/hooks/usePlayersData";
import { sleep } from "@/lib/helpers";
export default function BoardContainer() { export default function BoardContainer() {
const screenSize = useScreenSize(); const screenSize = useScreenSize();
@@ -40,7 +41,11 @@ export default function BoardContainer() {
) { ) {
return; return;
} }
const timePromise = sleep(1000);
const move = await engine.getEngineNextMove(gameFen, engineElo); const move = await engine.getEngineNextMove(gameFen, engineElo);
await timePromise;
if (move) playMove(uciMoveParams(move)); if (move) playMove(uciMoveParams(move));
}; };
playEngineMove(); playEngineMove();