From bbb1edd853522ec08ffa8f938ff02e02b8630e70 Mon Sep 17 00:00:00 2001
From: Paolo Brasolin <paolo.brasolin@eurac.edu>
Date: Wed, 13 Apr 2022 12:15:22 +0200
Subject: [PATCH] feat: #fe raggedy scoring system

---
 frontend/src/js/fight_scene.ts | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)

diff --git a/frontend/src/js/fight_scene.ts b/frontend/src/js/fight_scene.ts
index 9fd92e1..b7733c4 100644
--- a/frontend/src/js/fight_scene.ts
+++ b/frontend/src/js/fight_scene.ts
@@ -384,6 +384,10 @@ export default class FightScene extends Phaser.Scene {
     this.foes.splice(this.foes.indexOf(foe), 1);
   }
 
+  nthFibonacci(n: number) {
+    return Math.round(Math.pow((1 + Math.sqrt(5)) / 2, n) / Math.sqrt(5));
+  }
+
   submitTranscription(inputStatus: InputStatus) {
     // NOTE: this ain't async to avoid any UX delay
     const { score, match } = this.findMatchingFoe(inputStatus.final);
@@ -408,7 +412,16 @@ export default class FightScene extends Phaser.Scene {
         ended_at: new Date().toISOString(),
         ended_at_gmtm: this.getGameTime(),
       });
-      this.updateScore(+10);
+      const lengthScore = this.nthFibonacci(
+        1 + match.beWord.ocr_transcript.length,
+      );
+      const accuracyBonus = score;
+      const speedBonus =
+        2 -
+        (inputStatus.ended_at_gmtm - match.beClue.began_at_gmtm) /
+          (match.duration * 1000);
+      this.updateScore(Math.round(lengthScore * accuracyBonus * speedBonus));
+
       this.popFoe(match);
       match.handleSuccess();
       this.hud.showSubmitFeedback("green", inputStatus.final);
-- 
GitLab