getReserveMoves([x, y]) {
const color = this.turn;
+ const oppCol = V.GetOppCol(color);
const p = V.RESERVE_PIECES[y];
if (this.reserve[color][p] == 0) return [];
const bounds = (p == V.PAWN ? [1, V.size.x - 1] : [0, V.size.x]);
const firstRank = (this.movesCount == 0 ? 9 : 0);
// TODO: initDestFile currently hardcoded for deterministic setup
const initDestFile = new Map([[1, 2], [8, 7]]);
- // Only option is knight / bishop swap:
- if (x == firstRank && !!initDestFile.get(y)) {
+ // Only option is knight --> bishop swap:
+ if (
+ x == firstRank &&
+ !!initDestFile.get(y) &&
+ this.getPiece(x, y) == V.KNIGHT
+ ) {
const destFile = initDestFile.get(y);
return [
new Move({
const steps =
V.steps[V.KNIGHT].concat(V.steps[V.ROOK]).concat(V.steps[V.BISHOP]);
return (
- super.isAttackedBySlideNJump(sq, color, steps, V.SCEPTER, "oneStep")
+ super.isAttackedBySlideNJump(sq, color, V.SCEPTER, steps, "oneStep")
);
}
return (
super.isAttackedBySlideNJump(sq, color, V.steps[V.BISHOP], V.HORSE) ||
super.isAttackedBySlideNJump(
- sq, color, V.steps[V.ROOK], V.HORSE, "oneStep")
+ sq, color, V.HORSE, V.steps[V.ROOK], "oneStep")
);
}
return (
super.isAttackedBySlideNJump(sq, color, V.steps[V.ROOK], V.DRAGON) ||
super.isAttackedBySlideNJump(
- sq, color, V.steps[V.BISHOP], V.DRAGON, "oneStep")
+ sq, color, V.DRAGON, V.steps[V.BISHOP], "oneStep")
);
}
getAllValidMoves() {
let moves = super.getAllPotentialMoves();
- const color = this.turn;
- for (let i = 0; i < V.RESERVE_PIECES.length; i++) {
- moves = moves.concat(
- this.getReserveMoves([V.size.x + (color == "w" ? 0 : 1), i])
- );
+ if (this.movesCount >= 2) {
+ const color = this.turn;
+ for (let i = 0; i < V.RESERVE_PIECES.length; i++) {
+ moves = moves.concat(
+ this.getReserveMoves([V.size.x + (color == "w" ? 0 : 1), i])
+ );
+ }
}
return this.filterValid(moves);
}
}
updateCastleFlags(move, piece) {
- if (move.appear.length == 2) {
+ if (piece == V.KING && move.appear.length == 2) {
// Castling (only move which disable flags)
this.castleFlags[move.appear[0].c][0] = 10;
this.castleFlags[move.appear[0].c][1] = 10;
if (move.vanish.length == 0)
// Drop unpromoted piece:
this.reserve[color][move.appear[0].p]--;
- else if (move.vanish.length == 2)
+ else if (move.vanish.length == 2 && move.appear.length == 1)
// May capture a promoted piece:
this.reserve[color][V.MayDecode(move.vanish[1].p)]++;
}
const color = move.appear[0].c;
if (move.vanish.length == 0)
this.reserve[color][move.appear[0].p]++;
- else if (move.vanish.length == 2)
+ else if (move.vanish.length == 2 && move.appear.length == 1)
this.reserve[color][V.MayDecode(move.vanish[1].p)]--;
}
static get VALUES() {
return Object.assign(
+ {},
+ ChessRules.VALUES,
{
+ n: 2.5, //knight is weaker
g: 9,
s: 5,
h: 6,
w: 9,
m: 8,
a: 9
- },
- ChessRules.VALUES
+ }
);
}