// 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); // 0–1 const base = 40 + Math.round(effort * 45); // 40–85 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 0–1 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 }; })();