X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=variants%2FChakart%2Fclass.js;h=5202b489dfeaad00f5a74cac6f4a678a87a7cc94;hb=HEAD;hp=d804548e0c0d3ffe74537de3a3b2d13ccdc8f162;hpb=98d144512e5505f5ef8b702b139ca6ceff92c823;p=xogo.git diff --git a/variants/Chakart/class.js b/variants/Chakart/class.js index d804548..3454d8f 100644 --- a/variants/Chakart/class.js +++ b/variants/Chakart/class.js @@ -1,7 +1,7 @@ import ChessRules from "/base_rules.js"; -import GiveawayRules from "/variants/Giveaway/class.js"; import {ArrayFun} from "/utils/array.js"; import {Random} from "/utils/alea.js"; +import {FenUtil} from "/utils/setupPieces.js"; import PiPo from "/utils/PiPo.js"; import Move from "/utils/Move.js"; @@ -116,7 +116,6 @@ export default class ChakartRules extends ChessRules { { 'y': { // Virtual piece for "king remote shell captures" - moves: [], attack: [ { steps: [ @@ -131,12 +130,25 @@ export default class ChakartRules extends ChessRules { ); } + isKing(x, y, p) { + if (!p) + p = this.getPiece(x, y); + return ['k', 'l'].includes(p); + } + genRandInitBaseFen() { - const options = Object.assign({mode: "suicide"}, this.options); - const gr = new GiveawayRules({options: options, genFenOnly: true}); - let res = gr.genRandInitBaseFen(); - res.o["flags"] = "1111"; //Peach + Mario flags - return res; + const s = FenUtil.setupPieces( + ['r', 'n', 'b', 'q', 'k', 'b', 'n', 'r'], + { + randomness: this.options["randomness"], + diffCol: ['b'] + } + ); + return { + fen: s.b.join("") + "/pppppppp/8/8/8/8/PPPPPPPP/" + + s.w.join("").toUpperCase(), + o: {flags: "1111"} //Peach + Mario + }; } fen2board(f) { @@ -214,7 +226,7 @@ export default class ChakartRules extends ChessRules { moves = this.getDropMovesFrom([x, y]); else if (this.egg == "kingboo") { const color = this.turn; - const oppCol = C.GetOppCol(color); + const oppCol = C.GetOppTurn(color); // Only allow to swap (non-immobilized!) pieces for (let i=0; i { let [mx, my] = [x, y]; @@ -386,7 +398,7 @@ export default class ChakartRules extends ChessRules { play(move) { const color = this.turn; - const oppCol = C.GetOppCol(color); + const oppCol = C.GetOppTurn(color); this.egg = move.egg; if (move.egg == "toadette") { this.reserve = { w: {}, b: {} }; @@ -472,8 +484,7 @@ export default class ChakartRules extends ChessRules { ) ) { // "Forgotten" promotion, which occurred after some effect - let moves = [move]; - super.pawnPostProcess(moves, color, C.GetOppCol(color)); + let moves = super.pawnPostProcess([move], color, C.GetOppTurn(color)); super.showChoices(moves, r); } else @@ -481,6 +492,8 @@ export default class ChakartRules extends ChessRules { } computeNextMove(move) { + if (move.koopa) + return null; // Set potential random effects, so that play() is deterministic // from opponent viewpoint: const endPiece = this.getPiece(move.end.x, move.end.y); @@ -582,11 +595,15 @@ export default class ChakartRules extends ChessRules { case "luigi": case "waluigi": // Change color of friendly or enemy piece, king excepted - const oldColor = (move.egg == "waluigi" ? color : C.GetOppCol(color)); - const newColor = C.GetOppCol(oldColor); + const oldColor = (move.egg == "waluigi" ? color : C.GetOppTurn(color)); + const newColor = C.GetOppTurn(oldColor); const coords = getRandomPiece(oldColor); if (coords) { const piece = this.getPiece(coords[0], coords[1]); + if (coords[0] == move.start.x && coords[1] == move.start.y) { + // Moving piece change color: fix coords + coords = [move.end.x, move.end.y]; + } em = new Move({ appear: [ new PiPo({x: coords[0], y: coords[1], c: newColor, p: piece}) @@ -619,19 +636,25 @@ export default class ChakartRules extends ChessRules { }); break; case "koopa": - // Reverse move + // Reverse move, if possible em = new Move({ - appear: [ - new PiPo({ - x: move.start.x, y: move.start.y, c: color, p: move.appear[0].p - }) - ], + appear: [], vanish: [ new PiPo({ x: move.end.x, y: move.end.y, c: color, p: move.appear[0].p }) - ] + ], + end: {x: move.start.x, y: move.start.y} //may be irrelevant }); + em.koopa = true; //avoid applying effect + if (move.vanish.length == 0) + // After toadette+drop, just erase piece + break; + em.appear.push( + new PiPo({ + x: move.start.x, y: move.start.y, c: color, p: move.appear[0].p + }) + ); if (this.board[move.start.x][move.start.y] != "") { // Pawn or knight let something on init square em.vanish.push(new PiPo({