]> git.cworth.org Git - empires-server/commitdiff
Tweak game-ID generation toward more frequently used letters
authorCarl Worth <cworth@cworth.org>
Sun, 14 Jun 2020 16:37:27 +0000 (09:37 -0700)
committerCarl Worth <cworth@cworth.org>
Thu, 25 Jun 2020 16:11:51 +0000 (09:11 -0700)
I'd noticed recently that game IDs seemed to have more Qs, Zs, and Js
than it felt like they should. In fact, all letters were being given
an equal probability of appearing, but that doesn't match our
expectation that some letters should be "rare".

In this commit we tweak the selection of letters toward more "common"
letters. This should hopefully give game ID strings that are slightly
more "friendly" looking in general.

The set of available game ID values isn't reduced here (at least
because of the above, but it is reduced because of part of what is
described below), but when many game IDs are allocated it can now take
longer for the random-selection algorithm to find an available one.

We also switch from using 'B' and 'F'/'X' to instead using 'P' and
'S', again favoring letters that English speakers expect to be
"common".

This actually fixes a bug which I hadn't noticed before, in that the
code has always been replacing a '5' in the input with 'S' but doing
that after 'S' was replaced with 'F', so any input with '5' would not
be mapped as intended. Now an input of '5' will work in the place of
'S'.

lmno.js

diff --git a/lmno.js b/lmno.js
index 71ccc58165298b3e313fa7f60e0422fb19e3b7b6..c2942a419446562c0da4a0b11ec23318828ef002 100644 (file)
--- a/lmno.js
+++ b/lmno.js
@@ -128,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();
 
@@ -142,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');