X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=client%2Fsrc%2Fvariants%2FChakart.js;h=43bef4b25298bb7b8afae5c2cad949376adb0739;hb=5d75c82c70bcd4bcc43b65571231f0ba1b532b79;hp=5d79f4d0888c5c1b060d982cbc1fdc4a2c69bfe8;hpb=5333b500e6fd9debc9495bb5831974b82c492d33;p=vchess.git diff --git a/client/src/variants/Chakart.js b/client/src/variants/Chakart.js index 5d79f4d0..43bef4b2 100644 --- a/client/src/variants/Chakart.js +++ b/client/src/variants/Chakart.js @@ -1,23 +1,53 @@ import { ChessRules } from "@/base_rules"; +import { SuicideRules } from "@/variants/Suicide"; export class ChakartRules extends ChessRules { - // NOTE: getBasicMove, ajouter les bonus à vanish array - // + déterminer leur effet (si cavalier) ou case (si banane ou bombe) - // (L'effet doit être caché au joueur : devrait être OK) - // - // Saut possible par dessus bonus ou champis mais pas bananes ou bombes -//==> redefinir isAttackedBySlide et getPotentialSlide... + static get PawnSpecs() { + return SuicideRules.PawnSpecs; + } + + static get HasCastle() { + return false; + } -// keep track of captured pieces: comme Grand; pieces can get back to board with toadette bonus. -// --> pour ce bonus, passer "capture" temporairement en "reserve" pour permettre de jouer le coup. + static get HasEnpassant() { + // TODO: maybe enable them later, but then the capturing pawn take the + // mushroom and continue diagonally?! + return false; + } - // "pièces" supplémentaires : bananes, bombes, champis, bonus --> + couleur ? - // (Semble mieux sans couleur => couleur spéciale indiquant que c'est pas jouable) - // (Attention: pas jouables cf. getPotentialMoves...) + static get CorrConfirm() { + // Because of bonus effects + return false; + } + + static get CanAnalyze() { + return false; + } hoverHighlight(x, y) { - // TODO: exact squares - return this.subTurn == 2; //&& this.firstMove.donkey or wario or bonus roi boo + if ( + this.firstMove.appear.length == 0 || + this.firstMove.vanish.length == 0 || + this.board[x][y] != V.EMPTY + ) { + return false; + } + const deltaX = Math.abs(this.firstMove.end.x - x); + const deltaY = Math.abs(this.firstMove.end.y - y); + return ( + this.subTurn == 2 && + // Condition: rook or bishop move, may capture, but no bonus move + [V.ROOK, V.BISHOP].includes(this.firstMove.vanish[0].p) && + ( + this.firstMove.vanish.length == 1 || + ['w', 'b'].includes(this.firstMove.vanish[1].c) + ) && + ( + this.firstMove.vanish[0].p == V.ROOK && deltaX == 1 && deltaY == 1 || + this.firstMove.vanish[0].p == V.BISHOP && deltaX + deltaY == 1 + ) + ); } static get IMMOBILIZE_CODE() { @@ -46,9 +76,33 @@ export class ChakartRules extends ChessRules { return 'i'; } + // Fictive color 'a', bomb banana mushroom egg + static get BOMB() { + // Doesn't collide with bishop because color 'a' + return 'b'; + } + static get BANANA() { + return 'n'; + } + static get EGG() { + return 'e'; + } + static get MUSHROOM() { + return 'm'; + } + + static get PIECES() { + return ( + ChessRules.PIECES.concat( + Object.keys(V.IMMOBILIZE_DECODE)).concat( + [V.BANANA, V.BOMB, V.EGG, V.MUSHROOM, V.INVISIBLE_QUEEN]) + ); + } + getPpath(b) { let prefix = ""; if ( + b[0] == 'a' || b[1] == V.INVISIBLE_QUEEN || Object.keys(V.IMMOBILIZE_DECODE).includes(b[1]) ) { @@ -61,7 +115,7 @@ export class ChakartRules extends ChessRules { const fenParts = fen.split(" "); return Object.assign( ChessRules.ParseFen(fen), - { captured: fenParts[5] } + { captured: fenParts[4] } ); } @@ -90,30 +144,27 @@ export class ChakartRules extends ChessRules { } static IsGoodFlags(flags) { - // 4 for castle + 4 for Peach + Mario w, b - return !!flags.match(/^[a-z]{4,4}[01]{4,4}$/); + // 4 for Peach + Mario w, b + return !!flags.match(/^[01]{4,4}$/); } setFlags(fenflags) { - super.setFlags(fenflags); //castleFlags this.powerFlags = { - w: [...Array(2)], //king can send red shell? Queen can be invisible? + w: [...Array(2)], //king can send shell? Queen can be invisible? b: [...Array(2)] }; - const flags = fenflags.substr(4); //skip first 4 letters, for castle for (let c of ["w", "b"]) { for (let i = 0; i < 2; i++) - this.pawnFlags[c][i] = flags.charAt((c == "w" ? 0 : 2) + i) == "1"; + this.pawnFlags[c][i] = fenFlags.charAt((c == "w" ? 0 : 2) + i) == "1"; } } aggregateFlags() { - return [this.castleFlags, this.powerFlags]; + return this.powerFlags; } disaggregateFlags(flags) { - this.castleFlags = flags[0]; - this.powerFlags = flags[1]; + this.powerFlags = flags; } getFen() { @@ -136,7 +187,6 @@ export class ChakartRules extends ChessRules { } setOtherVariables(fen) { - super.setOtherVariables(fen); const fenParsed = V.ParseFen(fen); // Initialize captured pieces' counts from FEN this.captured = { @@ -159,91 +209,70 @@ export class ChakartRules extends ChessRules { } getFlagsFen() { - let fen = super.getFlagsFen(); + let fen = ""; // Add power flags for (let c of ["w", "b"]) for (let i = 0; i < 2; i++) fen += (this.powerFlags[c][i] ? "1" : "0"); return fen; } - getPotentialMovesFrom([x, y]) { - // TODO: bananes et bombes limitent les déplacements (agissent comme un mur "capturable") - // bananes jaunes et rouges ?! (agissant sur une seule couleur ?) --> mauvaise idée. + getPotentialMovesFrom(sq) { + if (this.subTurn == 1) return super.getPotentialMovesFrom(sq); if (this.subTurn == 2) { // TODO: coup compatible avec firstMove } - //Détails : - //Si une pièce pose quelque chose sur une case ça remplace ce qui y était déjà. - // TODO: un-immobilize my immobilized piece at the end of this turn, if any - } - - getPotentialPawnMoves(sq) { - //Toad: pion - // laisse sur sa case de départ un champi turbo permettant à Peach et cavalier et autres pions d'aller - // un dep plus loin (evt 2 cases si pion saut initial), et aux pièces arrivant sur cette case de sauter par - // dessus une pièce immédiatement adjacente dans leur trajectoire (en atterissant juste derrière). - } - - // Coups en 2 temps (si pose possible) - getPotentialRookMoves(sq) { - //Donkey : tour - // pose une banane (optionnel) sur une case adjacente (diagonale) à celle d'arrivée - // Si une pièce arrive sur la peau de banane, alors elle effectue un déplacement - // aléatoire d'une (2?) case (vertical ou horizontal) depuis sa position finale. - } - - // Coups en 2 temps (si pose) - getPotentialBishopMoves([x, y]) { - //Wario: fou - // pose une bombe (optionnel) sur une case orthogonalement adjacente à la case d'arrivée - // Si une pièce arrive sur une bombe, alors elle effectue un déplacement diagonal - // aléatoire d'une (2?) case depuis sa position finale (juste une case si impossible). - } - - getPotentialKnightMoves([x, y]) { - //Yoshi: cavalier - // laisse sur sa case de départ un bonus aléatoire - // (NOTE: certains bonus pourraient ne pas être applicables ==> pion bloqué par exemple) - // - i) roi boo(*E*) : échange avec n'importe quelle pièce (choix du joueur, type et/ou couleur différents) - // - i*) koopa(*B*) : ramène sur la case initiale - // - ii) toadette(*R*) : permet de poser une pièce capturée sur le plateau - // (n'importe où sauf 8eme rangée pour les pions) - // - ii*) chomp(*W*) : mange la pièce ; si c'est Peach, c'est perdu - // - iii) daisy(*T*) : permet de rejouer un coup avec la même pièce --> cumulable si ensuite coup sur bonus Daisy. - // - iii*) bowser(*M*) : immobilise la pièce (marquée jaune/rouge), qui ne pourra pas jouer au tour suivant - // - iv) luigi(*L*) : fait changer de camp une pièce adverse (aléatoire) (sauf le roi) - // - iv*) waluigi(*D*) : fait changer de camp une de nos pièces (aléatoire, sauf le roi) - // --> i, ii, iii en deux temps (subTurn 1 & 2) - } - - getPotentialQueenMoves(sq) { - //Mario: dame - // pouvoir "fantôme" : peut effectuer une fois dans la partie un coup non-capturant invisible (=> choix à chaque coup, getPPpath(m) teste m.nvisible...) - //wg bg ghost once in the game the queen can make an invisible move --> printed as "?" - } - - getPotentialKingMoves(sq) { - //Peach: roi - // Carapace rouge (disons ^^) jouable une seule fois dans la partie, - // au lieu de se déplacer. Capture un ennemi au choix parmi les plus proches, - // à condition qu'ils soient visibles (suivant les directions de déplacement d'une dame). - // Profite des accélérateurs posés par les pions (+ 1 case : obligatoire). - } - - atLeastOneMove() { - // TODO: check that - return true; } - play(move) { - // TODO: subTurn passe à 2 si arrivée sur bonus cavalier - // potentiellement pose (tour, fou) ou si choix (reconnaître i (ok), ii (ok) et iii (si coup normal + pas immobilisé) ?) - // voire +2 si plusieurs daisy... - // si pièce immobilisée de ma couleur : elle redevient utilisable (changer status fin de play) + getBasicMove([x1, y1], [x2, y2]) { + // Apply mushroom, bomb or banana effect (hidden to the player). + // Determine egg effect, too, and apply its first part if possible. + // add egg + add mushroom for pawns. + let move = super.getBasicMove([x1, y1], [x2, y2]); + // TODO + return move; + // Infer move type based on its effects (used to decide subTurn 1 --> 2) + // --> impossible étant donné juste first part (egg --> effect?) + // => stocker l'effet (i, ii ou iii) dans le coup directement, + // Pas terrible, mais y'aura pas 36 variantes comme ça. Disons end.effect == null, 0, 1, 2 ou 3 + // 0 => tour ou fou, pose potentielle. + // If queen can be invisible, add move same start + end but final type changes + } + + getPotentialKingMoves([x, y]) { + let moves = super.getPotentialKingMoves([x, y]); + // TODO: if flags allows it, add 'remote shell captures' + return moves; + } + + getSlideNJumpMoves([x, y], steps, oneStep) { + let moves = []; + outerLoop: for (let step of steps) { + let i = x + step[0]; + let j = y + 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)) + ) + ) + ) { + moves.push(this.getBasicMove([x, y], [i, j])); + if (oneStep) continue outerLoop; + i += step[0]; + j += step[1]; + } + if (V.OnBoard(i, j) && this.canTake([x, y], [i, j])) + moves.push(this.getBasicMove([x, y], [i, j])); + } + return moves; } - undo(move) { - // TODO: reconnaissance inverse si subTurn == 1 --> juste impossible ==> marquer pendant play (comme DoubleMove1 : move.turn = ...) + getAllPotentialMoves() { + if (this.subTurn == 1) return super.getAllPotentialMoves(); + // TODO: subTurn == 2, switch on firstMove.end.effect --> lack firstMove, setOtherVariables, play/undo, see Dynamo } doClick(square) { @@ -256,7 +285,6 @@ export class ChakartRules extends ChessRules { if (this.subTurn == 2) { if ( this.board[square[0]][square[1]] == V.EMPTY && - !this.underCheck(this.turn) && (La == 0 || !this.oppositeMoves(this.amoves[La-1], this.firstMove[Lf-1])) ) { return { @@ -270,43 +298,76 @@ export class ChakartRules extends ChessRules { return null; } - postPlay(move) { - // TODO: king may also be "chomped" - super.updateCastleFlags(move, piece); + play(move) { + // TODO +// --> pour bonus toadette, passer "capture" temporairement en "reserve" pour permettre de jouer le coup. + // il faut alors mettre à jour 'captured' + // TODO: subTurn passe à 2 si arrivée sur bonus cavalier + effect == 1, 2 ou 3 ou si coup de tour ou fou (non cumulables) } + postPlay(move) { - super.postPlay(move); - if (move.vanish.length == 2 && move.appear.length == 1) + // TODO: if effect = resurect a piece, then this.reserve = this.captured; + if (move.vanish.length == 2 && move.vanish[1].c != 'a') // Capture: update this.captured this.captured[move.vanish[1].c][move.vanish[1].p]++; + else if (move.vanish.length == 0) { + // A piece is back on board + this.captured[move.vanish[1].c][move.vanish[1].p]++; + this.reserve = null; + } + // si pièce immobilisée de ma couleur : elle redevient utilisable (changer status fin de play) + // TODO: un-immobilize my formerly immobilized piece, if any. + // Make invisible queen visible again, if any opponent invisible queen. + } + + undo(move) { + // TODO: should be easy once end.effect is set in getBasicMove() } postUndo(move) { - super.postUndo(move); - if (move.vanish.length == 2 && move.appear.length == 1) + if (move.vanish.length == 2 && move.vanish[1].c != 'a') this.captured[move.vanish[1].c][move.vanish[1].p]--; } + getCheckSquares() { + return []; + } + getCurrentScore() { - if (this.kingPos[this.turn][0] < 0) - // King captured (or "chomped") - return this.turn == "w" ? "0-1" : "1-0"; - return '*'; + // Find kings (not tracked in this variant) + let kingThere = { w: false, b: false }; + for (let i=0; i<8; i++) { + for (let j=0; j<8; j++) { + if (this.board[i][j] != V.EMPTY && this.getPiece(i, j) == V.KING) + kingThere[this.getColor(i, j)] = true; + } + } + if (!kingThere['w']) return "0-1"; + if (!kingThere['b']) return "1-0"; + return "*"; } static GenRandInitFen(randomness) { return ( - ChessRules.GenRandInitFen(randomness).slice(0, -2) + + SuicideRules.GenRandInitFen(randomness).slice(0, -1) + // Add Peach + Mario flags, re-add en-passant + capture counts "0000 - 0000000000" ); } + filterValid(moves) { + return moves; + } + getComputerMove() { + const moves = this.getAllValidMoves(); // TODO: random mover + return moves[0]; } getNotation(move) { + // TODO // invisibility used? --> move notation Q?? + return "?"; } };