X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=variants%2FAlapo%2Fclass.js;h=199a169b82a2c4404e697d7b7c299af401fe2f08;hb=HEAD;hp=e6131403884eed8004b5a3f9c65127fddb391b3c;hpb=33b427488bb6ee5c505c3a024bccedbef763f80e;p=xogo.git diff --git a/variants/Alapo/class.js b/variants/Alapo/class.js index e613140..9fcfc98 100644 --- a/variants/Alapo/class.js +++ b/variants/Alapo/class.js @@ -1,6 +1,7 @@ import ChessRules from "/base_rules.js"; import {ArrayFun} from "/utils/array.js"; import {Random} from "/utils/alea.js"; +import {FenUtil} from "/utils/setupPieces.js"; export default class AlapoRules extends ChessRules { @@ -29,55 +30,25 @@ export default class AlapoRules extends ChessRules { } genRandInitBaseFen() { - let fen = ""; - if (this.options["randomness"] == 0) - fen = "rbqqbr/tcssct/6/6/TCSSCT/RBQQBR"; - else { - const piece2pawn = { - r: 't', - q: 's', - b: 'c' - }; - let pieces = { w: new Array(6), b: new Array(6) }; - // Shuffle pieces on first (and last rank if randomness == 2) - for (let c of ["w", "b"]) { - if (c == 'b' && this.options["randomness"] == 1) { - pieces['b'] = pieces['w']; - break; - } - let positions = ArrayFun.range(6); - // Get random squares for bishops - let randIndex = 2 * Random.randInt(3); - const bishop1Pos = positions[randIndex]; - let randIndex_tmp = 2 * Random.randInt(3) + 1; - const bishop2Pos = positions[randIndex_tmp]; - positions.splice(Math.max(randIndex, randIndex_tmp), 1); - positions.splice(Math.min(randIndex, randIndex_tmp), 1); - // Get random square for queens - randIndex = Random.randInt(4); - const queen1Pos = positions[randIndex]; - positions.splice(randIndex, 1); - randIndex = Random.randInt(3); - const queen2Pos = positions[randIndex]; - positions.splice(randIndex, 1); - // Rooks positions are now fixed, - const rook1Pos = positions[0]; - const rook2Pos = positions[1]; - pieces[c][rook1Pos] = "r"; - pieces[c][bishop1Pos] = "b"; - pieces[c][queen1Pos] = "q"; - pieces[c][queen2Pos] = "q"; - pieces[c][bishop2Pos] = "b"; - pieces[c][rook2Pos] = "r"; + const s = FenUtil.setupPieces( + ['r', 'b', 'q', 'q', 'b', 'r'], + { + randomness: this.options["randomness"], + diffCol: ['b'] } - fen = ( - pieces["b"].join("") + "/" + - pieces["b"].map(p => piece2pawn[p]).join("") + - "/6/6/" + - pieces["w"].map(p => piece2pawn[p].toUpperCase()).join("") + "/" + - pieces["w"].join("").toUpperCase() - ); - } + ); + const piece2pawn = { + r: 't', + q: 's', + b: 'c' + }; + const fen = ( + s.b.join("") + "/" + + s.b.map(p => piece2pawn[p]).join("") + + "/6/6/" + + s.w.map(p => piece2pawn[p].toUpperCase()).join("") + "/" + + s.w.join("").toUpperCase() + ); return { fen: fen, o: {} }; } @@ -137,7 +108,7 @@ export default class AlapoRules extends ChessRules { // Try both colors (to detect potential suicides) let won = {}; for (let c of ['w', 'b']) { - const oppCol = C.GetOppCol(c); + const oppCol = C.GetOppTurn(c); const goal = (c == 'w' ? 0 : 5); won[c] = this.board[goal].some((b,j) => { return (