projects
/
vchess.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Implemented and tested DarkChess. Berolina, Upsidedown should be OK. Marseille: TODO
[vchess.git]
/
public
/
javascripts
/
variants
/
Magnetic.js
diff --git
a/public/javascripts/variants/Magnetic.js
b/public/javascripts/variants/Magnetic.js
index
b17bb74
..
1ccc192
100644
(file)
--- a/
public/javascripts/variants/Magnetic.js
+++ b/
public/javascripts/variants/Magnetic.js
@@
-1,9
+1,6
@@
class MagneticRules extends ChessRules
{
class MagneticRules extends ChessRules
{
- getEpSquare(move)
- {
- return undefined; //no en-passant
- }
+ static get HasEnpassant() { return false; }
getPotentialMovesFrom([x,y])
{
getPotentialMovesFrom([x,y])
{
@@
-23,7
+20,6
@@
class MagneticRules extends ChessRules
// TODO: job is done multiple times for (normal) promotions.
applyMagneticLaws(move)
{
// 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
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
@@
-32,11
+28,10
@@
class MagneticRules extends ChessRules
const lastRank = (color=="w" ? 0 : 7);
const standardMove = JSON.parse(JSON.stringify(move));
this.play(standardMove);
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]];
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)
{
{
if (this.board[i][j] != V.EMPTY)
{
@@
-71,7
+66,7
@@
class MagneticRules extends ChessRules
{
// Push it until we meet an obstacle or edge of the board
let [ii,jj] = [i+step[0],j+step[1]];
{
// 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;
{
if (this.board[ii][jj] != V.EMPTY)
break;
@@
-137,10
+132,11
@@
class MagneticRules extends ChessRules
return moves;
}
return moves;
}
- // TODO: verify this assertion
atLeastOneMove()
{
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(move)
@@
-155,8
+151,8
@@
class MagneticRules extends ChessRules
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
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))
]
- : [
];
+ ? [
JSON.parse(JSON.stringify(saveKingPos))
]
+ : [];
this.undo(move);
return res;
}
this.undo(move);
return res;
}
@@
-164,10
+160,8
@@
class MagneticRules extends ChessRules
updateVariables(move)
{
super.updateVariables(move);
updateVariables(move)
{
super.updateVariables(move);
- const c = this.getColor(move.start.x,move.start.y);
- if (this.board[move.end.x][move.end.y] != VariantRules.EMPTY
- && c != this.getColor(move.end.x,move.end.y)
- && 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);
{
// We took opponent king !
const oppCol = this.getOppCol(c);
@@
-189,7
+183,7
@@
class MagneticRules extends ChessRules
unupdateVariables(move)
{
super.unupdateVariables(move);
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)
{
const oppCol = this.getOppCol(c);
if (this.kingPos[oppCol][0] < 0)
{
@@
-205,26
+199,16
@@
class MagneticRules extends ChessRules
}
}
}
}
- 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";
}
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
}
}
return 500; //checkmates evals may be slightly below 1000
}
}
+
+const VariantRules = MagneticRules;