Browse Source

Fix country radius, add hard mode scoring

Kirk Trombley 3 years ago
parent
commit
9bf823017b

+ 4 - 0
client/src/components/util/GameCreationForm/GameCreationForm.jsx

@@ -4,6 +4,7 @@ import { createGame } from "../../../domain/apiMethods";
 import {
   COUNTRY_RACE,
   DISTANCE,
+  HARD,
   FROZEN,
   NORMAL,
   RACE,
@@ -259,6 +260,9 @@ const GameCreationForm = ({ afterCreate, lastSettings = null }) => {
             <Item value={COUNTRY_RACE} display="🗾">
               Country Race
             </Item>
+            <Item value={HARD} display="😬">
+              Hard Mode
+            </Item>
           </Dropdown>
           <Dropdown
             selected={roundPointCap}

+ 1 - 0
client/src/domain/constants.js

@@ -17,3 +17,4 @@ export const FROZEN = "FROZEN";
 export const RACE = "RACE";
 export const COUNTRY_RACE = "COUNTRYRACE";
 export const DISTANCE = "DISTANCE";
+export const HARD = "HARD";

+ 2 - 0
server/app/api/game.py

@@ -150,6 +150,8 @@ async def submit_guess(round_number: conint(gt=0),
     if game.score_method == ScoreMethodEnum.country_race:
         score = scoring.score_country_race(target.country_code, country_code, guess.time_remaining, game.timer)
         distance = None
+    elif game.score_method == ScoreMethodEnum.hard:
+        score, distance = scoring.score_hard((target.latitude, target.longitude), (guess.lat, guess.lng))
     else:
         score, distance = scoring.score((target.latitude, target.longitude), (guess.lat, guess.lng))
     if game.round_point_cap is not None:

+ 1 - 0
server/app/schemas.py

@@ -27,6 +27,7 @@ class ClockModeEnum(str, Enum):
 class ScoreMethodEnum(str, Enum):
     distance = "DISTANCE"
     country_race = "COUNTRYRACE"
+    hard = "HARD"
 
 
 class GameConfig(CamelModel):

+ 16 - 3
server/app/scoring.py

@@ -19,10 +19,10 @@ avg_continental_rad_km = 1468.0
 # somewhat arbitrarily, if you're within 1000 km, you get at least 3000 points
 one_thousand = 1000.0
 
-# https://www.wolframalpha.com/input/?i=sqrt%28%28%28land+mass+of+earth%29+%2F+%28number+of+countries+on+earth%29%29+%2F+pi%29+in+kilometers
+# https://www.wolframalpha.com/input?i=sqrt%28%28land+mass+of+earth%29+%2F+%28number+of+countries+on+earth%29%29+%2F+pi+in+kilometers
 # this is the average "radius" of a country
 # within this radius, you get at least 4000 points
-avg_country_rad_km = 479.7
+avg_country_rad_km = 270.7
 
 # if you're within 150m, you get a perfect score of 5000
 min_dist_km = 0.15  
@@ -77,4 +77,17 @@ def score_country_race(target: str, guess: str, time_remaining: int, time_total:
         return 5000
     
     # TODO make this into an interesting curve but for now linear is fine
-    return int(5000 * (time_remaining / time_total))
+    return int(5000 * (time_remaining / time_total))
+
+
+def score_hard(target: Tuple[float, float], guess: Tuple[float, float]) -> Tuple[int, float]:
+    """
+    Takes in two (latitude, longitude) pairs and produces an int score.
+    Score is in the (inclusive) range [0, 5000]
+    Higher scores are closer.
+    Scoring is much more punishing than standard
+
+    Returns (score, distance in km)
+    """
+    dist_km = haversine.haversine(target, guess)
+    return max(0, 5000 - int(dist_km * 1000)), dist_km