]> git.cworth.org Git - lmno-server/blobdiff - empathy.js
Two alterations to player scoring: per-round grouping, and round normalization
[lmno-server] / empathy.js
index fdf62a18d41abb42e1a41741ee2625e313b9faf0..7b27ee40c5d196866b19036455c66e6b5ebe713e 100644 (file)
@@ -50,17 +50,28 @@ class Empathy extends Game {
 
   reset() {
 
-    /* Before closing out the current round, we accumulate the score
-     * for each player into their runnning total. */
-    for (let score of this.state.scores.scores) {
-      const player = this.players.find(p => p.name === score.player);
-      if (player.score)
-        player.score += score.score;
-      else
-        player.score = score.score;
-
-      /* And broadcast that new score out. */
-      this.broadcast_event('player-update', player.info_json());
+    /* Before closing out the current round, we accumulate into each
+     * player's overall score the results from the current round.
+     *
+     * Note: Rather than applying the actual points from each round
+     * into the player's score, we instead accumulate up the number of
+     * players that they bested in each round. This ensures that each
+     * round receives an equal weight in the overall scoring. */
+    let bested = this.state.scores.scores.reduce(
+      (total, score) => total + score.players.length, 0);
+    for (let i = 0; i < this.state.scores.scores.length; i++) {
+      const score = this.state.scores.scores[i];
+      bested -= score.players.length;
+      for (let player_name of score.players) {
+        const player = this.players.find(p => p.name === player_name);
+        if (player.score)
+          player.score += bested;
+        else
+          player.score = bested;
+
+        /* And broadcast that new score out. */
+        this.broadcast_event('player-update', player.info_json());
+      }
     }
 
     /* Now that we're done with the active prompt, we remove it from
@@ -513,6 +524,18 @@ class Empathy extends Game {
       return b.score - a.score;
     });
 
+    /* After sorting individual players by score, group players
+     * together who have the same score. */
+    const reducer = (list, next) => {
+      if (list.length && list[list.length-1].score == next.score)
+        list[list.length-1].players.push(next.player);
+      else
+        list.push({players: [next.player], score: next.score});
+      return list;
+    };
+
+    const grouped_scores = scores.reduce(reducer, []);
+
     /* Put the word groups into a form the client can consume.
      */
     const words_submitted = word_groups.map(
@@ -531,7 +554,7 @@ class Empathy extends Game {
     /* Put this round's scores into the game state object so it will
      * be sent to any new clients that join. */
     this.state.scores = {
-      scores: scores,
+      scores: grouped_scores,
       words: words_submitted
     };