]> git.cworth.org Git - lmno-server/commitdiff
empathy: Don't let any player give kudos to themself
authorCarl Worth <cworth@cworth.org>
Mon, 29 Jun 2020 21:23:28 +0000 (14:23 -0700)
committerCarl Worth <cworth@cworth.org>
Mon, 6 Jul 2020 01:43:58 +0000 (18:43 -0700)
Which would not be very sporting of course, so we don't allow it.

Note that this restriction is applied after the majority-ruled
matching. So a player can't even give kudos to a word they didn't
submit and then hope to get matched into it.

It's also worth noting that the group can decide to split a group
where one player gave kudos. That will mean that both sides of the
split get kudos from the player, which seems to match the kudos-giving
player's intent.

empathy.js

index 01836df853df89760bc33794724d3a51611c4601..d6b007b4bc3ef75d32230cde000917cdacdb7fa4 100644 (file)
@@ -348,8 +348,12 @@ class Empathy extends Game {
     for (let group of word_groups) {
 
       const words = group.words;
-      if (group.kudos)
-        this.kudos[player.name] = [...words];
+      if (group.kudos) {
+        this.kudos[player.name] = {
+          player: player,
+          words: [...words]
+        };
+      }
 
       for (let i = 0; i < words.length - 1; i++) {
         for (let j = i + 1; j < words.length; j++) {
@@ -526,12 +530,16 @@ class Empathy extends Game {
     /* Apply kudos from each player to the word maps, (using a set so
      * that no word_map can get multiple kudos from a single
      * player). */
-    for (let player of Object.keys(this.kudos)) {
-      for (let word of this.kudos[player]) {
+    for (let kudos of Object.values(this.kudos)) {
+      for (let word of kudos.words) {
         const word_canon = this.canonize(word);
         if (! word_maps[word_canon])
           continue;
-        word_maps[word_canon].kudos.add(player);
+        /* Don't let any player give kudos to a group where they
+         * submitted a word themself. That just wouldn't be right. */
+        if (! word_maps[word_canon].players.has(kudos.player)) {
+          word_maps[word_canon].kudos.add(kudos.player);
+        }
       }
     }
 
@@ -611,7 +619,7 @@ class Empathy extends Game {
         return {
           word: group.words.join('/'),
           players: Array.from(group.players).map(p => p.name),
-          kudos: Array.from(group.kudos)
+          kudos: Array.from(group.kudos).map(p => p.name)
         };
       }
     );