this.INIT_COL_ROOK = { w: [-1, -1], b: [-1, -1] };
this.kingPos = { w: [-1, -1], b: [-1, -1] }; //squares of white and black king
const fenRows = V.ParseFen(fen).position.split("/");
+ const startRow = { 'w': V.size.x - 1, 'b': 0 };
for (let i = 0; i < fenRows.length; i++) {
let k = 0; //column index on board
for (let j = 0; j < fenRows[i].length; j++) {
this.INIT_COL_KING["w"] = k;
break;
case "r":
- if (this.INIT_COL_ROOK["b"][0] < 0) this.INIT_COL_ROOK["b"][0] = k;
- else this.INIT_COL_ROOK["b"][1] = k;
+ if (i == startRow['b']) {
+ if (this.INIT_COL_ROOK["b"][0] < 0) this.INIT_COL_ROOK["b"][0] = k;
+ else this.INIT_COL_ROOK["b"][1] = k;
+ }
break;
case "R":
- if (this.INIT_COL_ROOK["w"][0] < 0) this.INIT_COL_ROOK["w"][0] = k;
- else this.INIT_COL_ROOK["w"][1] = k;
+ if (i == startRow['w']) {
+ if (this.INIT_COL_ROOK["w"][0] < 0) this.INIT_COL_ROOK["w"][0] = k;
+ else this.INIT_COL_ROOK["w"][1] = k;
+ }
break;
default: {
const num = parseInt(fenRows[i].charAt(j));
move.start.x == firstRank && //our rook moves?
this.INIT_COL_ROOK[c].includes(move.start.y)
) {
- const flagIdx = move.start.y == this.INIT_COL_ROOK[c][0] ? 0 : 1;
+ const flagIdx = (move.start.y == this.INIT_COL_ROOK[c][0] ? 0 : 1);
this.castleFlags[c][flagIdx] = false;
} else if (
move.end.x == oppFirstRank && //we took opponent rook?
this.INIT_COL_ROOK[oppCol].includes(move.end.y)
) {
- const flagIdx = move.end.y == this.INIT_COL_ROOK[oppCol][0] ? 0 : 1;
+ const flagIdx = (move.end.y == this.INIT_COL_ROOK[oppCol][0] ? 0 : 1);
this.castleFlags[oppCol][flagIdx] = false;
}
}
play(move) {
// DEBUG:
// if (!this.states) this.states = [];
-// const stateFen = this.getBaseFen() + this.getTurnFen() + this.getFlagsFen();
+// const stateFen = this.getBaseFen() + this.getTurnFen();// + this.getFlagsFen();
// this.states.push(stateFen);
if (V.HasFlags) move.flags = JSON.stringify(this.aggregateFlags()); //save flags (for undo)
this.unupdateVariables(move);
// DEBUG:
-// const stateFen = this.getBaseFen() + this.getTurnFen() + this.getFlagsFen();
+// const stateFen = this.getBaseFen() + this.getTurnFen();// + this.getFlagsFen();
// if (stateFen != this.states[this.states.length-1]) debugger;
// this.states.pop();
}