Add scoring and pool validation

This commit is contained in:
ameer
2026-05-02 02:59:34 +08:00
parent f689b8f297
commit a4061331e5
2 changed files with 158 additions and 0 deletions

View File

@@ -1 +1,40 @@
"""Score functions."""
from __future__ import annotations
from collections.abc import Callable
ScoreFn = Callable[[bool, int, int], int]
SCORE_FNS: dict[str, ScoreFn] = {}
def register(name: str) -> Callable[[ScoreFn], ScoreFn]:
def decorator(func: ScoreFn) -> ScoreFn:
SCORE_FNS[name] = func
return func
return decorator
@register("linear_decay")
def linear_decay(correct: bool, elapsed_ms: int, time_limit_ms: int) -> int:
if not correct:
return 0
elapsed_ms = max(0, min(elapsed_ms, time_limit_ms))
return round(1000 * (1 - 0.5 * elapsed_ms / time_limit_ms))
@register("flat")
def flat(correct: bool, elapsed_ms: int, time_limit_ms: int) -> int:
return 1000 if correct else 0
@register("exponential_decay")
def exponential_decay(correct: bool, elapsed_ms: int, time_limit_ms: int) -> int:
if not correct:
return 0
import math
elapsed_ms = max(0, min(elapsed_ms, time_limit_ms))
decay = math.exp(-2 * elapsed_ms / time_limit_ms)
return round(1000 * (0.5 + 0.5 * decay))