From 7ba4a5bc5b64e19a1e7f26aa232d5c50770d07ad Mon Sep 17 00:00:00 2001 From: Benjamin Auder Date: Wed, 4 Mar 2020 16:12:30 +0100 Subject: [PATCH] Experimental symmetric randomness + deterministic option --- TODO | 8 ---- client/src/base_rules.js | 16 ++++++-- client/src/components/BaseGame.vue | 6 ++- client/src/components/ChallengeList.vue | 15 +++++++ client/src/translations/about/en.pug | 12 +++--- client/src/translations/about/es.pug | 12 +++--- client/src/translations/about/fr.pug | 12 +++--- client/src/translations/en.js | 5 +++ client/src/translations/es.js | 5 +++ client/src/translations/fr.js | 5 +++ client/src/utils/timeControl.js | 2 + client/src/variants/Allmate1.js | 4 +- client/src/variants/Allmate2.js | 4 +- client/src/variants/Antiking.js | 11 ++++- client/src/variants/Arena.js | 6 ++- client/src/variants/Baroque.js | 12 +++++- client/src/variants/Checkered.js | 8 ++-- client/src/variants/Circular.js | 11 ++++- client/src/variants/Crazyhouse.js | 4 +- client/src/variants/Grand.js | 13 +++++- client/src/variants/Grasshopper.js | 4 +- client/src/variants/Hidden.js | 1 + client/src/variants/Hiddenqueen.js | 6 +-- client/src/variants/Knightmate.js | 53 ++----------------------- client/src/variants/Losers.js | 14 ++++++- client/src/variants/Recycle.js | 4 +- client/src/variants/Royalrace.js | 14 ++++++- client/src/variants/Shatranj.js | 4 +- client/src/variants/Suction.js | 4 +- client/src/variants/Threechecks.js | 8 ++-- client/src/variants/Upsidedown.js | 11 ++++- client/src/variants/Wildebeest.js | 13 +++++- client/src/views/Analyse.vue | 12 +++--- client/src/views/Hall.vue | 14 ++++++- server/db/create.sql | 1 + server/models/Challenge.js | 13 +++--- server/routes/challenges.js | 1 + 37 files changed, 222 insertions(+), 126 deletions(-) diff --git a/TODO b/TODO index ab06e20a..7e9c4834 100644 --- a/TODO +++ b/TODO @@ -7,14 +7,6 @@ From MyGames page: send "mconnect" to all online players (me included: potential When quit, send mdisconnect (relayed by server if no other MyGames tab). And remove current "notify through newmove" on server in sockets.js -Analyse mode when launched from a position: should keep orientation ---> $route query param, "side=w or b" - -Subcursor (intra move) for multi-move variants for better navigation (in BaseGame) - -Allow symmetric mode in all variants (vertical symmetry for racing kings) -flag in challenge, "Symmetric: true / false", option of GenRandInitFen() - # Misc: Saw once a "double challenge" bug, one anonymous and a second one logged Both were asked a challenge probably, and both challenges added as different ones. diff --git a/client/src/base_rules.js b/client/src/base_rules.js index 5b335b0f..93772b9b 100644 --- a/client/src/base_rules.js +++ b/client/src/base_rules.js @@ -238,11 +238,21 @@ export const ChessRules = class ChessRules { ///////////// // FEN UTILS - // Setup the initial random (assymetric) position - static GenRandInitFen() { + // Setup the initial random (asymmetric) position + static GenRandInitFen(randomness) { + if (!randomness) randomness = 2; + if (randomness == 0) + // Deterministic: + return "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w 0 1111 -"; + let pieces = { w: new Array(8), b: new Array(8) }; - // Shuffle pieces on first and last rank + // Shuffle pieces on first (and last rank if randomness == 2) for (let c of ["w", "b"]) { + if (c == 'b' && randomness == 1) { + pieces['b'] = pieces['w']; + break; + } + let positions = ArrayFun.range(8); // Get random squares for bishops diff --git a/client/src/components/BaseGame.vue b/client/src/components/BaseGame.vue index 2a1a4474..4af4e153 100644 --- a/client/src/components/BaseGame.vue +++ b/client/src/components/BaseGame.vue @@ -227,11 +227,13 @@ export default { this.lastMove = null; }, analyzePosition: function() { - const newUrl = + let newUrl = "/analyse/" + this.game.vname + "/?fen=" + this.vr.getFen().replace(/ /g, "_"); + if (this.game.mycolor) + newUrl += "&side=" + this.game.mycolor; // Open in same tab in live games (against cheating) if (this.game.type == "live") this.$router.push(newUrl); else window.open("#" + newUrl); @@ -337,7 +339,7 @@ export default { } }; const playMove = () => { - const animate = V.ShowMoves == "all" && received; + const animate = V.ShowMoves == "all" && (received || navigate); if (!Array.isArray(move)) move = [move]; let moveIdx = 0; let self = this; diff --git a/client/src/components/ChallengeList.vue b/client/src/components/ChallengeList.vue index a350c705..7572ede1 100644 --- a/client/src/components/ChallengeList.vue +++ b/client/src/components/ChallengeList.vue @@ -6,6 +6,7 @@ div th {{ st.tr["Variant"] }} th {{ st.tr["With"] }} th {{ st.tr["Cadence"] }} + th {{ st.tr["Random?"] }} tbody tr( v-for="c in sortedChallenges" @@ -15,6 +16,7 @@ div td {{ c.vname }} td {{ withWho(c) }} td {{ c.cadence }} + td(:class="getRandomnessClass(c)")