You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am currently using chessboard.js as a frontend to process a game whose logic is controlled with an engine I've written in C++. Currently, whenever I make a move (with the onDrop event and draggable set to true), it determines whether it is a valid move, makes the move on my backend C++ board, queries it for its FEN string, and updates the chessboard display accordingly. This is working fine so far, but I am running into issues when I attempt to promote a pawn.
My onDrop function looks like this:
function onDrop(source, target, piece, newPos, oldPos, orientation) {
// Gets the start and end squares of the move
var source_index = squareIndexes.indexOf(source);
var target_index = squareIndexes.indexOf(target);
// Returns true if this is a valid move
if (Module.MakeMove(source_index, target_index)) {
UpdateBoard();
return true;
}
return 'snapback';
}
My Update Board function looks like this:
/* Gets the FEN string from the chess engine and updates the display */
function UpdateBoard() {
// boardPosition contains an FEN string of the true board representation
var boardPosition = Module.GetBoardPosition();
// Sets the board position to the correct FEN string
board.position(boardPosition, false);
}
Through debugging, I've found that the chess engine is processing the move correctly, and the FEN string Module.GetBoardPosition() returns shows a queen where the pawn previously was. However, it seems that chessboard.js in this case is updating the board twice, the first time it correctly updates the pawn to a queen. This is the expected behavior, however, it somehow updates the board position a second time, reverting the queen to a pawn. (This was verified by logging with the onChange event). Upon the next move for the other side, chessboard.js gets correctly updated and a queen appears, but it only shows correctly upon the move following the promotion.
I have no idea why the board position is being updated twice in the event of a pawn promotion and even weirder, why it is reverting the promoted queen back to a pawn, even though the FEN string the board position is being set to contains a queen there.
Any help would be super appreciated as I have been battling this issue for a while.
The text was updated successfully, but these errors were encountered:
I am currently using chessboard.js as a frontend to process a game whose logic is controlled with an engine I've written in C++. Currently, whenever I make a move (with the onDrop event and draggable set to true), it determines whether it is a valid move, makes the move on my backend C++ board, queries it for its FEN string, and updates the chessboard display accordingly. This is working fine so far, but I am running into issues when I attempt to promote a pawn.
My onDrop function looks like this:
My Update Board function looks like this:
Through debugging, I've found that the chess engine is processing the move correctly, and the FEN string
Module.GetBoardPosition()
returns shows a queen where the pawn previously was. However, it seems that chessboard.js in this case is updating the board twice, the first time it correctly updates the pawn to a queen. This is the expected behavior, however, it somehow updates the board position a second time, reverting the queen to a pawn. (This was verified by logging with theonChange
event). Upon the next move for the other side, chessboard.js gets correctly updated and a queen appears, but it only shows correctly upon the move following the promotion.I have no idea why the board position is being updated twice in the event of a pawn promotion and even weirder, why it is reverting the promoted queen back to a pawn, even though the FEN string the board position is being set to contains a queen there.
Any help would be super appreciated as I have been battling this issue for a while.
The text was updated successfully, but these errors were encountered: