X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=variants%2FChakart%2Fclass.js;h=d6c683dcf3d06c6a8d447c816c90682a9d80c841;hb=be3cb9d1e4dc4f9871cfe662b969f26fda362738;hp=a9f11fb957190a3bbc6cc181a2d08ae959344847;hpb=91339921da57eb47911ac36d159dd408f7752fc3;p=xogo.git diff --git a/variants/Chakart/class.js b/variants/Chakart/class.js index a9f11fb..d6c683d 100644 --- a/variants/Chakart/class.js +++ b/variants/Chakart/class.js @@ -141,11 +141,13 @@ export class ChakartRules extends ChessRules { b: Array.toObject(pieces, allCapts.slice(6, 12)) }; this.reserve = { w: {}, b: {} }; //to be replaced by this.captured - this.effect = ""; + this.moveStack = []; } + // For Toadette bonus getDropMovesFrom([c, p]) { - if (this.reserve[c][p] == 0) return []; + if (typeof c != "string" || this.reserve[c][p] == 0) + return []; let moves = []; const start = (c == 'w' && p == 'p' ? 1 : 0); const end = (color == 'b' && p == 'p' ? 7 : 8); @@ -173,21 +175,67 @@ export class ChakartRules extends ChessRules { return moves; } +// TODO: rethink from here: +// allow pawns + // queen invisible move, king shell: special functions +// prevent pawns from capturing invisible queen (post) +// post-process: +//events : playPlusVisual after mouse up, playReceived (include animation) on opp move +// ==> if move.cont (banana...) self re-call playPlusVisual (rec ?) + // Moving something. Potential effects resolved after playing + getPotentialMovesFrom([x, y], bonus) { + let moves = []; + if (bonus == "toadette") + return this.getDropMovesFrom([x, y]); + else if (bonus == "kingboo") { + // Only allow to swap pieces + // TODO (end of move, as for toadette) + return moves; + } + // Normal case (including bonus daisy) + switch (this.getPiece(x, y)) { + case 'p': + moves = this.getPawnMovesFrom([x, y]); //apply promotions + break; + case 'q': + moves = this.getQueenMovesFrom([x, y]); + break; + case 'k', + moves = this.getKingMoves([x, y]); + break; + default: + moves = super.getPotentialMovesFrom([x, y]); + } + return moves; + } + // idée : on joue le coup, puis son effet est déterminé, puis la suite (si suite) + // est jouée automatiquement ou demande action utilisateur, etc jusqu'à coup terminal. + tryMoveFollowup(move) { + if (this.getColor(move.end.x, move.end.y) == 'a') { + // effect, or bonus/malus + const endType = this.getPiece(m.end.x, m.end.y); + if (endType == V.EGG) + this.applyRandomBonus(m); + else { + this.moveStack.push(m); + switch (endType) { + case V.BANANA: + this.randomRedirect( + case V.BOMB: + case V.MUSHROOM: + // aller dans direction, saut par dessus pièce adverse + // ou amie (tjours), new step si roi caval pion + } + } + } - -// TODO: rethink from here: - - getPotentialMovesFrom([x, y]) { - let moves = []; - if (this.subTurn == 1) { - moves = super.getPotentialMovesFrom([x, y]); const finalPieces = V.PawnSpecs.promotions; const color = this.turn; const lastRank = (color == "w" ? 0 : 7); @@ -269,8 +317,8 @@ export class ChakartRules extends ChessRules { // Helper for getBasicMove(): banana/bomb effect getRandomSquare([x, y], steps) { - const validSteps = steps.filter(s => V.OnBoard(x + s[0], y + s[1])); - const step = validSteps[randInt(validSteps.length)]; + const validSteps = steps.filter(s => this.onBoard(x + s[0], y + s[1])); + const step = validSteps[Random.randInt(validSteps.length)]; return [x + step[0], y + step[1]]; } @@ -723,18 +771,23 @@ export class ChakartRules extends ChessRules { return move; } + + + + getPotentialPawnMoves([x, y]) { const color = this.turn; - const oppCol = V.GetOppCol(color); - const [sizeX, sizeY] = [V.size.x, V.size.y]; - const shiftX = V.PawnSpecs.directions[color]; - const firstRank = (color == "w" ? sizeX - 1 : 0); + const oppCol = C.GetOppCol(color); + const shiftX = (color == 'w' ? -1 : 1); + const firstRank = (color == "w" ? this.size.x - 1 : 0); let moves = []; if ( - this.board[x + shiftX][y] == V.EMPTY || + this.board[x + shiftX][y] == "" || this.getColor(x + shiftX, y) == 'a' || this.getPiece(x + shiftX, y) == V.INVISIBLE_QUEEN ) { + + // TODO: this.addPawnMoves([x, y], [x + shiftX, y], moves); if ( [firstRank, firstRank + shiftX].includes(x) && @@ -921,7 +974,8 @@ export class ChakartRules extends ChessRules { - +/// if any of my pieces was immobilized, it's not anymore. + //if play set a piece immobilized, then mark it prePlay(move) { if (move.effect == "toadette") this.reserve = this.captured; @@ -1012,7 +1066,14 @@ export class ChakartRules extends ChessRules { return moves; } - // TODO + display bonus messages - // + animation + multi-moves for bananas/bombs/mushrooms + playPlusVisual(move, r) { + this.play(move); + this.playVisual(move, r); + + + // TODO: display bonus messages +// TODO: si continuation, continuer, et sinon : + this.afterPlay(this.moveStack); //user method + } };