]> git.cworth.org Git - lmno-server/commitdiff
Use set difference (ANSWERED - JUDGED) to determine whether to advance
authorCarl Worth <cworth@cworth.org>
Sun, 28 Jun 2020 00:52:06 +0000 (17:52 -0700)
committerCarl Worth <cworth@cworth.org>
Sun, 28 Jun 2020 00:52:06 +0000 (17:52 -0700)
This is a bug fix for the bug described and tested in the previous
commit. Previously we were simply comparing the count of players who
had judged with the count of those who had answered.

Here, instead, we compute an actual set difference and only
auto-advance from the judging phase when every player who answered has
also completed judging.

This fix causes the test added in the previous comit to start passing,
so now the entire test suite is passing once again.

empathy.js

index 7b27ee40c5d196866b19036455c66e6b5ebe713e..ba25cc4c49d7e996ba2c93505efc0ab2ba75b9d8 100644 (file)
@@ -663,7 +663,8 @@ router.post('/judged/:prompt_id([0-9]+)', (request, response) => {
 
   /* If every player who answered has also judged, then there's no
    * need to wait for anything else. */
-  if (game.state.players_judged.length >= game.state.players_answered.length)
+  const judged_set = new Set(game.state.players_judged);
+  if ([...game.state.players_answered].filter(x => !judged_set.has(x)).length === 0)
     game.compute_scores();
 });