fix: correct efficiency calculation direction
- Efficiency now starts at 100% (perfect play) and decreases toward 0% (bad play) - Formula: (optimalSteps / keystrokes) * 100 - Clamped to 0-100 range - Examples: - 100 keystrokes / 100 optimal = 100% (perfect) - 120 keystrokes / 100 optimal = 83% (good) - 200 keystrokes / 100 optimal = 50% (fair) - 500 keystrokes / 100 optimal = 20% (poor) - Default 100% when no keystrokes yet
This commit is contained in:
@@ -50,7 +50,11 @@ export function useScore({ board, hero, gameStatusManager, keyManager, gameOver
|
|||||||
}, [gameStatus, board.mazeInstanceRef]);
|
}, [gameStatus, board.mazeInstanceRef]);
|
||||||
|
|
||||||
const optimalSteps = optimalRef.current;
|
const optimalSteps = optimalRef.current;
|
||||||
const efficiency = optimalSteps > 0 ? Math.round((keystrokes / optimalSteps) * 100) : 0;
|
// 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)))
|
||||||
|
: 100;
|
||||||
|
|
||||||
// Check custom gameOver condition if provided
|
// Check custom gameOver condition if provided
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|||||||
Reference in New Issue
Block a user