-export const VariantRules = class LosersRules extends ChessRules
-{
- static get HasFlags() { return false; }
-
- getPotentialPawnMoves([x,y])
- {
- let moves = super.getPotentialPawnMoves([x,y]);
-
- // Complete with promotion(s) into king, if possible
- const color = this.turn;
- const shift = (color == "w" ? -1 : 1);
- const lastRank = (color == "w" ? 0 : V.size.x-1);
- if (x+shift == lastRank)
- {
- // Normal move
- if (this.board[x+shift][y] == V.EMPTY)
- moves.push(this.getBasicMove([x,y], [x+shift,y], {c:color,p:V.KING}));
- // Captures
- if (y>0 && this.canTake([x,y], [x+shift,y-1])
- && this.board[x+shift][y-1] != V.EMPTY)
- {
- moves.push(this.getBasicMove([x,y], [x+shift,y-1], {c:color,p:V.KING}));
- }
- if (y<V.size.y-1 && this.canTake([x,y], [x+shift,y+1])
- && this.board[x+shift][y+1] != V.EMPTY)
- {
- moves.push(this.getBasicMove([x,y], [x+shift,y+1], {c:color,p:V.KING}));
- }
- }
-
- return moves;
- }
-
- getPotentialKingMoves(sq)
- {
- // No castle:
- return this.getSlideNJumpMoves(sq,
- V.steps[V.ROOK].concat(V.steps[V.BISHOP]), "oneStep");
- }
-
- // Stop at the first capture found (if any)
- atLeastOneCapture()
- {
- const color = this.turn;
- const oppCol = V.GetOppCol(color);
- for (let i=0; i<V.size.x; i++)
- {
- for (let j=0; j<V.size.y; j++)
- {
- if (this.board[i][j] != V.EMPTY && this.getColor(i,j) != oppCol)
- {
- const moves = this.getPotentialMovesFrom([i,j]);
- if (moves.length > 0)
- {
- for (let k=0; k<moves.length; k++)
- {
- if (moves[k].vanish.length==2 && this.filterValid([moves[k]]).length > 0)
- return true;
- }
- }
- }
- }
- }
- return false;
- }
-
- // Trim all non-capturing moves
- static KeepCaptures(moves)
- {
- return moves.filter(m => { return m.vanish.length == 2; });
- }
-
- getPossibleMovesFrom(sq)
- {
- let moves = this.filterValid( this.getPotentialMovesFrom(sq) );
- // This is called from interface: we need to know if a capture is possible
- if (this.atLeastOneCapture())
- moves = V.KeepCaptures(moves);
- return moves;
- }
-
- getAllValidMoves()
- {
- let moves = super.getAllValidMoves();
- if (moves.some(m => { return m.vanish.length == 2; }))
- moves = V.KeepCaptures(moves);
- return moves;
- }
-
- underCheck(color)
- {
- return false; //No notion of check
- }
-
- getCheckSquares(move)
- {
- return [];
- }
-
- // No variables update because no royal king + no castling
- updateVariables(move) { }
- unupdateVariables(move) { }
-
- getCurrentScore()
- {
- if (this.atLeastOneMove()) // game not over
+export const VariantRules = class LosersRules extends ChessRules {
+ static get HasFlags() {
+ return false;
+ }
+
+ getPotentialPawnMoves([x, y]) {
+ let moves = super.getPotentialPawnMoves([x, y]);
+
+ // Complete with promotion(s) into king, if possible
+ const color = this.turn;
+ const shift = color == "w" ? -1 : 1;
+ const lastRank = color == "w" ? 0 : V.size.x - 1;
+ if (x + shift == lastRank) {
+ // Normal move
+ if (this.board[x + shift][y] == V.EMPTY)
+ moves.push(
+ this.getBasicMove([x, y], [x + shift, y], { c: color, p: V.KING })
+ );
+ // Captures
+ if (
+ y > 0 &&
+ this.canTake([x, y], [x + shift, y - 1]) &&
+ this.board[x + shift][y - 1] != V.EMPTY
+ ) {
+ moves.push(
+ this.getBasicMove([x, y], [x + shift, y - 1], { c: color, p: V.KING })
+ );
+ }
+ if (
+ y < V.size.y - 1 &&
+ this.canTake([x, y], [x + shift, y + 1]) &&
+ this.board[x + shift][y + 1] != V.EMPTY
+ ) {
+ moves.push(
+ this.getBasicMove([x, y], [x + shift, y + 1], { c: color, p: V.KING })
+ );
+ }
+ }
+
+ return moves;
+ }
+
+ getPotentialKingMoves(sq) {
+ // No castle:
+ return this.getSlideNJumpMoves(
+ sq,
+ V.steps[V.ROOK].concat(V.steps[V.BISHOP]),
+ "oneStep"
+ );
+ }
+
+ // Stop at the first capture found (if any)
+ atLeastOneCapture() {
+ const color = this.turn;
+ const oppCol = V.GetOppCol(color);
+ for (let i = 0; i < V.size.x; i++) {
+ for (let j = 0; j < V.size.y; j++) {
+ if (this.board[i][j] != V.EMPTY && this.getColor(i, j) != oppCol) {
+ const moves = this.getPotentialMovesFrom([i, j]);
+ if (moves.length > 0) {
+ for (let k = 0; k < moves.length; k++) {
+ if (
+ moves[k].vanish.length == 2 &&
+ this.filterValid([moves[k]]).length > 0
+ )
+ return true;
+ }
+ }
+ }
+ }
+ }
+ return false;
+ }
+
+ // Trim all non-capturing moves
+ static KeepCaptures(moves) {
+ return moves.filter(m => {
+ return m.vanish.length == 2;
+ });
+ }
+
+ getPossibleMovesFrom(sq) {
+ let moves = this.filterValid(this.getPotentialMovesFrom(sq));
+ // This is called from interface: we need to know if a capture is possible
+ if (this.atLeastOneCapture()) moves = V.KeepCaptures(moves);
+ return moves;
+ }
+
+ getAllValidMoves() {
+ let moves = super.getAllValidMoves();
+ if (
+ moves.some(m => {
+ return m.vanish.length == 2;
+ })
+ )
+ moves = V.KeepCaptures(moves);
+ return moves;
+ }
+
+ underCheck() {
+ return false; //No notion of check
+ }
+
+ getCheckSquares() {
+ return [];
+ }
+
+ // No variables update because no royal king + no castling
+ updateVariables() {}
+ unupdateVariables() {}
+
+ getCurrentScore() {
+ if (this.atLeastOneMove())
+ // game not over