X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=variants%2FAmbiguous%2Fclass.js;h=a0cb7f2f602cdeca7af1dcae5d8daebff5503764;hb=04d93b7bb3b64ecdf3fb7219eee42879f0200b88;hp=6a001a6f795e94349a439f30b7e0946218332d7b;hpb=554e3ad3773a3123701bd894db1df4c1843283b8;p=xogo.git diff --git a/variants/Ambiguous/class.js b/variants/Ambiguous/class.js index 6a001a6..a0cb7f2 100644 --- a/variants/Ambiguous/class.js +++ b/variants/Ambiguous/class.js @@ -1,5 +1,5 @@ import ChessRules from "/base_rules.js"; -import GiveawayRules from "/variants/Giveaway/class.js"; +import {FenUtil} from "/utils/setupPieces.js"; export default class AmbiguousRules extends ChessRules { @@ -22,10 +22,19 @@ export default class AmbiguousRules extends ChessRules { this.subTurn = 1; } - genRandInitFen(seed) { - const options = Object.assign({mode: "suicide"}, this.options); - const gr = new GiveawayRules({options: options, genFenOnly: true}); - return gr.genRandInitFen(seed); + genRandInitBaseFen() { + 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: {} + }; } canStepOver(x, y) { @@ -36,7 +45,7 @@ export default class AmbiguousRules extends ChessRules { // Subturn 2: play a move for me (which just indicate a square). getPotentialMovesFrom([x, y]) { const color = this.turn; - const oppCol = C.GetOppCol(color); + const oppCol = C.GetOppTurn(color); if (this.subTurn == 2) { // Just play a normal move (which in fact only indicate a square) let movesHash = {}; @@ -55,13 +64,11 @@ export default class AmbiguousRules extends ChessRules { return true; }) .map(m => { - if (m.vanish.length == 1) { - m.appear[0].c = 'a'; //a-color + if (m.vanish.length == 1) m.appear[0].p = V.GOAL; - } else { m.appear[0].p = V.TARGET_CODE[m.vanish[1].p]; - m.appear[0].c = oppCol; + m.appear[0].c = m.vanish[1].c; } m.vanish.shift(); return m; @@ -69,7 +76,7 @@ export default class AmbiguousRules extends ChessRules { ); } // At subTurn == 1, play a targeted move for the opponent. - // Search for target (we could also have it in a stack...) + // Search for target: let target = {x: -1, y: -1}; outerLoop: for (let i = 0; i < this.size.x; i++) { for (let j = 0; j < this.size.y; j++) { @@ -126,15 +133,15 @@ export default class AmbiguousRules extends ChessRules { pieces(color, x, y) { const targets = { - 's': {"class": "target-pawn", moves: []}, - 'u': {"class": "target-rook", moves: []}, - 'o': {"class": "target-knight", moves: []}, - 'c': {"class": "target-bishop", moves: []}, - 't': {"class": "target-queen", moves: []}, - 'l': {"class": "target-king", moves: []} + 's': {"class": "target-pawn"}, + 'u': {"class": "target-rook"}, + 'o': {"class": "target-knight"}, + 'c': {"class": "target-bishop"}, + 't': {"class": "target-queen"}, + 'l': {"class": "target-king"} }; - return Object.assign( - { 'g': {"class": "target"} }, targets, super.pieces(color, x, y)); + return Object.assign({ 'g': {"class": "target"} }, + targets, super.pieces(color, x, y)); } atLeastOneMove() { @@ -146,23 +153,24 @@ export default class AmbiguousRules extends ChessRules { return moves; } - isKing(symbol) { - return ['k', 'l'].includes(symbol); + isKing(x, y, p) { + if (!p) + p = this.getPiece(x, y); + return ['k', 'l'].includes(p); } getCurrentScore() { // This function is only called at subTurn 1 - const color = C.GetOppCol(this.turn); - const kingPos = this.searchKingPos(color); - if (kingPos[0] < 0) + const color = C.GetOppTurn(this.turn); + if (this.searchKingPos(color).length == 0) return (color == 'w' ? "0-1" : "1-0"); return "*"; } postPlay(move) { const color = this.turn; - if (this.subTurn == 2 || this.searchKingPos(color)[0] < 0) { - this.turn = C.GetOppCol(color); + if (this.subTurn == 2 || this.searchKingPos(color).length == 0) { + this.turn = C.GetOppTurn(color); this.movesCount++; } this.subTurn = 3 - this.subTurn;