-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Luca Hendrik Helms
committed
Oct 24, 2022
1 parent
3b128bc
commit 8215b15
Showing
7 changed files
with
106 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { possibleMoves } from '@/helper/Board'; | ||
import { moveableSquaresWhite } from './Constants'; | ||
import type { BoardAPI } from '@/typings/BoardAPI'; | ||
import type { SquareKey } from '@/typings/Chessboard'; | ||
|
||
export function randomMoveFirstMove(boardApi: BoardAPI) { | ||
const moves = possibleMoves(boardApi.game); | ||
const randomSquare = | ||
moveableSquaresWhite[ | ||
Math.floor(Math.random() * moveableSquaresWhite.length) | ||
]; | ||
const random = Math.floor(Math.random() * 2); | ||
const move = moves.get(randomSquare)?.[random] as SquareKey; | ||
if (!move) { | ||
console.warn('Random move is undefined'); | ||
return; | ||
} | ||
boardApi?.makeMove(randomSquare, move); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters