I am creating a chess related application using nodejs. I tried to use chess.js as much as I can, but I think I ran into a checkpoint in terms of functionality. Before expanding this functionality, I wanted to make sure that there was no other tool that could do what I needed.
I am looking for a way to convert a PGN string to a FEN motion list. I was hoping to use load_pgn() in chess.js to load movements into an object, and then loop over each movement and call the fen() function to output the current FEN. However, chess.js does not seem to have the ability to go through the turn in the game. If I didn’t miss something.
I would prefer not to understand the syntax lines, but if necessary. Any suggestions?
Decision:
also see efirvida below for a solution
It seems to be something like this (untested). The function accepts a Chess object created using chess.js , which has already loaded PGN into it.
function getMovesAsFENs(chessObj) { var moves = chessObj.history(); var newGame = new Chess(); var fens = []; for (var i = 0; i < moves.length; i++) { newGame.move(moves[i]); fens.push(newGame.fen()); } return fens; }
n0pe source share