X-Git-Url: https://git.auder.net/img/parser.js?a=blobdiff_plain;f=base_rules.js;h=864bb33d072566a13c1ae09c6d469d55e81753da;hb=bc2bc396ec4df092f218b58a0fbf08ba7eb8ca6e;hp=3fa4e0bf40baa5514c40315eb5f21bae97b83c16;hpb=437dfd42748eb2359103fd87a7d0e780121a7865;p=xogo.git diff --git a/base_rules.js b/base_rules.js index 3fa4e0b..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,7 +182,8 @@ export default class ChessRules { else { // Randomize - let pieces = { w: new Array(8), b: new Array(8) }; + Random.setSeed(seed); + let pieces = {w: new Array(8), b: new Array(8)}; flags = ""; // Shuffle pieces on first (and last rank if randomness == 2) for (let c of ["w", "b"]) { @@ -379,6 +378,9 @@ export default class ChessRules { if (this.options[opt.variable] === undefined) this.options[opt.variable] = opt.defaut; }); + if (o.genFenOnly) + // This object will be used only for initial FEN generation + return; this.playerColor = o.color; this.afterPlay = o.afterPlay; //trigger some actions after playing a move @@ -1044,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 @@ -2159,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);