From: Carl Worth Date: Fri, 12 Jun 2020 02:53:15 +0000 (-0700) Subject: Empathy: Fix the capitalization bug X-Git-Url: https://git.cworth.org/git?p=lmno-server;a=commitdiff_plain;h=2a719335c919a492b2752e9ef7a35bc3c139b863 Empathy: Fix the capitalization bug The simple fix here is to always use the canonize function before passing any word into the word_map. With this fix, the test implemented in the previous commit now passes. --- diff --git a/empathy.js b/empathy.js index 25d8f77..028117d 100644 --- a/empathy.js +++ b/empathy.js @@ -219,19 +219,21 @@ class Empathy extends Game { const word_maps = {}; for (let e of agreed_equivalencies) { - let group = word_maps[e.words[0]]; + const word0_canon = this.canonize(e.words[0]); + const word1_canon = this.canonize(e.words[1]); + let group = word_maps[word0_canon]; if (! group) - group = word_maps[e.words[1]]; + group = word_maps[word1_canon]; if (! group) group = { words: [], players: new Set()}; - if (! word_maps[e.words[0]]) { - word_maps[e.words[0]] = group; + if (! word_maps[word0_canon]) { + word_maps[word0_canon] = group; group.words.push(e.words[0]); } - if (! word_maps[e.words[1]]) { - word_maps[e.words[1]] = group; + if (! word_maps[word1_canon]) { + word_maps[word1_canon] = group; group.words.push(e.words[1]); } } @@ -240,13 +242,14 @@ class Empathy extends Game { * to the set corresponding to each word group. */ for (let a of this.answers) { for (let word of a.answers) { + const word_canon = this.canonize(word); /* If there's no group yet, this is a singleton word. */ - if (word_maps[word]) { - word_maps[word].players.add(a.player); + if (word_maps[word_canon]) { + word_maps[word_canon].players.add(a.player); } else { const group = { words: [word], players: new Set() }; group.players.add(a.player); - word_maps[word] = group; + word_maps[word_canon] = group; } } }