39 lines
1.2 KiB
Dart
39 lines
1.2 KiB
Dart
import 'dart:math';
|
|
|
|
/// Tunables for spelling familiarity scoring and weighted selection.
|
|
abstract final class SpellingProgressPolicy {
|
|
/// Added to [familiarity_score] when the user answers the quiz correctly.
|
|
static const int correctDelta = 1;
|
|
|
|
/// Subtracted from [familiarity_score] when the user answers incorrectly.
|
|
static const int incorrectDelta = 1;
|
|
|
|
/// Base weight before familiarity adjustment.
|
|
static const double baseWeight = 1.0;
|
|
|
|
/// Weight reduction per point of positive familiarity (mastered words).
|
|
static const double penaltyPerPoint = 0.15;
|
|
|
|
/// Minimum selection weight — never zero chance.
|
|
static const double minWeight = 0.05;
|
|
|
|
/// Selection weight for a catalog item given the user's familiarity score.
|
|
static double weightForScore(int familiarityScore) {
|
|
return max(
|
|
minWeight,
|
|
baseWeight - familiarityScore * penaltyPerPoint,
|
|
);
|
|
}
|
|
|
|
/// Applies a graded quiz outcome to the stored familiarity score.
|
|
static int scoreAfterAttempt({
|
|
required int currentScore,
|
|
required bool correct,
|
|
}) {
|
|
if (correct) {
|
|
return currentScore + correctDelta;
|
|
}
|
|
return currentScore - incorrectDelta;
|
|
}
|
|
}
|