From 1aee14be31c8cac3bd8fc089a07e9c526666edd8 Mon Sep 17 00:00:00 2001 From: Carl Worth Date: Fri, 26 Jun 2020 07:33:04 -0700 Subject: [PATCH] Include still-answering players when ruling on end-asnwering majority 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 | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/empathy.js b/empathy.js index b7d01a0..1cd120e 100644 --- a/empathy.js +++ b/empathy.js @@ -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(); }); -- 2.43.0