Question

I am trying to make a game where the aim is to correctly set up the chessboard using chessboard.js

I have this at the moment which shows the start position as an object, and the most recent move in the same format:

var setup1 = ChessBoard.fenToObj('rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR');
var onDrop = function(source, target, piece, newPos, oldPos, orientation) {

$.each( setup1, function( key, value ) {
if (target == key && piece !== value) {
console.log("wrong");
return 'snapback';
}

});

Setup1 here returns Object {a8: "bR", b8: "bN", c8: "bB", d8: "bQ", e8: "bK"…}

target returns a8 piece returns "bR"

What would be the best way to check that setup1 contains the correct combination of target and piece?

When I try the above, I can correctly display "wrong" in the console, but cannot return 'snapback' to onDrop. Is there a problem with nested functions?

Was it helpful?

Solution

Try with setup1.contains(move1);

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top