Browse Source

fixing some spacing and improving scoring

Kirk Trombley 5 years ago
parent
commit
ba41413592
2 changed files with 15 additions and 11 deletions
  1. 6 2
      server/lib.py
  2. 9 9
      ui/src/components/pre-round.component.jsx

+ 6 - 2
server/lib.py

@@ -33,6 +33,7 @@ mean_earth_radius_km = (6378 + 6357) / 2
 # the farthest you can be from another point on Earth
 antipode_dist_km = math.pi * mean_earth_radius_km
 min_dist_km = 0.15 # if you're within 150m, you get a perfect score
+max_dist_km = antipode_dist_km / 2 # if you're more than 1/4 of the Earth away, you get 0
 perfect_score = 5000
 
 
@@ -45,6 +46,9 @@ def score(target, guess):
     dist_km = haversine.haversine(target, guess)
     if dist_km <= min_dist_km:
         return perfect_score
+    
+    if dist_km >= max_dist_km:
+        return 0
 
-    # TODO might want to try something logarithmic here eventually
-    return int(perfect_score * (1 - (dist_km / antipode_dist_km)))
+    # TODO probably still needs tweaking
+    return int(perfect_score * (1 - (dist_km / max_dist_km) ** 2))

+ 9 - 9
ui/src/components/pre-round.component.jsx

@@ -4,11 +4,11 @@ class PreRound extends React.Component {
   copyGameId() {
     const { gameId } = this.props;
     const textarea = this.textarea;
-		textarea.value = gameId;
+    textarea.value = gameId;
     textarea.select();
     document.execCommand("copy");
   }
-
+  
   render() {
     const { gameId, playerName, onStart } = this.props;
     return (
@@ -18,14 +18,14 @@ class PreRound extends React.Component {
           Game Code: {gameId} <button onClick={() => this.copyGameId()}>Copy</button>
         </p>
         <button onClick={onStart}>Start Game</button>
-				<textarea
-					ref={textarea => this.textarea = textarea}
-					style={{ position: "absolute", top: "-1000px" }}
-				/>
+        <textarea
+          ref={textarea => this.textarea = textarea}
+          style={{ position: "absolute", top: "-1000px" }}
+        />
       </div>
-    );
+      );
+    }
   }
-}
   
-export default PreRound;
+  export default PreRound;