feat: add intermediate efficiency calculation for real-time feedback

- While keystrokes ≤ optimalSteps: show progress (keystrokes/optimal * 100)
  - Players see efficiency climbing from 0→100% as they play well
  - Provides real-time feedback during navigation
- After keystrokes > optimalSteps: show degradation (optimal/keystrokes * 100)
  - Efficiency smoothly decreases below 100%
- Examples with 100 optimal steps:
  - At 25 keystrokes: 25% (progress)
  - At 50 keystrokes: 50% (halfway)
  - At 100 keystrokes: 100% (optimal reached!)
  - At 120 keystrokes: 83% (slightly over)
  - At 200 keystrokes: 50% (double the optimal)
This commit is contained in:
2025-11-02 17:15:38 +00:00
parent c1f578be42
commit 7352eff726
+9 -3
View File
@@ -51,9 +51,15 @@ export function useScore({ board, hero, gameStatusManager, keyManager, gameOver
const optimalSteps = optimalRef.current;
// Efficiency: 100% = optimal play, 0% = worst case
// Formula: (optimalSteps / keystrokes) * 100, clamped to 0-100
const efficiency = optimalSteps > 0 && keystrokes > 0
? Math.max(0, Math.min(100, Math.round((optimalSteps / keystrokes) * 100)))
// - If keystrokes <= optimalSteps: intermediate calc showing progress toward goal
// Formula: (keystrokes / optimalSteps) * 100 (shows how far along optimal path)
// - If keystrokes > optimalSteps: inverse calc showing how much over optimal
// Formula: (optimalSteps / keystrokes) * 100 (shows excess usage)
// Result clamped to 0-100
const efficiency = optimalSteps > 0 && keystrokes > 0
? keystrokes <= optimalSteps
? Math.round((keystrokes / optimalSteps) * 100)
: Math.max(0, Math.round((optimalSteps / keystrokes) * 100))
: 100;
// Check custom gameOver condition if provided