]> git.cworth.org Git - empires-server/commitdiff
Fix bug with incorrect scoring based on capitalization
authorCarl Worth <cworth@cworth.org>
Fri, 12 Jun 2020 17:10:06 +0000 (10:10 -0700)
committerCarl Worth <cworth@cworth.org>
Fri, 12 Jun 2020 17:10:06 +0000 (10:10 -0700)
As exposed in the previous commit which extended testing.

After we construct what we call "word maps", (where a group of words
are hased to by each word in the group individually), we collapse them
down to just the array of word groups themselves. This step was being
carried out by looking for the mapping to the word group where the
mapped word matched the first word in the list.

However, if that first word happened to differ in case from the
mapping word (which was already made canonically lowercase) then the
word group wouldn't be included in the final array and all submissions
of words from that group would incorrectly be scored as singletons.

The fix for this is to simply force the word being compared to as in
this commit.

This commit causes the test suite to pass again.

empathy.js

index 759b486f8b58b1814299c1fe6863bb17109b2917..e80c1af34e0644b13ba898c38d6e0ec464a5542b 100644 (file)
@@ -266,7 +266,8 @@ class Empathy extends Game {
      * multiple times). In contrast, iterating over"word_groups" will
      * have you visit each group only once. */
     const word_groups = Object.entries(word_maps).filter(
-      entry => entry[0] === entry[1].words[0]).map(entry => entry[1]);
+      entry => entry[0] === this.canonize(entry[1].words[0]))
+          .map(entry => entry[1]);
 
     /* Now, go through each word group and assign the scores out to
      * the corresponding players.