feat: add authoritative rating outcome scoring

This commit is contained in:
Josh Creek
2026-08-31 21:07:04 +01:00
parent 63332435d2
commit e13a64756f
3 changed files with 49 additions and 1 deletions
+27
View File
@@ -30,6 +30,33 @@ type Opponent struct {
Score float64
}
type MatchOutcome struct {
Team0Score int
Team1Score int
Overtime bool
Abandoners map[string]bool
}
func ScoreForPlayer(outcome MatchOutcome, playerID string, team int) (float64, error) {
if playerID == "" || (team != 0 && team != 1) || outcome.Team0Score < 0 || outcome.Team1Score < 0 {
return 0, fmt.Errorf("invalid match outcome")
}
if outcome.Abandoners[playerID] {
return 0, nil
}
if outcome.Team0Score == outcome.Team1Score {
return 0.5, nil
}
winner := 0
if outcome.Team1Score > outcome.Team0Score {
winner = 1
}
if team == winner {
return 1, nil
}
return 0, nil
}
type RankedProfile struct {
Rating
RankedGames int