chess.js
chess.js copied to clipboard
set turn
It would be helpful to have a public method for setting turn and be able to call something like chess.turn('w')
Right now in order to change the turn, I have to call .load and pass it a fen, which clears the entire history
@dngo Although inconvenient, here is what I've done with a work around to set turn and store history.
https://github.com/jhlywa/chess.js/issues/62
/* untested, seems to save history so you can continue using .undo() */
let getOpponentMoves = (symGame) => {
let gamePGN = symGame.pgn()
let tokens = symGame.fen().split(' ')
tokens[1] = tokens[1] === 'w' ? 'b' : 'w'
symGame.load(tokens.join(' '))
let moves = symGame.moves()
tokens = symGame.fen().split(' ')
tokens[1] = tokens[1] === 'w' ? 'b' : 'w'
symGame.load_pgn(gamePGN)
return moves
}
Also I don't think there should be two issues for the same topic.