Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to make chess.js play white and make a first move? #474

Open
Huub62 opened this issue Sep 3, 2024 · 1 comment
Open

How to make chess.js play white and make a first move? #474

Huub62 opened this issue Sep 3, 2024 · 1 comment

Comments

@Huub62
Copy link

Huub62 commented Sep 3, 2024

For a kids-chessgame I use chess.js and chessboard.js. Playing with white is easy, but how can i let chess.js make a first move and let the kids play with black?

Thanks in advance for any help.

@tazo-taz
Copy link

It has built in method which returns all possible moves of current player and you can let computer start playing.

const moves = chess.moves({ verbose: true })
const randomMove = moves[Math.floor(Math.random() * moves.length)]
chess.play(randomMove)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants