Repository: makhidkarun/traveller_pyroute

Issue:
Update / Fix some missing allegiance codes
The following are changes to allegiance codes that don't work correctly with the current PyRoute:

* `Kc` is a "K'kree Client state and should be a non-aligned 
* The sophont code for the K'kree is "KXkr, which only affects the upload to the wiki. 
* The SELK allegiance should have a default sophont code of "Lith" (Lithkin)
* The Krotan Protectorate (KrPr) should have a default sophont code of "Krot" (Krotan)
* Droyne worlds (Dr, NaDr) should have a default sophont code of "Droy" (Droyne) 
* Worlds of Taakas Yh'Drak (TY) should have a default sophont code of "Drak" (Drakaran)
* Add a "----" (four dash) unaligned, unpopulated world 
* Add a "NaZh" for a non-aligned Zhodani world with a default sophont code of "Zhod" 
* Add a "NaHu" for a non-aligned Human dominated world with a default sophont code "Huma"
* 

Discussion:

Patch:
diff --git a/PyRoute/AllyGen.py b/PyRoute/AllyGen.py
index 1f0dca2..8d9d1c5 100644
--- a/PyRoute/AllyGen.py
+++ b/PyRoute/AllyGen.py
@@ -16,9 +16,9 @@ class AllyGen(object):
     """
     classdocs
     """
-    noOne = ['--', '??', 'Xx']
-    nonAligned = ['Na', 'Ns', 'Va', 'Cs', 'Hc',
-                  'NaHv', 'NaDr', 'NaVa', 'NaAs', 'NaXx', 'NaXX', "NaSo",
+    noOne = ['--', '----', '??', 'Xx']
+    nonAligned = ['Na', 'Ns', 'Va', 'Cs', 'Hc', 'Kc'
+                  'NaHu', 'NaHv', 'NaDr', 'NaVa', 'NaAs', 'NaXx', 'NaXX', "NaSo", "NaZh",
                   'VaEx',
                   'CsCa', 'CsHv', 'CsIm', 'CsMP', 'CsVa', 'CsZh', 'CsRe', 'CsMo', 'CsRr', "CsTw",
                   'Wild']
@@ -34,7 +34,12 @@ class AllyGen(object):
                     'JAOz', 'JAsi', 'JCoK', 'JHhk', 'JLum', 'JMen',
                     'JPSt', 'JRar', 'JUkh', 'JuHl', 'JuRu', 'JVug'),
                    ('Ke', 'KoEm'),
-                   ("Kk", "KkTw", "Kc", "KC"),
+                   ("K1",),
+                   ("K2",),
+                   ("K3",),
+                   ("K4",),
+                   ("KC",),
+                   ("Kk", "KkTw", "KO"),
                    ('So', 'SoCf', 'SoBF', 'SoCT', 'SoFr', 'SoHn', 'SoKv', 'SoNS',
                     'SoQu', 'SoRD', 'SoRz', 'SoWu' ),
                    ('Lp', 'CoLp'),
@@ -47,13 +52,18 @@ class AllyGen(object):
 
     default_population = {
         "As": "Asla",
+        "Cr": "Huma",
+        "Dr": "Droy",
         "Hv": "Hive",
         "JP": "Huma",
-        "Kk": "KXKr",
+        "Kk": "KXkr",
         "Pd": "Piri",
         "Te": "Piri",
         "Tk": "Piri",
+        "TY": "Drak",
         "Va": "Varg",
+        "Vb": "Varg",
+        "Vc": "Varg",
         "Wc": "Droy",
         "Yt": "Yask",
         "Zh": "Zhod",
@@ -74,12 +84,15 @@ class AllyGen(object):
         "KaWo": "Karh",
         "KhLe": "Sydi",
         "KoEm": "Jaib",
+        "KrPr": "Krot",
         "MaEm": "Mask",
         "MaPr": "MalX",
         "NaAs": "Asla",
+        "NaDr": "Droy",
         "NaHv": "Hive",
         "NaVa": "Varg",
         "OcWs": "Stal",
+        "SELK": "Lith",
         "SaCo": "Vlaz",
         "Sark": "Varg",
         "SwFW": "Swan",
@@ -88,6 +101,42 @@ class AllyGen(object):
         "ZhCa": "Vlaz"
     }
 
