From: Carl Worth <cworth@cworth.org>
Date: Fri, 12 Jun 2020 02:58:33 +0000 (-0700)
Subject: empathy: Alphabetize list before sending it out for judging
X-Git-Url: https://git.cworth.org/git?a=commitdiff_plain;h=e181d1b70ae0fdb3499852a5c8820617a533924d;p=empires-server

empathy: Alphabetize list before sending it out for judging

This should make judging much easier.

Fix is confirmed with the existing test case (which is updated to
match the new behavior).
---

diff --git a/empathy.js b/empathy.js
index 028117d..759b486 100644
--- a/empathy.js
+++ b/empathy.js
@@ -144,7 +144,9 @@ class Empathy extends Game {
       }
     }
 
-    this.state.ambiguities = Object.values(word_map);
+    this.state.ambiguities = Object.values(word_map).sort((a,b) => {
+      return a.toLowerCase().localeCompare(b.toLowerCase());
+    });
 
     this.broadcast_event_object('ambiguities', this.state.ambiguities);
   }
diff --git a/test b/test
index 7113659..e56cc93 100755
--- a/test
+++ b/test
@@ -533,7 +533,7 @@ empathy_ambiguities()
 TEST "Received all unique words"
 # echo here is to strip newlines
 result=$(echo $(empathy_ambiguities $alice))
-test "$result" = '"sun" "sand" "water" "people" "sands" "SunLight" "towels" "SunShine" "Grains of Sand" "wafer"'
+test "$result" = '"Grains of Sand" "people" "sand" "sands" "sun" "SunLight" "SunShine" "towels" "wafer" "water"'
 TEST_END
 
 TEST "Submit word groups from alice"