return V.ShowMoves;
}
+ // Sometimes moves must remain hidden until game ends
+ static get SomeHiddenMoves() {
+ return false;
+ }
+ get someHiddenMoves() {
+ return V.SomeHiddenMoves;
+ }
+
+ // Generally true, unless the variant includes random effects
+ static get CorrConfirm() {
+ return true;
+ }
+
+ // Used for Monochrome variant (TODO: harmonize: !canFlip ==> showFirstTurn)
+ get showFirstTurn() {
+ return false;
+ }
+
// Some variants always show the same orientation
static get CanFlip() {
return true;
return V.CanFlip;
}
+ // For (generally old) variants without checkered board
+ static get Monochrome() {
+ return false;
+ }
+
+ // Some variants require lines drawing
+ static get Lines() {
+ if (V.Monochrome) {
+ let lines = [];
+ // Draw all inter-squares lines
+ for (let i = 0; i <= V.size.x; i++)
+ lines.push([[i, 0], [i, V.size.y]]);
+ for (let j = 0; j <= V.size.y; j++)
+ lines.push([[0, j], [V.size.x, j]]);
+ return lines;
+ }
+ return null;
+ }
+
// Some variants use click infos:
doClick() {
return null;
}
+ // Some variants may need to highlight squares on hover (Hamilton, Weiqi...)
+ hoverHighlight() {
+ return false;
+ }
+
static get IMAGE_EXTENSION() {
// All pieces should be in the SVG format
return ".svg";
}
// On which squares is color under check ? (for interface)
- getCheckSquares(color) {
+ getCheckSquares() {
+ const color = this.turn;
return (
this.underCheck(color)
// kingPos must be duplicated, because it may change:
return;
const fenParsed = V.ParseFen(fen);
this.board = V.GetBoard(fenParsed.position);
- this.turn = fenParsed.turn[0]; //[0] to work with MarseilleRules
+ this.turn = fenParsed.turn;
this.movesCount = parseInt(fenParsed.movesCount);
this.setOtherVariables(fen);
}
// Consider all potential promotions:
addPawnMoves([x1, y1], [x2, y2], moves, promotions) {
let finalPieces = [V.PAWN];
- const color = this.turn;
+ const color = this.turn; //this.getColor(x1, y1);
const lastRank = (color == "w" ? 0 : V.size.x - 1);
if (x2 == lastRank) {
// promotions arg: special override for Hiddenqueen variant
if (!!promotions) finalPieces = promotions;
- else if (!!V.PawnSpecs.promotions)
- finalPieces = V.PawnSpecs.promotions;
+ else if (!!V.PawnSpecs.promotions) finalPieces = V.PawnSpecs.promotions;
}
let tr = null;
for (let piece of finalPieces) {
// What are the pawn moves from square x,y ?
getPotentialPawnMoves([x, y], promotions) {
- const color = this.turn;
+ const color = this.turn; //this.getColor(x, y);
const [sizeX, sizeY] = [V.size.x, V.size.y];
const pawnShiftX = V.PawnSpecs.directions[color];
const firstRank = (color == "w" ? sizeX - 1 : 0);
+ const forward = (color == 'w' ? -1 : 1);
// Pawn movements in shiftX direction:
const getPawnMoves = (shiftX) => {
// NOTE: next condition is generally true (no pawn on last rank)
if (x + shiftX >= 0 && x + shiftX < sizeX) {
if (this.board[x + shiftX][y] == V.EMPTY) {
- // One square forward
+ // One square forward (or backward)
this.addPawnMoves([x, y], [x + shiftX, y], moves, promotions);
// Next condition because pawns on 1st rank can generally jump
if (
(color == 'b' && x <= V.PawnSpecs.initShift['b'])
)
) {
- if (this.board[x + 2 * shiftX][y] == V.EMPTY) {
+ if (
+ shiftX == forward &&
+ this.board[x + 2 * shiftX][y] == V.EMPTY
+ ) {
// Two squares jump
moves.push(this.getBasicMove([x, y], [x + 2 * shiftX, y]));
if (
// Captures
if (V.PawnSpecs.canCapture) {
for (let shiftY of [-1, 1]) {
- if (
- y + shiftY >= 0 &&
- y + shiftY < sizeY
- ) {
+ if (y + shiftY >= 0 && y + shiftY < sizeY) {
if (
this.board[x + shiftX][y + shiftY] != V.EMPTY &&
this.canTake([x, y], [x + shiftX, y + shiftY])
);
}
if (
- V.PawnSpecs.captureBackward &&
+ V.PawnSpecs.captureBackward && shiftX == forward &&
x - shiftX >= 0 && x - shiftX < V.size.x &&
this.board[x - shiftX][y + shiftY] != V.EMPTY &&
this.canTake([x, y], [x - shiftX, y + shiftY])
) {
this.addPawnMoves(
- [x, y], [x + shiftX, y + shiftY],
+ [x, y], [x - shiftX, y + shiftY],
moves, promotions
);
}
if (
// NOTE: "castling" arg is used by some variants (Monster),
// where "isAttacked" is overloaded in an infinite-recursive way.
+ // TODO: not used anymore (Monster + Doublemove2 are simplified).
(!castleInCheck && this.isAttacked([x, i], oppCol, "castling")) ||
(this.board[x][i] != V.EMPTY &&
// NOTE: next check is enough, because of chessboard constraints
let potentialMoves = [];
for (let i = 0; i < V.size.x; i++) {
for (let j = 0; j < V.size.y; j++) {
- if (this.getColor(i, j) == color) {
+ if (this.board[i][j] != V.EMPTY && this.getColor(i, j) == color) {
Array.prototype.push.apply(
potentialMoves,
this.getPotentialMovesFrom([i, j])
const color = this.turn;
for (let i = 0; i < V.size.x; i++) {
for (let j = 0; j < V.size.y; j++) {
- if (this.getColor(i, j) == color) {
+ if (this.board[i][j] != V.EMPTY && this.getColor(i, j) == color) {
const moves = this.getPotentialMovesFrom([i, j]);
if (moves.length > 0) {
- for (let k = 0; k < moves.length; k++) {
+ for (let k = 0; k < moves.length; k++)
if (this.filterValid([moves[k]]).length > 0) return true;
- }
}
}
}
}
// Is square x,y attacked by 'color' pawns ?
- isAttackedByPawn([x, y], color) {
+ isAttackedByPawn(sq, color) {
const pawnShift = (color == "w" ? 1 : -1);
- if (x + pawnShift >= 0 && x + pawnShift < V.size.x) {
- for (let i of [-1, 1]) {
- if (
- y + i >= 0 &&
- y + i < V.size.y &&
- this.getPiece(x + pawnShift, y + i) == V.PAWN &&
- this.getColor(x + pawnShift, y + i) == color
- ) {
- return true;
- }
- }
- }
- return false;
+ return this.isAttackedBySlideNJump(
+ sq,
+ color,
+ V.PAWN,
+ [[pawnShift, 1], [pawnShift, -1]],
+ "oneStep"
+ );
}
// Is square x,y attacked by 'color' rooks ?
piece = move.appear[0].p;
// Update king position + flags
- if (piece == V.KING && move.appear.length > 0) {
- this.kingPos[c][0] = move.appear[0].x;
- this.kingPos[c][1] = move.appear[0].y;
- }
+ if (piece == V.KING && move.appear.length > 0)
+ this.kingPos[c] = [move.appear[0].x, move.appear[0].y];
if (V.HasCastle) this.updateCastleFlags(move, piece);
}
return 3;
}
- getComputerMove() {
+ // 'movesList' arg for some variants to provide a custom list
+ getComputerMove(movesList) {
const maxeval = V.INFINITY;
const color = this.turn;
- let moves1 = this.getAllValidMoves();
+ let moves1 = movesList || this.getAllValidMoves();
if (moves1.length == 0)
// TODO: this situation should not happen