]> git.cworth.org Git - empires-server/commitdiff
Include still-answering players when ruling on end-asnwering majority
authorCarl Worth <cworth@cworth.org>
Fri, 26 Jun 2020 14:33:04 +0000 (07:33 -0700)
committerCarl Worth <cworth@cworth.org>
Fri, 26 Jun 2020 14:33:04 +0000 (07:33 -0700)
The test suite exposed a logical bug here. Imagine a 10-player game
where two players have submitted and 8 are still answering. Those two
players should not have the ability to move on without the answers
from the larger set of players still waiting. But that's what the old
logic would have allowed here.

In this commit we count up all players who have already submitted
answers as well as all players who have at least indicated that they
are answering in order to decide how many we need for a majority.

Note: This does mean that if something happens, (like a major network
outage), that prevents a majority of the players from being able to
submit their answers, the game cannot proceed with the minority who
succesfully submitted. I think I'm OK with that. (If the minority
really wants to proceed in a case as dramatic as that then it would be
reasonable for them to start a new game.)

With this commit the test suite is now fully passing again, (for the
first time since the recent addition of new tests).

empathy.js

index b7d01a0566c2d5b379db9ab90c3c77f4c8928bbd..1cd120ee5e098870112f91c13025464fea079a40 100644 (file)
@@ -506,7 +506,12 @@ router.post('/end-answers/:prompt_id([0-9]+)', (request, response) => {
   else
     response.sendStatus(404);
 
-  if (game.state.end_answers.size > (game.state.players_answered.length / 2))
+  /* The majority rule here includes all players that have answered as
+   * well as all that have started typing. */
+  const players_involved = (game.state.players_answered.length +
+                            game.state.players_answering.size);
+
+  if (game.state.end_answers.size > players_involved / 2)
     game.perform_judging();
 });