Browse Source

Implement diff_tiered gen method, with all tiers as estonia for the moment

Kirk Trombley 3 years ago
parent
commit
45ea813455
1 changed files with 33 additions and 5 deletions
  1. 33 5
      server/app/point_gen/__init__.py

+ 33 - 5
server/app/point_gen/__init__.py

@@ -34,6 +34,20 @@ class ExhaustedSourceError(Exception):
     pass
 
 
+DIFFICULTY_1 = ["ee"] # TODO actually fill these out
+DIFFICULTY_2 = ["ee"]
+DIFFICULTY_3 = ["ee"]
+DIFFICULTY_4 = ["ee"]
+DIFFICULTY_5 = ["ee"]
+DIFFICULTY_X = ["ee"] # TODO all islands
+DIFFICULTY_TIER_ORDER = (
+    DIFFICULTY_1, DIFFICULTY_2, DIFFICULTY_3, DIFFICULTY_4,
+    DIFFICULTY_5,
+    DIFFICULTY_4, DIFFICULTY_3, DIFFICULTY_2, DIFFICULTY_1,
+    DIFFICULTY_X,
+)
+
+
 class PointStore:
     def __init__(self, 
                  cache_targets: Dict[Tuple[GenMethodEnum, CountryCode], int],
@@ -124,12 +138,26 @@ class PointStore:
         In the event that the configured source cannot reasonably supply enough points,
         most likely due to time constraints, this will raise an ExhaustedSourceError.
         """
-        # in the case of using the "difficulty tiered" generator there is some special logic
-        if config.generation_method == GenMethodEnum.diff_tiered:
-            # TODO - actually implement this, for now just fail
-            raise ExhaustedSourceError
         try:
-            point_tasks = [self.get_point(config.generation_method, config.country_lock) for _ in range(config.rounds)]
+            if config.generation_method == GenMethodEnum.diff_tiered:
+                # in the case of using the "difficulty tiered" generator there is some special logic
+                # assume that, in general, we want 10 points (4 normal rounds going up in difficulty, 1 max difficulty round, 4 normal going down, 1 nightmare tier)
+                if config.rounds != len(DIFFICULTY_TIER_ORDER):
+                    # TODO would probably be nice to relax this restriction at some point
+                    raise ExhaustedSourceError
+
+                def make_point_task(tier):
+                    country_lock = random.choice(tier)
+                    if country_lock in random_street_view.VALID_COUNTRIES:
+                        return self.get_point(GenMethodEnum.rsv, country_lock)
+                    elif country_lock in urban_centers.VALID_COUNTRIES:
+                        return self.get_point(GenMethodEnum.urban, country_lock) 
+                    else:
+                        raise ExhaustedSourceError
+
+                point_tasks = [make_point_task(tier) for tier in DIFFICULTY_TIER_ORDER]
+            else:
+                point_tasks = [self.get_point(config.generation_method, config.country_lock) for _ in range(config.rounds)]
             gathered = asyncio.gather(*point_tasks)
             return await asyncio.wait_for(gathered, 60)
             # TODO - it would be nice to keep partially generated sets around if there's a timeout or exhaustion