From: Benjamin Auder Date: Wed, 10 Mar 2021 19:38:10 +0000 (+0100) Subject: Adjust Chakart rules X-Git-Url: https://git.auder.net/variants/current/doc/css/assets/pieces/config.php?a=commitdiff_plain;h=54879803f060e8243291735d02181f350c4dfe78;p=vchess.git Adjust Chakart rules --- diff --git a/client/src/translations/rules/Chakart/en.pug b/client/src/translations/rules/Chakart/en.pug index a89d4ae9..fbfc4eb8 100644 --- a/client/src/translations/rules/Chakart/en.pug +++ b/client/src/translations/rules/Chakart/en.pug @@ -79,8 +79,8 @@ p. first the positive, then the negative. ul li. - King Boo (*B) let you exchange the position of the playing piece with any - of the pieces of the board. + King Boo (*B) let you exchange the position of one of your pieces with + any of the pieces of the board. li Koopa (*K) drives the piece back onto its initial square. li. Toadette (*T) allows to place a captured piece on the board (on an empty @@ -89,7 +89,7 @@ ul li. Chomp (*C) eats the piece, which is thus captured. If it's Peach, then you have lost :) - li Daisy (*D) allows to play again with the same piece. + li Daisy (*D) allows to play again with any of your pieces. li. Bowser (*M) immobilizes the piece (which turns into yellow or red). It won't be allowed to move on next turn. diff --git a/client/src/translations/rules/Chakart/es.pug b/client/src/translations/rules/Chakart/es.pug index 378edce7..fedc2743 100644 --- a/client/src/translations/rules/Chakart/es.pug +++ b/client/src/translations/rules/Chakart/es.pug @@ -86,8 +86,8 @@ p. entonces lo negativo. ul li. - Rey Boo (*B) te permite cambiar la posición de la pieza que jugó con - cualquier otro en el tablero. + Rey Boo (*B) te permite cambiar la posición de cualquier de tus piezas + con cualquier otra en el tablero. li Koopa (*K) devuelve la pieza a su casilla original. li. Toadette (*T) le permite reemplazar una pieza capturada en cualquier lugar @@ -96,7 +96,7 @@ ul li. Chomp (*C) se come la pieza, que termina capturada. Si es Peach, pues perdiste :) - li Daisy (*D) te permite reproducir un movimiento con la misma pieza. + li Daisy (*D) te permite reproducir un movimiento con cualquier pieza. li. Bowser (*M) inmoviliza la pieza (que se vuelve amarilla o roja). Ella no podrá jugar la próxima ronda. diff --git a/client/src/translations/rules/Chakart/fr.pug b/client/src/translations/rules/Chakart/fr.pug index ee04216a..92e00ede 100644 --- a/client/src/translations/rules/Chakart/fr.pug +++ b/client/src/translations/rules/Chakart/fr.pug @@ -83,8 +83,8 @@ p. puis le négatif. ul li. - Le Roi Boo (*B) permet d'échanger la position de la pièce ayant joué avec - n'importe quelle autre sur le plateau. + Le Roi Boo (*B) permet d'échanger la position d'une de vos pièces avec + n'importe quelle autre pièce sur le plateau. li Koopa (*K) ramène la pièce sur sa case initiale. li. Toadette (*T) permet de replacer une pièce capturée n'importe où sur le @@ -93,7 +93,7 @@ ul li. Chomp (*C) mange la pièce, qui se retrouve capturée. Si c'est Peach, et bien vous avez perdu :) - li Daisy (*D) permet de rejouer un coup avec la même pièce. + li Daisy (*D) permet de rejouer un coup avec une de vos pièces. li. Bowser (*M) immobilise la pièce (qui passe en jaune ou rouge). Celle-ci ne pourra pas jouer au tour suivant. diff --git a/client/src/variants/Chakart.js b/client/src/variants/Chakart.js index 5f20132e..14e64b5c 100644 --- a/client/src/variants/Chakart.js +++ b/client/src/variants/Chakart.js @@ -30,22 +30,6 @@ export class ChakartRules extends ChessRules { return true; } - hoverHighlight([x, y]) { - if (this.subTurn == 1) return false; - const L = this.firstMove.length; - const fm = this.firstMove[L-1]; - if (fm.end.effect != 0) return false; - const deltaX = Math.abs(fm.appear[0].x - x); - const deltaY = Math.abs(fm.appear[0].y - y); - return ( - (this.board[x][y] == V.EMPTY || this.getColor(x, y) == 'a') && - ( - (fm.vanish[0].p == V.ROOK && deltaX == 1 && deltaY == 1) || - (fm.vanish[0].p == V.BISHOP && deltaX + deltaY == 1) - ) - ); - } - static get IMMOBILIZE_CODE() { return { 'p': 's', @@ -236,7 +220,7 @@ export class ChakartRules extends ChessRules { [V.KING]: captured[11] } }; - this.firstMove = []; + this.effects = []; this.subTurn = 1; } @@ -323,9 +307,8 @@ export class ChakartRules extends ChessRules { } else { // Subturn == 2 - const L = this.firstMove.length; - const fm = this.firstMove[L-1]; - switch (fm.end.effect) { + const L = this.effects.length; + switch (this.effects[L-1]) { case "kingboo": // Exchange position with any piece, // except pawns if arriving on last rank. @@ -364,9 +347,8 @@ export class ChakartRules extends ChessRules { if (x >= V.size.x) moves = this.getReserveMoves([x, y]); break; case "daisy": - // Play again with the same piece - if (fm.appear[0].x == x && fm.appear[0].y == y) - moves = super.getPotentialMovesFrom([x, y]); + // Play again with any piece + moves = super.getPotentialMovesFrom([x, y]); break; } } @@ -390,46 +372,6 @@ export class ChakartRules extends ChessRules { return [x + step[0], y + step[1]]; } - canMove([x, y], piece) { - const color = this.getColor(x, y); - const oppCol = V.GetOppCol(color); - piece = piece || this.getPiece(x, y); - if (piece == V.PAWN) { - const forward = (color == 'w' ? -1 : 1); - return ( - V.OnBoard(x + forward, y) && - ( - this.board[x + forward][y] == V.EMPTY || - ( - V.OnBoard(x + forward, y + 1) && - this.board[x + forward][y + 1] != V.EMPTY && - this.getColor[x + forward, y + 1] == oppCol - ) || - ( - V.OnBoard(x + forward, y - 1) && - this.board[x + forward][y - 1] != V.EMPTY && - this.getColor[x + forward, y - 1] == oppCol - ) - ) - ); - } - // Checking one step is enough: - const steps = - [V.KING, V.QUEEN].includes(piece) - ? V.steps[V.ROOK].concat(V.steps[V.BISHOP]) - : V.steps[piece]; - for (let step of steps) { - const [i, j] = [x + step[0], y + step[1]]; - if ( - V.OnBoard(i, j) && - (this.board[i][j] == V.EMPTY || this.getColor(i, j) != color) - ) { - return true; - } - } - return false; - } - // Apply mushroom, bomb or banana effect (hidden to the player). // Determine egg effect, too, and apply its first part if possible. getBasicMove_aux(psq1, sq2, tr, initMove) { @@ -473,11 +415,11 @@ export class ChakartRules extends ChessRules { // The move starts normally, on board: let move = super.getBasicMove([x1, y1], [x2, y2], tr); if (!!tr) move.promoteInto = tr.c + tr.p; //in case of (chomped...) - const L = this.firstMove.length; + const L = this.effects.length; if ( [V.PAWN, V.KNIGHT].includes(piece1) && !!initMove && - (this.subTurn == 1 || this.firstMove[L-1].end.effect == "daisy") + (this.subTurn == 1 || this.effects[L-1] == "daisy") ) { switch (piece1) { case V.PAWN: { @@ -585,27 +527,10 @@ export class ChakartRules extends ChessRules { // No egg effects at subTurn 2 return; // 1) Determine the effect (some may be impossible) - let effects = ["kingboo", "koopa", "chomp", "bowser"]; + let effects = ["kingboo", "koopa", "chomp", "bowser", "daisy"]; if (Object.values(this.captured[color1]).some(c => c >= 1)) effects.push("toadette"); const lastRank = { 'w': 0, 'b': 7 }; - let canPlayAgain = undefined; - if ( - move.appear[0].p == V.PAWN && - move.appear[0].x == lastRank[color1] - ) { - // Always possible: promote into a queen, rook or king - canPlayAgain = true; - } - else { - move.end.effect = "daisy"; - V.PlayOnBoard(this.board, move); - const square = [move.appear[0].x, move.appear[0].y]; - canPlayAgain = this.canMove(square, piece1); - V.UndoOnBoard(this.board, move); - delete move.end["effect"]; - } - if (canPlayAgain) effects.push("daisy"); if ( this.board.some((b,i) => b.some(cell => { @@ -1017,66 +942,40 @@ export class ChakartRules extends ChessRules { getAllPotentialMoves() { if (this.subTurn == 1) return super.getAllPotentialMoves(); let moves = []; - const L = this.firstMove.length; - const fm = this.firstMove[L-1]; - switch (fm.end.effect) { - case 0: - moves.push({ - start: { x: -1, y: -1 }, - end: { x: -1, y: -1 }, - appear: [], - vanish: [] - }); - for ( - let step of - (fm.vanish[0].p == V.ROOK ? V.steps[V.BISHOP] : V.steps[V.ROOK]) - ) { - const [i, j] = [fm.appear[0].x + step[0], fm.appear[0].y + step[1]]; - if ( - V.OnBoard(i, j) && - (this.board[i][j] == V.EMPTY || this.getColor(i, j) == 'a') - ) { - let m = new Move({ - start: { x: -1, y: -1 }, - end: { x: i, y: j }, - appear: [ - new PiPo({ - x: i, - y: j, - c: 'a', - p: (fm.vanish[0].p == V.ROOK ? V.BANANA : V.BOMB) - }) - ], - vanish: [] - }); - if (this.board[i][j] != V.EMPTY) { - m.vanish.push( - new PiPo({ x: i, y: j, c: 'a', p: this.getPiece(i, j) })); - } - moves.push(m); - } - } - break; + const color = this.turn; + const L = this.effects.length; + switch (this.effects[L-1]) { case "kingboo": { - const [x, y] = [fm.appear[0].x, fm.appear[0].y]; + let allPieces = []; for (let i=0; i<8; i++) { for (let j=0; j<8; j++) { const colIJ = this.getColor(i, j); if ( - i != x && - j != y && + i != x && j != y && this.board[i][j] != V.EMPTY && colIJ != 'a' ) { - const movedUnit = new PiPo({ - x: x, - y: y, - c: colIJ, - p: this.getPiece(i, j) + allPieces.push({ x: i, y: j, c: colIJ, p: this.getPiece(i, j) }); + } + } + } + for (let x=0; x<8; x++) { + for (let y=0; y<8; y++) { + if (this.getColor(i, j) == color) { + // Add exchange with something + allPieces.forEach(pp => { + if (pp.x != i || pp.y != j) { + const movedUnit = new PiPo({ + x: x, + y: y, + c: pp.c, + p: pp.p + }); + let mMove = this.getBasicMove({ x: x, y: y }, [pp.x, pp.y]); + mMove.appear.push(movedUnit); + moves.push(mMove); + } }); - let mMove = this.getBasicMove({ x: x, y: y }, [i, j]); - mMove.appear.push(movedUnit); - moves.push(mMove); } } } @@ -1089,68 +988,12 @@ export class ChakartRules extends ChessRules { break; } case "daisy": - moves = super.getPotentialMovesFrom([fm.appear[0].x, fm.appear[0].y]); + moves = super.getAllPotentialMoves(); break; } return moves; } - doClick(square) { - const L = this.firstMove.length; - const fm = (L > 0 ? this.firstMove[L-1] : null); - if ( - isNaN(square[0]) || - this.subTurn == 1 || - !([0, "daisy"].includes(fm.end.effect)) - ) { - return null; - } - const [x, y] = [square[0], square[1]]; - const deltaX = Math.abs(fm.appear[0].x - x); - const deltaY = Math.abs(fm.appear[0].y - y); - if ( - fm.end.effect == 0 && - (this.board[x][y] == V.EMPTY || this.getColor(x, y) == 'a') && - ( - (fm.vanish[0].p == V.ROOK && deltaX == 1 && deltaY == 1) || - (fm.vanish[0].p == V.BISHOP && deltaX + deltaY == 1) - ) - ) { - let m = new Move({ - start: { x: -1, y: -1 }, - end: { x: x, y: y }, - appear: [ - new PiPo({ - x: x, - y: y, - c: 'a', - p: (fm.vanish[0].p == V.ROOK ? V.BANANA : V.BOMB) - }) - ], - vanish: [] - }); - if (this.board[x][y] != V.EMPTY) { - m.vanish.push( - new PiPo({ x: x, y: y, c: 'a', p: this.getPiece(x, y) })); - } - return m; - } - else if ( - fm.end.effect == "daisy" && - deltaX == 0 && deltaY == 0 && - !this.canMove([x, y]) - ) { - // No possible move: return empty move - return { - start: { x: -1, y: -1 }, - end: { x: -1, y: -1 }, - appear: [], - vanish: [] - }; - } - return null; - } - play(move) { // if (!this.states) this.states = []; // const stateFen = this.getFen(); @@ -1159,8 +1002,8 @@ export class ChakartRules extends ChessRules { move.flags = JSON.stringify(this.aggregateFlags()); V.PlayOnBoard(this.board, move); move.turn = [this.turn, this.subTurn]; - if ([0, "kingboo", "toadette", "daisy"].includes(move.end.effect)) { - this.firstMove.push(move); + if (["kingboo", "toadette", "daisy"].includes(move.end.effect)) { + this.effects.push(move.end.effect); this.subTurn = 2; } else { @@ -1239,8 +1082,8 @@ export class ChakartRules extends ChessRules { undo(move) { this.disaggregateFlags(JSON.parse(move.flags)); V.UndoOnBoard(this.board, move); - if ([0, "kingboo", "toadette", "daisy"].includes(move.end.effect)) - this.firstMove.pop(); + if (["kingboo", "toadette", "daisy"].includes(move.end.effect)) + this.effects.pop(); else this.movesCount--; this.turn = move.turn[0]; this.subTurn = move.turn[1]; @@ -1416,7 +1259,7 @@ export class ChakartRules extends ChessRules { move.vanish.every(v => v.c != 'a') ) { // King Boo exchange - return move.vanish[1].p.toUpperCase() + finalSquare; + return V.CoordsToSquare(move.start) + finalSquare; } const piece = move.vanish[0].p; let notation = undefined;