This is after all answers are submitted, and before scores are computed.
The list of unique words are sent to each player so that they can
group them into sets of equivalent words.
The server isn't yet _doing_ anything with the word groups that are
submitted from judging, but that will be the next step.
prompts: [],
active_prompt: null,
players_answered: 0,
prompts: [],
active_prompt: null,
players_answered: 0,
+ ambiguities: null,
+ players_judged: 0,
scores: null
};
this.answers = [];
scores: null
};
this.answers = [];
this.state.active_prompt = null;
this.state.players_answered = 0;
this.state.active_prompt = null;
this.state.players_answered = 0;
+ this.state.ambiguities = 0;
+ this.state.players_judged = 0;
this.state.scores = null;
this.answers = [];
this.state.scores = null;
this.answers = [];
return { valid: true };
}
return { valid: true };
}
+ perform_judging() {
+ const word_map = {};
+
+ for (let a of this.answers) {
+ for (let word of a.answers) {
+ const key = this.canonize(word);
+ word_map[key] = word;
+ }
+ }
+
+ this.state.ambiguities = Object.values(word_map);
+
+ this.broadcast_event_object('ambiguities', this.state.ambiguities);
+ }
+
+ receive_judging() {
+ /* And notify players how many players have completed judging. */
+ this.state.players_judged++;
+ this.broadcast_event_object('judged', this.state.players_judged);
+
+ return { valid: true };
+ }
+
+ canonize(word) {
+ return word.replace(/[^a-zA-Z0-9]/g, '').toLowerCase();
+ }
+
compute_scores() {
const word_submitters = {};
const scores = [];
compute_scores() {
const word_submitters = {};
const scores = [];
request.body.answers);
response.json(result);
request.body.answers);
response.json(result);
- if (game.answers.length >= game.players.length)
+ if (game.state.players_answered >= game.players.length)
+ game.perform_judging();
+});
+
+router.post('/judging/:prompt_id([0-9]+)', (request, response) => {
+ const game = request.game;
+ const prompt_id = parseInt(request.params.prompt_id, 10);
+
+ const result = game.receive_judging(prompt_id,
+ request.session.id,
+ request.body);
+ response.json(result);
+
+ if (game.state.players_judged >= game.players.length)
game.compute_scores();
});
game.compute_scores();
});