[V.QUEEN]: 0,
}
};
- // May be a continuation: adjust numbers of pieces according to captures + rebirths
- this.moves.forEach(m => {
- if (m.vanish.length == 2)
- this.reserve[m.appear[0].c][m.vanish[1].p]++;
- else if (m.vanish.length == 0)
- this.reserve[m.appear[0].c][m.appear[0].p]--;
- });
- // TODO: keep track of promoted pawns ==> give a pawn if captured.
+ const [sizeX,sizeY] = VariantRules.size;
+ this.promoted = doubleArray(sizeX, sizeY, false);
+ // May be a continuation: adjust numbers of pieces in reserve + promoted pieces
+ this.moves.forEach(m => { this.updateVariables(m); });
}
getColor(i,j)
return color + VariantRules.RESERVE_PIECES[index];
}
- // Put an ordering on reserve pieces
+ // Ordering on reserve pieces
static get RESERVE_PIECES() {
const V = VariantRules;
return [V.PAWN,V.ROOK,V.KNIGHT,V.BISHOP,V.QUEEN];
})
],
vanish: [],
- start: {x:sizeX, y:y}, //a bit artificial...
+ start: {x:x, y:y}, //a bit artificial...
end: {x:i, y:j}
});
moves.push(mv);
getPotentialMovesFrom([x,y])
{
const sizeX = VariantRules.size[0];
- if (x < sizeX)
- return super.getPotentialMovesFrom([x,y]);
- // Reserves, outside of board: x == sizeX
- return this.getReserveMoves([x,y]);
+ if (x >= sizeX)
+ {
+ // Reserves, outside of board: x == sizeX(+1)
+ return this.getReserveMoves([x,y]);
+ }
+ // Standard moves
+ return super.getPotentialMovesFrom([x,y]);
}
getAllValidMoves()
const color = this.turn;
const sizeX = VariantRules.size[0];
for (let i=0; i<VariantRules.RESERVE_PIECES.length; i++)
- moves = moves.concat(this.getReserveMoves([sizeX,i]));
+ moves = moves.concat(this.getReserveMoves([sizeX+(color=="w"?0:1),i]));
return this.filterValid(moves);
}
updateVariables(move)
{
super.updateVariables(move);
+ if (move.vanish.length == 2 && move.appear.length == 2)
+ return; //skip castle
const color = this.turn;
- if (move.vanish.length==2)
- this.reserve[color][move.vanish[1].p]++;
- if (move.vanish.length==0)
+ const V = VariantRules;
+ if (move.vanish.length == 0)
+ {
this.reserve[color][move.appear[0].p]--;
+ return;
+ }
+ move.movePromoted = this.promoted[move.start.x][move.start.y];
+ move.capturePromoted = this.promoted[move.end.x][move.end.y]
+ this.promoted[move.start.x][move.start.y] = false;
+ this.promoted[move.end.x][move.end.y] = move.movePromoted
+ || (move.vanish[0].p == V.PAWN && move.appear[0].p != V.PAWN);
+ if (move.capturePromoted)
+ this.reserve[color][VariantRules.PAWN]++;
+ else if (move.vanish.length == 2)
+ this.reserve[color][move.vanish[1].p]++;
}
unupdateVariables(move)
{
super.unupdateVariables(move);
+ if (move.vanish.length == 2 && move.appear.length == 2)
+ return;
const color = this.turn;
- if (move.vanish.length==2)
- this.reserve[color][move.vanish[1].p]--;
- if (move.vanish.length==0)
+ const V = VariantRules;
+ if (move.vanish.length == 0)
+ {
this.reserve[color][move.appear[0].p]++;
+ return;
+ }
+ if (move.movePromoted)
+ this.promoted[move.start.x][move.start.y] = true;
+ this.promoted[move.end.x][move.end.y] = move.capturePromoted;
+ if (move.capturePromoted)
+ this.reserve[color][VariantRules.PAWN]--;
+ else if (move.vanish.length == 2)
+ this.reserve[color][move.vanish[1].p]--;
}
static get SEARCH_DEPTH() { return 2; } //high branching factor
+ evalPosition()
+ {
+ let evaluation = super.evalPosition();
+ // Add reserves:
+ for (let i=0; i<VariantRules.RESERVE_PIECES.length; i++)
+ {
+ const p = VariantRules.RESERVE_PIECES[i];
+ evaluation += this.reserve["w"][p] * VariantRules.VALUES[p];
+ evaluation -= this.reserve["b"][p] * VariantRules.VALUES[p];
+ }
+ return evaluation;
+ }
+
getNotation(move)
{
if (move.vanish.length > 0)
String.fromCharCode(97 + move.end.y) + (VariantRules.size[0]-move.end.x);
return piece + "@" + finalSquare;
}
+
+ getLongNotation(move)
+ {
+ if (move.vanish.length > 0)
+ return super.getLongNotation(move);
+ const finalSquare =
+ String.fromCharCode(97 + move.end.y) + (VariantRules.size[0]-move.end.x);
+ return "@" + finalSquare;
+ }
}