class CheckeredRules extends ChessRules
{
- // Path to pieces
static getPpath(b)
{
return b[0]=='c' ? "Checkered/"+b : b;
getPotentialMovesFrom([x,y])
{
let standardMoves = super.getPotentialMovesFrom([x,y]);
+ const lastRank = this.turn == "w" ? 0 : 7;
if (this.getPiece(x,y) == VariantRules.KING)
return standardMoves; //king has to be treated differently (for castles)
let moves = [];
{
// A capture occured (m.vanish.length == 2)
m.appear[0].c = "c";
- moves.push(JSON.parse(JSON.stringify(m)));
- if (m.appear[0].p != m.vanish[1].p)
+ moves.push(m);
+ if (m.appear[0].p != m.vanish[1].p //avoid promotions (already treated):
+ && (m.vanish[0].p != VariantRules.PAWN || m.end.x != lastRank))
{
// Add transformation into captured piece
let m2 = JSON.parse(JSON.stringify(m));
- m2.vanish[1].p = m.appear[0].p;
+ m2.appear[0].p = m.vanish[1].p;
moves.push(m2);
}
}
canIplay(side, [x,y])
{
- return ((side=='w' && this.moves.length%2==0) || (side=='b' && this.moves.length%2==1))
+ return ((side=='w' && this.moves.length%2==0)
+ || (side=='b' && this.moves.length%2==1))
&& [side,'c'].includes(this.getColor(x,y));
}
this.play(move);
const color = this.turn;
this.moves.push(move); //artifically change turn, for checkered pawns (TODO)
- const kingAttacked = this.isAttacked(this.kingPos[color], [this.getOppCol(color),'c']);
+ const kingAttacked = this.isAttacked(
+ this.kingPos[color], [this.getOppCol(color),'c']);
let res = kingAttacked
? [ JSON.parse(JSON.stringify(this.kingPos[color])) ] //need to duplicate!
: [ ];
checkGameEnd()
{
const color = this.turn;
- if (!this.isAttacked(this.kingPos[color], this.getOppCol(color))
- && !this.isAttacked(this.kingPos[color], 'c'))
- {
- return "1/2";
- }
- // OK, checkmate
- return color == "w" ? "0-1" : "1-0";
+ this.moves.length++; //artifically change turn, for checkered pawns (TODO)
+ const res = this.isAttacked(this.kingPos[color], [this.getOppCol(color),'c'])
+ ? (color == "w" ? "0-1" : "1-0")
+ : "1/2";
+ this.moves.length--;
+ return res;
}
evalPosition()
{
// Capture
let startColumn = String.fromCharCode(97 + move.start.y);
- notation = startColumn + "x" + finalSquare + "=" + move.appear[0].p.toUpperCase();
+ notation = startColumn + "x" + finalSquare +
+ "=" + move.appear[0].p.toUpperCase();
}
else //no capture
+ {
notation = finalSquare;
- if (move.appear.length > 0 && piece != move.appear[0].p) //promotion
- notation += "=" + move.appear[0].p.toUpperCase();
+ if (move.appear.length > 0 && piece != move.appear[0].p) //promotion
+ notation += "=" + move.appear[0].p.toUpperCase();
+ }
return notation;
}