+    alleg_border_colours = {
+        "Im": "red",
+        "As": "yellow",
+        "Cr": "gold",
+        "Dr": None,
+        "Hv": "violet",
+        "JP": "blue",
+        "Kr": "blue",
+        "K1": "emerald",
+        "K2": "emerald",
+        "K3": "emerald",
+        "K4": "darkolive",
+        "KC": "emerald",
+        "Kk": "green",
+        "Rr": "blue",
+        "So": "orange",
+        "TY": "purple",
+        "Va": "olive",
+        "Vb": "olive",
+        "Vc": "olive",
+        "Wc": "lightblue",
+        "Zh": "blue",
+        "--": None,
+        "Na": None,
+        "----": None,
+        "NaHu": None,
+        "NaXX": None,
+        "NaZh": None,
+        "CsIm": None,
+        "DaCf": "lightblue",
+        "SwCf": "blue",
+        "VAug": "olive",
+        "VDzF": "olive",
+        "NONE": "white",  # Default color
+    }
+
 
     def __init__(self, galaxy):
         """
@@ -95,7 +144,7 @@ class AllyGen(object):
         """
         self.galaxy = galaxy
         self.borders = {}  # 2D array using (q,r) as key, with flags for data
-        self.allyMap = {}
+        self.allyMap = {}  # 2D array using (q,r) as key, with allegiance code as data
         self.logger = logging.getLogger('PyRoute.AllyGen')
 
     @staticmethod
@@ -136,7 +185,7 @@ class AllyGen(object):
 
     @staticmethod
     def population_align(alg, name):
-        # Try get the default cases
+        # Try getting the default cases
         code = AllyGen.default_population.get(alg, AllyGen.default_population.get(AllyGen.same_align(alg), None))
 
         # Handle the special cases.
@@ -148,6 +197,8 @@ class AllyGen(object):
                     code = 'Hive'
                 elif 'Vargr' in name:
                     code = 'Varg'
+                elif 'Zhodani' in name:
+                    code = 'Zhod'
                 elif 'Human' in name:
                     code = 'Huma'
                 else:
@@ -165,7 +216,7 @@ class AllyGen(object):
     def sort_allegiances(alg_list, base_match_only):
         # The logic: 
         # base_match_only == true -> --ally-match=collapse
-        # only what the base allegiances
+        # only what matches the base allegiances
         # base_match_only == false -> --ally-match=separate
         # want the non-base code or the base codes for single code allegiances. 
 
@@ -218,6 +269,8 @@ class AllyGen(object):
 
     def _generate_borders(self, allyMap):
         """
+        This is deep, dark magic.  Futzing with this will break the border drawing process.
+
         Convert the allyMap, which is a dict of (q,r) keys with allegiance codes
         as values, into the borders, which is a dict of (q.r) keys with flags
         indicating which side of the hex needs to have a border drawn on:


Test patch:
diff --git a/Tests/testAllyGen.py b/Tests/testAllyGen.py
index f930749..3e03db8 100644
--- a/Tests/testAllyGen.py
+++ b/Tests/testAllyGen.py
@@ -29,5 +29,10 @@ class testAllyGen(unittest.TestCase):
     def test_are_owned_allies_diff_parent(self):
         self.assertFalse(AllyGen.are_owned_allies('ZhAx', 'HvFd'))
 
+    def test_zhodani_in_name_of_population_alignment(self):
+        expected = 'Zhod'
+        actual = AllyGen.population_align('Na', 'Zhodani')
+        self.assertEqual(expected, actual)
+
 if __name__ == '__main__':
     unittest.main()