import { ChessRules } from "@/base_rules";
export class MonochromeRules extends ChessRules {
+
static get HasEnpassant() {
// Pawns would be on the same side
return false;
}
+ static get HasFlags() {
+ return false;
+ }
+
static get Lines() {
return [ [[4, 0], [4, 8]] ];
}
return true;
}
+ getPpath(b) {
+ return (b[1] == V.KNIGHT ? "Enpassant/" : "") + b;
+ }
+
canIplay(side, [x, y]) {
const xBounds = side == 'w' ? [4,7] : [0,3];
return this.turn == side && x >= xBounds[0] && x <= xBounds[1];
// Trim all non-capturing moves
static KeepCaptures(moves) {
- return moves.filter(m => m.vanish.length == 2 && m.appear.length == 1);
+ return moves.filter(m => m.vanish.length == 2);
+ }
+
+ getPotentialKnightMoves(sq) {
+ // Knight becomes knightrider:
+ return this.getSlideNJumpMoves(sq, V.steps[V.KNIGHT]);
+ }
+
+ getPotentialKingMoves(sq) {
+ // King become queen:
+ return (
+ this.getSlideNJumpMoves(sq, V.steps[V.ROOK].concat(V.steps[V.BISHOP]))
+ );
}
getAllPotentialMoves() {
for (let j = 0; j < V.size.y; j++) {
if (
this.board[i][j] != V.EMPTY &&
- this.getPotentialMovesFrom([i, j]).some(m =>
- // Warning: discard castle moves
- m.vanish.length == 2 && m.appear.length == 1)
+ this.getPotentialMovesFrom([i, j]).some(m => m.vanish.length == 2)
) {
return true;
}
}
getCurrentScore() {
- // Is there anything in my half board?
+ // Is there anything in opponent's half board?
const color = V.GetOppCol(this.turn);
const xBounds = color == 'w' ? [4,7] : [0,3];
let nothingHere = true;
}
static GenRandInitFen(randomness) {
- // Remove the en-passant part of the FEN
- const fen = ChessRules.GenRandInitFen(randomness).slice(0, -2);
+ // Remove the en-passant + castle part of the FEN
+ let fen = ChessRules.GenRandInitFen(randomness).slice(0, -6);
+ // Replace kings with queens
+ fen = fen.replace("k", "q").replace("K", "Q");
+ // Move pawns up:
+ fen = fen.replace("pppppppp/8","8/pppppppp")
+ .replace("8/PPPPPPPP","PPPPPPPP/8");
const firstSpace = fen.indexOf(' ');
- return (
+ // Paint it black:
+ fen =
fen.substr(0, firstSpace).replace(/[A-Z]/g, (c) => c.toLowerCase()) +
- fen.substr(firstSpace)
- );
+ fen.substr(firstSpace);
+ return fen;
}
static get SEARCH_DEPTH() {
}
return evaluation;
}
+
+ getNotation(move) {
+ // Translate initial square (because pieces may fly unusually!)
+ const initialSquare = V.CoordsToSquare(move.start);
+
+ // Translate final square
+ const finalSquare = V.CoordsToSquare(move.end);
+
+ let notation = "";
+ const piece = this.getPiece(move.start.x, move.start.y);
+ if (piece == V.PAWN) {
+ // pawn move (TODO: enPassant indication)
+ if (move.vanish.length == 2) {
+ // capture
+ notation = initialSquare + "x" + finalSquare;
+ }
+ else notation = finalSquare;
+ if (piece != move.appear[0].p)
+ //promotion
+ notation += "=" + move.appear[0].p.toUpperCase();
+ }
+ else {
+ // Piece movement
+ notation = piece.toUpperCase();
+ if (move.vanish.length > 1) notation += initialSquare + "x";
+ notation += finalSquare;
+ }
+ return notation;
+ }
+
};