From 7352eff726cbeb1e0b18d02e0d33dd5478d50ab7 Mon Sep 17 00:00:00 2001 From: Andre Padez Date: Sun, 2 Nov 2025 17:15:38 +0000 Subject: [PATCH] feat: add intermediate efficiency calculation for real-time feedback MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 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) --- src/useScore/useScore.ts | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/useScore/useScore.ts b/src/useScore/useScore.ts index 8f58a18..e1621f6 100644 --- a/src/useScore/useScore.ts +++ b/src/useScore/useScore.ts @@ -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