From: Benjamin Auder Date: Wed, 22 Apr 2020 02:15:45 +0000 (+0200) Subject: Better colors (not good enough yet) + randomization for Shogi X-Git-Url: https://git.auder.net/%7B%7B%20asset%28%27mixstore/images/css/mini-custom.min.css?a=commitdiff_plain;h=b4f2488a58c5c92e1673cd64c6bba13afcafbf66;p=vchess.git Better colors (not good enough yet) + randomization for Shogi --- diff --git a/client/src/variants/Shogi.js b/client/src/variants/Shogi.js index 1b2ba03a..521e4680 100644 --- a/client/src/variants/Shogi.js +++ b/client/src/variants/Shogi.js @@ -1,6 +1,6 @@ import { ChessRules, PiPo, Move } from "@/base_rules"; import { ArrayFun } from "@/utils/array"; -import { shuffle } from "@/utils/alea"; +import { sample, shuffle } from "@/utils/alea"; export class ShogiRules extends ChessRules { static get HasFlags() { @@ -15,6 +15,10 @@ export class ShogiRules extends ChessRules { return true; } + static get Notoodark() { + return true; + } + static IsGoodFen(fen) { if (!ChessRules.IsGoodFen(fen)) return false; const fenParsed = V.ParseFen(fen); @@ -106,20 +110,49 @@ export class ShogiRules extends ChessRules { "w 0 00000000000000" ); } - let pieces = { w: new Array(9), b: new Array(9) }; + // Randomization following these indications: + // http://www.shogi.net/shogi-l/Archive/2007/Nmar16-02.txt + let pieces1 = { w: new Array(4), b: new Array(4) }; + let positions2 = { w: new Array(2), b: new Array(2) }; for (let c of ["w", "b"]) { if (c == 'b' && randomness == 1) { - pieces['b'] = pieces['w']; + pieces1['b'] = JSON.parse(JSON.stringify(pieces1['w'])).reverse(); + positions2['b'] = + JSON.parse(JSON.stringify(positions2['w'])).reverse() + .map(p => 8 - p); break; } - let positions = shuffle(ArrayFun.range(9)); - const composition = ['l', 'l', 'n', 'n', 's', 's', 'g', 'g', 'k']; - for (let i = 0; i < 9; i++) pieces[c][positions[i]] = composition[i]; + let positions = shuffle(ArrayFun.range(4)); + const composition = ['s', 's', 'g', 'g']; + for (let i = 0; i < 4; i++) pieces1[c][positions[i]] = composition[i]; + positions2[c] = sample(ArrayFun.range(9), 2).sort(); } return ( - pieces["b"].join("") + - "/1r5b1/ppppppppp/9/9/9/PPPPPPPPP/1B5R1/" + - pieces["w"].join("").toUpperCase() + + ( + "ln" + + pieces1["b"].slice(0, 2).join("") + + "k" + + pieces1["b"].slice(2, 4).join("") + + "nl/" + ) + + ( + (positions2['b'][0] || "") + 'r' + + (positions2['b'][1] - positions2['b'][0] - 1 || "") + 'b' + + (8 - positions2['b'][1] || "") + ) + + "/ppppppppp/9/9/9/PPPPPPPPP/" + + ( + (positions2['w'][0] || "") + 'B' + + (positions2['w'][1] - positions2['w'][0] - 1 || "") + 'R' + + (8 - positions2['w'][1] || "") + ) + + ( + "/LN" + + pieces1["w"].slice(0, 2).join("").toUpperCase() + + "K" + + pieces1["w"].slice(2, 4).join("").toUpperCase() + + "NL" + ) + " w 0 00000000000000" ); } diff --git a/client/src/views/Game.vue b/client/src/views/Game.vue index 1753df0d..919a7ebc 100644 --- a/client/src/views/Game.vue +++ b/client/src/views/Game.vue @@ -1054,7 +1054,7 @@ export default { let gameInfo = { id: getRandString(), //ignored if corr fen: V.GenRandInitFen(this.game.randomness), - players: this.game.players.reverse(), + players: [this.game.players[1], this.game.players[0]], vid: this.game.vid, cadence: this.game.cadence };