class MagneticRules extends ChessRules
{
- getEpSquare(move)
- {
- return undefined; //no en-passant
- }
+ static get HasEnpassant() { return false; }
getPotentialMovesFrom([x,y])
{
// TODO: job is done multiple times for (normal) promotions.
applyMagneticLaws(move)
{
- const V = VariantRules;
if (move.appear[0].p == V.KING && move.appear.length==1)
return [move]; //kings are not charged
const aIdx = (move.appear[0].p != V.KING ? 0 : 1); //if castling, rook is charged
const lastRank = (color=="w" ? 0 : 7);
const standardMove = JSON.parse(JSON.stringify(move));
this.play(standardMove);
- const [sizeX,sizeY] = V.size;
for (let step of [[-1,0],[1,0],[0,-1],[0,1]])
{
let [i,j] = [x+step[0],y+step[1]];
- while (i>=0 && i<sizeX && j>=0 && j<sizeY)
+ while (V.OnBoard(i,j))
{
if (this.board[i][j] != V.EMPTY)
{
{
// Push it until we meet an obstacle or edge of the board
let [ii,jj] = [i+step[0],j+step[1]];
- while (ii>=0 && ii<sizeX && jj>=0 && jj<sizeY)
+ while (V.OnBoard(ii,jj))
{
if (this.board[ii][jj] != V.EMPTY)
break;
return moves;
}
- // TODO: verify this assertion
atLeastOneMove()
{
- return true; //always at least one possible move
+ if (this.kingPos[this.turn][0] < 0)
+ return false;
+ return true; //TODO: is it right?
}
- underCheck(move)
+ underCheck(color)
{
return false; //there is no check
}
getCheckSquares(move)
{
- const c = this.getOppCol(this.turn); //opponent
- const saveKingPos = this.kingPos[c]; //king might be taken
- this.play(move);
- // The only way to be "under check" is to have lost the king (thus game over)
- let res = this.kingPos[c][0] < 0
- ? [ JSON.parse(JSON.stringify(saveKingPos)) ]
- : [ ];
- this.undo(move);
- return res;
+ return [];
}
updateVariables(move)
{
super.updateVariables(move);
- const c = this.getColor(move.start.x,move.start.y);
- if (c != this.getColor(move.end.x,move.end.y)
- && this.board[move.end.x][move.end.y] != VariantRules.EMPTY
- && this.getPiece(move.end.x,move.end.y) == VariantRules.KING)
+ const c = move.vanish[0].c;
+ if (move.vanish.length >= 2 && move.vanish[1].p == V.KING)
{
// We took opponent king !
const oppCol = this.getOppCol(c);
this.kingPos[oppCol] = [-1,-1];
this.castleFlags[oppCol] = [false,false];
}
- // Did we move our (init) rooks or opponents' ones ?
+ // Did we magnetically move our (init) rooks or opponents' ones ?
const firstRank = (c == "w" ? 7 : 0);
const oppFirstRank = 7 - firstRank;
const oppCol = this.getOppCol(c);
unupdateVariables(move)
{
super.unupdateVariables(move);
- const c = this.getColor(move.start.x,move.start.y);
+ const c = move.vanish[0].c;
const oppCol = this.getOppCol(c);
if (this.kingPos[oppCol][0] < 0)
{
}
}
- checkGameOver()
- {
- if (this.checkRepetition())
- return "1/2";
-
- const color = this.turn;
- // TODO: do we need "atLeastOneMove()"?
- if (this.atLeastOneMove() && this.kingPos[color][0] >= 0)
- return "*";
-
- return this.checkGameEnd();
- }
-
checkGameEnd()
{
// No valid move: our king disappeared
return this.turn == "w" ? "0-1" : "1-0";
}
- static get THRESHOLD_MATE() {
+ static get THRESHOLD_MATE()
+ {
return 500; //checkmates evals may be slightly below 1000
}
}
+
+const VariantRules = MagneticRules;