qwerty084 / vue3-chessboard

Vue 3 chessboard component, built with lichess chessground and chess.js
https://qwerty084.github.io/vue3-chessboard-docs/
GNU General Public License v3.0
70 stars 16 forks source link

Use the changeTurn method to make a move programmatically #18

Closed Pepijnk12 closed 1 year ago

Pepijnk12 commented 2 years ago

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 commented 2 years ago

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 commented 2 years ago

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 commented 2 years ago

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 commented 1 year ago

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.