mirror of
https://github.com/jcreek/CosmicClash.git
synced 2026-09-14 07:22:05 +00:00
feat: add authoritative rating outcome scoring
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user