X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=client%2Fsrc%2Fvariants%2FCannibal.js;h=1d8469e2419be18c51c9a63bc5ecee03bbb03784;hb=7e8a7ea1cb66adb4a987badfb0a3c2f99a21bd0a;hp=b66ac3827478457f81609f67531c3acbe2c807a7;hpb=305ede7ec3753fc669b7c86af5b5c5b2fc78a164;p=vchess.git diff --git a/client/src/variants/Cannibal.js b/client/src/variants/Cannibal.js index b66ac382..1d8469e2 100644 --- a/client/src/variants/Cannibal.js +++ b/client/src/variants/Cannibal.js @@ -1,6 +1,7 @@ import { ChessRules, Move, PiPo } from "@/base_rules"; export class CannibalRules extends ChessRules { + static get KING_CODE() { return { 'p': 's', @@ -49,7 +50,7 @@ export class CannibalRules extends ChessRules { else if (kingWhiteCodes.includes(row[i])) kings['w']++; if (allPiecesCodes.includes(row[i].toLowerCase())) sumElts++; else { - const num = parseInt(row[i]); + const num = parseInt(row[i], 10); if (isNaN(num)) return false; sumElts += num; } @@ -74,7 +75,7 @@ export class CannibalRules extends ChessRules { const color = (piece.charCodeAt(0) <= 90 ? 'w' : 'b'); this.kingPos[color] = [i, k]; } else { - const num = parseInt(rows[i].charAt(j)); + const num = parseInt(rows[i].charAt(j), 10); if (!isNaN(num)) k += num - 1; } k++; @@ -88,7 +89,7 @@ export class CannibalRules extends ChessRules { return moves.filter(m => m.vanish.length == 2 && m.appear.length == 1); } - // Stop at the first capture found (if any) + // Stop at the first capture found (if any) atLeastOneCapture() { const color = this.turn; const oppCol = V.GetOppCol(color); @@ -207,8 +208,9 @@ export class CannibalRules extends ChessRules { this.kingPos[c][0] = move.appear[0].x; this.kingPos[c][1] = move.appear[0].y; this.castleFlags[c] = [V.size.y, V.size.y]; - return; } + // Next call is still required because the king may eat an opponent's rook + // TODO: castleFlags will be turned off twice then. super.updateCastleFlags(move, piece); } @@ -231,10 +233,6 @@ export class CannibalRules extends ChessRules { }; } - static get SEARCH_DEPTH() { - return 4; - } - getNotation(move) { let notation = super.getNotation(move); const lastRank = (move.appear[0].c == "w" ? 0 : 7); @@ -249,4 +247,5 @@ export class CannibalRules extends ChessRules { } return notation; } + };