X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=base_rules.js;h=864bb33d072566a13c1ae09c6d469d55e81753da;hb=bc2bc396ec4df092f218b58a0fbf08ba7eb8ca6e;hp=30e9ee5fc475650d4d13d36b729b9b321e17bbd1;hpb=f382c57bf08425c170479e55b8670efaf3a7a548;p=xogo.git diff --git a/base_rules.js b/base_rules.js index 30e9ee5..864bb33 100644 --- a/base_rules.js +++ b/base_rules.js @@ -175,8 +175,6 @@ export default class ChessRules { // Setup the initial random-or-not (asymmetric-or-not) position genRandInitFen(seed) { - Random.setSeed(seed); - let fen, flags = "0707"; if (!this.options.randomness) // Deterministic: @@ -184,6 +182,7 @@ export default class ChessRules { else { // Randomize + Random.setSeed(seed); let pieces = {w: new Array(8), b: new Array(8)}; flags = ""; // Shuffle pieces on first (and last rank if randomness == 2) @@ -372,14 +371,14 @@ export default class ChessRules { ////////////////// // INITIALIZATION - constructor(o, genFenOnly) { + constructor(o) { this.options = o.options; // Fill missing options (always the case if random challenge) (V.Options.select || []).concat(V.Options.input || []).forEach(opt => { if (this.options[opt.variable] === undefined) this.options[opt.variable] = opt.defaut; }); - if (genFenOnly) + if (o.genFenOnly) // This object will be used only for initial FEN generation return; this.playerColor = o.color; @@ -1047,7 +1046,11 @@ export default class ChessRules { } static GetColorClass(c) { - return (c == 'w' ? "white" : "black"); + if (c == 'w') + return "white"; + if (c == 'b') + return "black"; + return ""; //unidentified color } // Assume square i,j isn't empty @@ -2162,7 +2165,7 @@ export default class ChessRules { move.appear.forEach(a => { this.g_pieces[a.x][a.y] = document.createElement("piece"); this.g_pieces[a.x][a.y].classList.add(this.pieces()[a.p]["class"]); - this.g_pieces[a.x][a.y].classList.add(a.c == "w" ? "white" : "black"); + this.g_pieces[a.x][a.y].classList.add(C.GetColorClass(a.c)); this.g_pieces[a.x][a.y].style.width = pieceWidth + "px"; this.g_pieces[a.x][a.y].style.height = pieceWidth + "px"; const [ip, jp] = this.getPixelPosition(a.x, a.y, r);