X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=client%2Fsrc%2Fvariants%2FChakart.js;h=f170f707a18995dfdcda33697459b8c61560c284;hb=7c05a5f2297bea540c700ebceb0cc8b03a7f6775;hp=73d7cfc9fe3ac25f98c9f3a0e02a1c39baae6c57;hpb=7c8d0174f68dfcda183848d85588e58f5d347cda;p=vchess.git diff --git a/client/src/variants/Chakart.js b/client/src/variants/Chakart.js index 73d7cfc9..f170f707 100644 --- a/client/src/variants/Chakart.js +++ b/client/src/variants/Chakart.js @@ -4,6 +4,7 @@ import { ArrayFun } from "@/utils/array"; import { randInt } from "@/utils/alea"; export class ChakartRules extends ChessRules { + static get PawnSpecs() { return SuicideRules.PawnSpecs; } @@ -29,7 +30,7 @@ export class ChakartRules extends ChessRules { return true; } - hoverHighlight(x, y) { + hoverHighlight([x, y]) { if (this.subTurn == 1) return false; const L = this.firstMove.length; const fm = this.firstMove[L-1]; @@ -115,8 +116,12 @@ export class ChakartRules extends ChessRules { getPPpath(m) { if (!!m.promoteInto) return m.promoteInto; + if (m.appear.length == 0 && m.vanish.length == 1) + // King 'remote shell capture', on an adjacent square: + return this.getPpath(m.vanish[0].c + m.vanish[0].p); let piece = m.appear[0].p; if (Object.keys(V.IMMOBILIZE_DECODE).includes(piece)) + // Promotion by capture into immobilized piece: do not reveal! piece = V.IMMOBILIZE_DECODE[piece]; return this.getPpath(m.appear[0].c + piece); } @@ -148,7 +153,7 @@ export class ChakartRules extends ChessRules { if (['K', 'k', 'L', 'l'].includes(row[i])) kings[row[i]]++; if (V.PIECES.includes(row[i].toLowerCase())) sumElts++; else { - const num = parseInt(row[i]); + const num = parseInt(row[i], 10); if (isNaN(num)) return false; sumElts += num; } @@ -210,24 +215,25 @@ export class ChakartRules extends ChessRules { setOtherVariables(fen) { super.setOtherVariables(fen); - const fenParsed = V.ParseFen(fen); // Initialize captured pieces' counts from FEN + const captured = + V.ParseFen(fen).captured.split("").map(x => parseInt(x, 10)); this.captured = { w: { - [V.PAWN]: parseInt(fenParsed.captured[0]), - [V.ROOK]: parseInt(fenParsed.captured[1]), - [V.KNIGHT]: parseInt(fenParsed.captured[2]), - [V.BISHOP]: parseInt(fenParsed.captured[3]), - [V.QUEEN]: parseInt(fenParsed.captured[4]), - [V.KING]: parseInt(fenParsed.captured[5]) + [V.PAWN]: captured[0], + [V.ROOK]: captured[1], + [V.KNIGHT]: captured[2], + [V.BISHOP]: captured[3], + [V.QUEEN]: captured[4], + [V.KING]: captured[5] }, b: { - [V.PAWN]: parseInt(fenParsed.captured[6]), - [V.ROOK]: parseInt(fenParsed.captured[7]), - [V.KNIGHT]: parseInt(fenParsed.captured[8]), - [V.BISHOP]: parseInt(fenParsed.captured[9]), - [V.QUEEN]: parseInt(fenParsed.captured[10]), - [V.KING]: parseInt(fenParsed.captured[11]) + [V.PAWN]: captured[6], + [V.ROOK]: captured[7], + [V.KNIGHT]: captured[8], + [V.BISHOP]: captured[9], + [V.QUEEN]: captured[10], + [V.KING]: captured[11] } }; this.firstMove = []; @@ -393,7 +399,7 @@ export class ChakartRules extends ChessRules { return ( V.OnBoard(x + forward, y) && ( - this.board[x + forward][y] != oppCol || + this.board[x + forward][y] == V.EMPTY || ( V.OnBoard(x + forward, y + 1) && this.board[x + forward][y + 1] != V.EMPTY && @@ -944,48 +950,36 @@ export class ChakartRules extends ChessRules { // If flag allows it, add 'remote shell captures' if (this.powerFlags[this.turn][V.KING]) { V.steps[V.ROOK].concat(V.steps[V.BISHOP]).forEach(step => { - const [nextX, nextY] = [x + step[0], y + step[1]]; - if ( - V.OnBoard(nextX, nextY) && + let [i, j] = [x + step[0], y + step[1]]; + while ( + V.OnBoard(i, j) && ( - this.board[nextX][nextY] == V.EMPTY || + this.board[i][j] == V.EMPTY || ( - this.getColor(nextX, nextY) == 'a' && - [V.EGG, V.MUSHROOM].includes(this.getPiece(nextX, nextY)) + this.getColor(i, j) == 'a' && + [V.EGG, V.MUSHROOM].includes(this.getPiece(i, j)) ) ) ) { - let [i, j] = [x + 2 * step[0], y + 2 * step[1]]; - while ( - V.OnBoard(i, j) && - ( - this.board[i][j] == V.EMPTY || - ( - this.getColor(i, j) == 'a' && - [V.EGG, V.MUSHROOM].includes(this.getPiece(i, j)) - ) - ) - ) { - i += step[0]; - j += step[1]; - } - if (V.OnBoard(i, j)) { - const colIJ = this.getColor(i, j); - if (colIJ != color) { - // May just destroy a bomb or banana: - moves.push( - new Move({ - start: { x: x, y: y}, - end: { x: i, y: j }, - appear: [], - vanish: [ - new PiPo({ - x: i, y: j, c: colIJ, p: this.getPiece(i, j) - }) - ] - }) - ); - } + i += step[0]; + j += step[1]; + } + if (V.OnBoard(i, j)) { + const colIJ = this.getColor(i, j); + if (colIJ != color) { + // May just destroy a bomb or banana: + moves.push( + new Move({ + start: { x: x, y: y}, + end: { x: i, y: j }, + appear: [], + vanish: [ + new PiPo({ + x: i, y: j, c: colIJ, p: this.getPiece(i, j) + }) + ] + }) + ); } } }); @@ -1469,4 +1463,5 @@ export class ChakartRules extends ChessRules { } return notation; } + };