X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=client%2Fsrc%2Fbase_rules.js;h=69549525408d51fa349cac05fb2254db758c216b;hb=4a2093139089632727de4f510127ef186cab528e;hp=2c2b705c4c71b90fc052d1018d3a68c80125ca52;hpb=9a1e3abe33fff07218b17c7c799eb622a730b7c7;p=vchess.git diff --git a/client/src/base_rules.js b/client/src/base_rules.js index 2c2b705c..69549525 100644 --- a/client/src/base_rules.js +++ b/client/src/base_rules.js @@ -112,6 +112,11 @@ export const ChessRules = class ChessRules { return false; } + // Some games are drawn unusually (bottom right corner is black) + static get DarkBottomRight() { + return false; + } + // Some variants require lines drawing static get Lines() { if (V.Monochrome) { @@ -192,7 +197,7 @@ export const ChessRules = class ChessRules { if (V.PIECES.includes(row[i].toLowerCase())) sumElts++; else { const num = parseInt(row[i], 10); - if (isNaN(num)) return false; + if (isNaN(num) || num <= 0) return false; sumElts += num; } } @@ -270,7 +275,7 @@ export const ChessRules = class ChessRules { // En-passant square, if any getEpSquare(moveOrSquare) { - if (!moveOrSquare) return undefined; + if (!moveOrSquare) return undefined; //TODO: necessary line?! if (typeof moveOrSquare === "string") { const square = moveOrSquare; if (square == "-") return undefined; @@ -648,20 +653,14 @@ export const ChessRules = class ChessRules { // MOVES GENERATION // All possible moves from selected square - getPotentialMovesFrom([x, y]) { - switch (this.getPiece(x, y)) { - case V.PAWN: - return this.getPotentialPawnMoves([x, y]); - case V.ROOK: - return this.getPotentialRookMoves([x, y]); - case V.KNIGHT: - return this.getPotentialKnightMoves([x, y]); - case V.BISHOP: - return this.getPotentialBishopMoves([x, y]); - case V.QUEEN: - return this.getPotentialQueenMoves([x, y]); - case V.KING: - return this.getPotentialKingMoves([x, y]); + getPotentialMovesFrom(sq) { + switch (this.getPiece(sq[0], sq[1])) { + case V.PAWN: return this.getPotentialPawnMoves(sq); + case V.ROOK: return this.getPotentialRookMoves(sq); + case V.KNIGHT: return this.getPotentialKnightMoves(sq); + case V.BISHOP: return this.getPotentialBishopMoves(sq); + case V.QUEEN: return this.getPotentialQueenMoves(sq); + case V.KING: return this.getPotentialKingMoves(sq); } return []; //never reached } @@ -676,8 +675,8 @@ export const ChessRules = class ChessRules { new PiPo({ x: ex, y: ey, - c: tr ? tr.c : initColor, - p: tr ? tr.p : initPiece + c: !!tr ? tr.c : initColor, + p: !!tr ? tr.p : initPiece }) ], vanish: [ @@ -1072,8 +1071,10 @@ export const ChessRules = class ChessRules { } if ( V.OnBoard(rx, ry) && + this.board[rx][ry] != V.EMPTY && this.getPiece(rx, ry) == piece && - this.getColor(rx, ry) == color + this.getColor(rx, ry) == color && + this.canTake([rx, ry], [x, y]) ) { return true; }