feat : add minimum delay to engine next move in /play
This commit is contained in:
@@ -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));
|
||||||
|
|||||||
@@ -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();
|
||||||
|
|||||||
Reference in New Issue
Block a user