chess.js icon indicating copy to clipboard operation
chess.js copied to clipboard

set turn

Open dngo opened this issue 8 years ago • 1 comments

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 avatar Jan 06 '17 17:01 dngo

@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.

AlexeiDarmin avatar Jan 06 '17 21:01 AlexeiDarmin