]> git.cworth.org Git - empires-server/blobdiff - lmno.js
Consistently use null value to reset the ambiguities list
[empires-server] / lmno.js
diff --git a/lmno.js b/lmno.js
index d01b3e9478543b20c9a51196677a30a02c30edef..c2942a419446562c0da4a0b11ec23318828ef002 100644 (file)
--- a/lmno.js
+++ b/lmno.js
@@ -91,7 +91,8 @@ nunjucks.configure("templates", {
 const engines = {
   empires: require("./empires").Game,
   tictactoe: require("./tictactoe").Game,
-  scribe: require("./scribe").Game
+  scribe: require("./scribe").Game,
+  empathy: require("./empathy").Game
 };
 
 class LMNO {
@@ -100,7 +101,11 @@ class LMNO {
   }
 
   generate_id() {
-    return Array(4).fill(null).map(() => LMNO.letters.charAt(Math.floor(Math.random() * LMNO.letters.length))).join('');
+    /* Note: The copy from Array(4) to [...Array(4)] is necessary so
+     * that map() will actually work, (which it doesn't on an array
+     * from Array(N) which is in this strange state of having "empty"
+     * items rather than "undefined" as we get after [...Array(4)] */
+    return [...Array(4)].map(() => LMNO.letters.charAt(Math.floor(Math.random() * LMNO.letters.length))).join('');
   }
 
   create_game(engine_name) {
@@ -123,10 +128,10 @@ class LMNO {
  * 1. Vowels (AEIOU) to avoid accidentally spelling an unfortunate word
  * 2. Lowercase letters (replace with corresponding capital on input)
  * 3. N (replace with M on input)
- * 4. P (replace with B on input)
- * 5. S (replace with F on input)
+ * 4. B (replace with P on input)
+ * 5. F,X (replace with S on input)
  */
-LMNO.letters = "BCDFGHJKLMQRTVWXYZ";
+LMNO.letters = "CCDDDGGGHHJKLLLLMMMMPPPPQRRRSSSTTTVVWWYYZ";
 
 const lmno = new LMNO();
 
@@ -137,8 +142,9 @@ function lmno_canonize(id) {
 
   /* Replace unused letters with nearest phonetic match. */
   id = id.replace(/N/g, 'M');
-  id = id.replace(/P/g, 'B');
-  id = id.replace(/S/g, 'F');
+  id = id.replace(/B/g, 'P');
+  id = id.replace(/F/g, 'S');
+  id = id.replace(/X/g, 'S');
 
   /* Replace unused numbers nearest visual match. */
   id = id.replace(/0/g, 'O');