class AntikingRules extends ChessRules
{
- // Path to pieces
static getPpath(b)
{
return b[1]=='a' ? "Antiking/"+b : b;
}
static get ANTIKING() { return 'a'; }
-
- initVariables(fen)
+
+ static get PIECES()
+ {
+ return ChessRules.PIECES.concat([V.ANTIKING]);
+ }
+
+ setOtherVariables(fen)
{
- super.initVariables(fen);
+ super.setOtherVariables(fen);
this.antikingPos = {'w':[-1,-1], 'b':[-1,-1]};
- const position = fen.split(" ")[0].split("/");
- for (let i=0; i<position.length; i++)
+ const rows = V.ParseFen(fen).position.split("/");
+ for (let i=0; i<rows.length; i++)
{
let k = 0;
- for (let j=0; j<position[i].length; j++)
+ for (let j=0; j<rows[i].length; j++)
{
- switch (position[i].charAt(j))
+ switch (rows[i].charAt(j))
{
case 'a':
this.antikingPos['b'] = [i,k];
this.antikingPos['w'] = [i,k];
break;
default:
- let num = parseInt(position[i].charAt(j));
+ const num = parseInt(rows[i].charAt(j));
if (!isNaN(num))
k += (num-1);
}
{
switch (this.getPiece(x,y))
{
- case VariantRules.ANTIKING:
+ case V.ANTIKING:
return this.getPotentialAntikingMoves([x,y]);
default:
return super.getPotentialMovesFrom([x,y]);
getPotentialAntikingMoves(sq)
{
- const V = VariantRules;
return this.getSlideNJumpMoves(sq,
V.steps[V.ROOK].concat(V.steps[V.BISHOP]), "oneStep");
}
isAttackedByKing([x,y], colors)
{
- const V = VariantRules;
if (this.getPiece(x,y) == V.ANTIKING)
return false; //antiking is not attacked by king
return this.isAttackedBySlideNJump([x,y], colors, V.KING,
isAttackedByAntiking([x,y], colors)
{
- const V = VariantRules;
if ([V.KING,V.ANTIKING].includes(this.getPiece(x,y)))
return false; //(anti)king is not attacked by antiking
return this.isAttackedBySlideNJump([x,y], colors, V.ANTIKING,
V.steps[V.ROOK].concat(V.steps[V.BISHOP]), "oneStep");
}
- underCheck(move)
+ underCheck(color)
{
- const c = this.turn;
- const oppCol = this.getOppCol(c);
- this.play(move)
- let res = this.isAttacked(this.kingPos[c], [oppCol])
- || !this.isAttacked(this.antikingPos[c], [oppCol]);
- this.undo(move);
+ const oppCol = this.getOppCol(color);
+ let res = this.isAttacked(this.kingPos[color], [oppCol])
+ || !this.isAttacked(this.antikingPos[color], [oppCol]);
return res;
}
- getCheckSquares(move)
+ getCheckSquares(color)
{
- let res = super.getCheckSquares(move);
- this.play(move);
- const c = this.turn;
- if (!this.isAttacked(this.antikingPos[c], [this.getOppCol(c)]))
- res.push(JSON.parse(JSON.stringify(this.antikingPos[c])));
- this.undo(move);
+ let res = super.getCheckSquares(color);
+ if (!this.isAttacked(this.antikingPos[color], [this.getOppCol(color)]))
+ res.push(JSON.parse(JSON.stringify(this.antikingPos[color])));
return res;
}
updateVariables(move)
{
super.updateVariables(move);
- const piece = this.getPiece(move.start.x,move.start.y);
- const c = this.getColor(move.start.x,move.start.y);
+ const piece = move.vanish[0].p;
+ const c = move.vanish[0].c;
// Update antiking position
- if (piece == VariantRules.ANTIKING)
+ if (piece == V.ANTIKING)
{
this.antikingPos[c][0] = move.appear[0].x;
this.antikingPos[c][1] = move.appear[0].y;
unupdateVariables(move)
{
super.unupdateVariables(move);
- const c = this.getColor(move.start.x,move.start.y);
- if (this.getPiece(move.start.x,move.start.y) == VariantRules.ANTIKING)
+ const c = move.vanish[0].c;
+ if (move.vanish[0].p == V.ANTIKING)
this.antikingPos[c] = [move.start.x, move.start.y];
}
return color == "w" ? "0-1" : "1-0";
}
- // Pieces values (TODO: use Object.assign() + ChessRules.VALUES ?)
static get VALUES() {
- return {
- 'p': 1,
- 'r': 5,
- 'n': 3,
- 'b': 3,
- 'q': 9,
- 'k': 1000,
- 'a': 1000
- };
+ return Object.assign(
+ ChessRules.VALUES,
+ { 'a': 1000 }
+ );
}
static GenRandInitFen()
+ "A" + (antikingPos["w"]<7?7-antikingPos["w"]:"");
const ranks23_white = (antikingPos["b"]>0?antikingPos["b"]:"") + "a"
+ (antikingPos["b"]<7?7-antikingPos["b"]:"") + "/PPPPPPPP";
- let fen = pieces["b"].join("") + "/" + ranks23_black +
+ return pieces["b"].join("") + "/" + ranks23_black +
"/8/8/" +
ranks23_white + "/" + pieces["w"].join("").toUpperCase() +
- " 1111"; //add flags
- return fen;
+ " w 1111 -";
}
}
+
+const VariantRules = AntikingRules;