From bfa7d9931b50c1ed54ff3c6d4ef5bc423f26de94 Mon Sep 17 00:00:00 2001 From: Benjamin Auder Date: Sat, 28 Mar 2020 22:04:43 +0100 Subject: [PATCH] Better randomness in Ball variant + notify when receiving targetting challenge --- client/src/variants/Ball.js | 17 +++++++++++++---- client/src/views/Hall.vue | 9 +++++++++ 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/client/src/variants/Ball.js b/client/src/variants/Ball.js index 19b81ede..734a9218 100644 --- a/client/src/variants/Ball.js +++ b/client/src/variants/Ball.js @@ -134,17 +134,26 @@ export class BallRules extends ChessRules { break; } - // Get random squares for every piece, totally freely + // Get random squares for every piece, with bishops and phoenixes + // on different colors: let positions = shuffle(ArrayFun.range(9)); - const composition = ['b', 'b', 'r', 'r', 'n', 'n', 'h', 'h', 'q']; - const rem2 = positions[0] % 2; + const composition = ['b', 'b', 'h', 'h', 'n', 'n', 'r', 'r', 'q']; + let rem2 = positions[0] % 2; if (rem2 == positions[1] % 2) { // Fix bishops (on different colors) - for (let i=2; i<9; i++) { + for (let i=4; i<9; i++) { if (positions[i] % 2 != rem2) [positions[1], positions[i]] = [positions[i], positions[1]]; } } + rem2 = positions[2] % 2; + if (rem2 == positions[3] % 2) { + // Fix phoenixes too: + for (let i=4; i<9; i++) { + if (positions[i] % 2 != rem2) + [positions[3], positions[i]] = [positions[i], positions[3]]; + } + } for (let i = 0; i < 9; i++) pieces[c][positions[i]] = composition[i]; } return ( diff --git a/client/src/views/Hall.vue b/client/src/views/Hall.vue index ab5108e5..0ed355bf 100644 --- a/client/src/views/Hall.vue +++ b/client/src/views/Hall.vue @@ -927,6 +927,15 @@ export default { .getElementById("btnC" + newChall.type) .classList.add("somethingnew"); } + if (!!chall.to) { + notify( + "New challenge", + // fromValues.name should exist since the player is online, but + // let's consider there is some chance that the challenge arrives + // right after we connected and before receiving the poll result: + { body: "from " + (fromValues.name || "unknown yet...") } + ); + } } }, loadNewchallVariant: async function(cb) { -- 2.44.0