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

Use the changeTurn method to make a move programmatically #18

Closed
Pepijnk12 opened this issue Oct 17, 2022 · 4 comments
Closed

Use the changeTurn method to make a move programmatically #18

Pepijnk12 opened this issue Oct 17, 2022 · 4 comments

Comments

@Pepijnk12
Copy link

From the documentation it is not entirely clear how to make a move programmatically.
Can the changeTurn method be used to do this?

Thank you for this amazing chess package. It really helps me to create my hobby chess analysis tool.
If you need any help to develop this package, please let me know.

@qwerty084
Copy link
Owner

qwerty084 commented Oct 17, 2022

Hey,

thanks for your feedback!
The development and documentation is still in an early stage and far from finished.

You can use the move() function provided by the lichess chessground to make a move on the board programmatically.

Example:

function makeMove() {
  boardAPI.value?.board.move('e2', 'e4');  
  setTimeout(() => {  
    boardAPI.value?.board.move('e7', 'e5');  
  }, 1000);  
}

Any help in development would be very welcome :)

@Pepijnk12
Copy link
Author

That does not work because the board and game are then out of sync.

I solved it by updating the board like this:

boardAPI.value.game.move({from: request.from, to: request.to})
boardAPI.value.board.set({
  fen: boardAPI.value.game.fen(),
  turnColor: toColor(boardAPI.value.game),
  movable: {
    color: toColor(boardAPI.value.game),
    dests: possibleMoves(boardAPI.value.game),
  },
});

Thank you for your response!
Do you need help on any specific tasks?

@qwerty084
Copy link
Owner

oh, youre right. Its out of sync :D

If you want you could implement a move method for the boardAPI which stays in sync with the board.
Or if you have any other idea for a feature let me know.

At the moment im mostly working on polishing the board, not really features.

@qwerty084 qwerty084 reopened this Oct 17, 2022
@qwerty084
Copy link
Owner

i added a makeMove method in 0.0.7 (8215b15).

Please reopen this issue if this method doesn't work for you or you see room for improvement.

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