play(move, ingame)
{
+ // DEBUG:
+// if (!this.states) this.states = [];
+// if (!ingame) this.states.push(JSON.stringify(this.board));
+
if (!!ingame)
move.notation = [this.getNotation(move), this.getLongNotation(move)];
this.moves.pop();
this.unupdateVariables(move);
this.parseFlags(JSON.parse(move.flags));
+
+ // DEBUG:
+// if (JSON.stringify(this.board) != this.states[this.states.length-1])
+// debugger;
+// this.states.pop();
}
//////////////
// END OF GAME
// Basic check for 3 repetitions (in the last moves only)
+ // TODO: extend to usual 3-repetition recognition (storing FEN with move?)
checkRepetition()
{
if (this.moves.length >= 8)
// Setup the initial random (assymetric) position
static GenRandInitFen()
{
- let pieces = [new Array(8), new Array(8)];
+ let pieces = { "w": new Array(8), "b": new Array(8) };
// Shuffle pieces on first and last rank
- for (let c = 0; c <= 1; c++)
+ for (let c of ["w","b"])
{
let positions = _.range(8);
pieces[c][knight2Pos] = 'n';
pieces[c][rook2Pos] = 'r';
}
- let fen = pieces[0].join("") +
+ return pieces["b"].join("") +
"/pppppppp/8/8/8/8/PPPPPPPP/" +
- pieces[1].join("").toUpperCase() +
+ pieces["w"].join("").toUpperCase() +
" 1111"; //add flags
- return fen;
}
// Return current fen according to pieces+colors state