Szabo Ivan c168da359e implement complete frontend:
- add lobby, game, leaderboard, results pages
- add scripts: storage, lobby, game, drawing, scoring, countries
- add styles: main, lobby, game
- unify header/footer across all pages
- show lobby name in lobby view
- remove clear board from leaderboard
2026-05-05 13:01:14 +02:00

42 lines
1.4 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// scoring.js — accuracy calculation
const Scoring = (() => {
/**
* Calculate score from drawn path points.
* MVP: fake score based on number of points drawn (effort-based).
* TODO: replace with real compareShapes() using polygon overlap.
*/
function calculateScore(drawnPoints) {
if (!drawnPoints || drawnPoints.length < 10) return 0;
// Fake scoring: reward effort + randomness so it feels real
const effort = Math.min(drawnPoints.length / 300, 1); // 01
const base = 40 + Math.round(effort * 45); // 4085
const jitter = Math.round((Math.random() - 0.5) * 14); // ±7
const score = Math.max(0, Math.min(100, base + jitter));
return score;
}
/**
* Stub for real shape comparison (future).
* drawnPoints: [{x,y}, ...]
* referencePolygon: [{x,y}, ...] (normalised 01 coords)
*/
function compareShapes(_drawnPoints, _referencePolygon) {
// TODO: implement IoU (Intersection over Union) or
// Hausdorff distance for polygon comparison.
return 0;
}
function getGrade(score) {
if (score >= 90) return { label: "S", color: "#f0b429" };
if (score >= 75) return { label: "A", color: "#41b869" };
if (score >= 60) return { label: "B", color: "#1a7fc4" };
if (score >= 40) return { label: "C", color: "#7a9aaa" };
return { label: "D", color: "#e05c5c" };
}
return { calculateScore, compareShapes, getGrade };
})();