X-Git-Url: https://git.auder.net/img/parser.js?a=blobdiff_plain;f=variants%2FAlapo%2Fclass.js;h=3707ac87b33fb2960e2c4dedfd603674161ce55f;hb=7c03823594cef3ce6e8da7ac1d7d3504c73695a9;hp=eb0e73f6bd3146778a26cf53ba64ce58db6c09ae;hpb=f55a0a6753a62257c7caa62ae49c8a5673769065;p=xogo.git diff --git a/variants/Alapo/class.js b/variants/Alapo/class.js index eb0e73f..3707ac8 100644 --- a/variants/Alapo/class.js +++ b/variants/Alapo/class.js @@ -1,9 +1,17 @@ import ChessRules from "/base_rules.js"; -import { ArrayFun } from "/utils/array.js"; -import { Random } from "/utils/alea.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 { + static get Options() { + return { + select: C.Options.select, + styles: C.Options.styles.filter(s => s != "teleport") + }; + } + get hasFlags() { return false; } @@ -21,78 +29,35 @@ export default class AlapoRules extends ChessRules { return board; } - genRandInitFen(seed) { - if (this.options["randomness"] == 0) - return "rbqqbr/tcssct/6/6/TCSSCT/RBQQBR w 0"; - - Random.setSeed(seed); - + genRandInitBaseFen() { + const s = + FenUtil.setupPieces(['r', 'b', 'q', 'q', 'b', 'r'], {diffCol: ['b']}); 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"; - } - - return ( - pieces["b"].join("") + "/" + - pieces["b"].map(p => piece2pawn[p]).join("") + + const fen = ( + s.b.join("") + "/" + + s.b.map(p => piece2pawn[p]).join("") + "/6/6/" + - pieces["w"].map(p => piece2pawn[p].toUpperCase()).join("") + "/" + - pieces["w"].join("").toUpperCase() + - " w 0" + s.w.map(p => piece2pawn[p].toUpperCase()).join("") + "/" + + s.w.join("").toUpperCase() ); + return { fen: fen, o: {} }; } + // Triangles are rotated from opponent viewpoint (=> suffix "_inv") pieces(color, x, y) { + const allSpecs = super.pieces(color, x, y); return { - 'r': super.pieces(color, x, y)['r'], - 'q': super.pieces(color, x, y)['q'], - 'b': { - // Triangle is rotated from opponent viewpoint - "class": "bishop" + (this.playerColor != color ? "_inv" : ""), - moves: [ { steps: [[1, 1], [1, -1], [-1, 1], [-1, -1]] } ] - }, + 'r': allSpecs['r'], + 'q': allSpecs['q'], + 'b': Object.assign({}, allSpecs['b'], + {"class": "bishop" + (this.playerColor != color ? "_inv" : "")}), 's': { //"square" "class": "babyrook", - moves: [ + both: [ { steps: [[0, 1], [0, -1], [1, 0], [-1, 0]], range: 1 @@ -101,7 +66,7 @@ export default class AlapoRules extends ChessRules { }, 'c': { //"circle" "class": "babyqueen", - moves: [ + both: [ { steps: [ [0, 1], [0, -1], [1, 0], [-1, 0], @@ -113,7 +78,7 @@ export default class AlapoRules extends ChessRules { }, 't': { //"triangle" "class": "babybishop" + (this.playerColor != color ? "_inv" : ""), - moves: [ + both: [ { steps: [[1, 1], [1, -1], [-1, 1], [-1, -1]], range: 1 @@ -143,8 +108,14 @@ export default class AlapoRules extends ChessRules { won[c] = this.board[goal].some((b,j) => { return ( this.getColor(goal, j) == c && - this.findCapturesOn( - [goal, j], {one: true, oppCol: oppCol}).length == 0 + !this.findCapturesOn( + [goal, j], + { + one: true, + oppCol: oppCol, + segments: this.options["cylinder"] + } + ) ); }); }