go.charczuk.com@v0.0.0-20240327042549-bc490516bd1a/experiments/matchmaker/pkg/sim/ratings.go (about) 1 /* 2 3 Copyright (c) 2024 - Present. Will Charczuk. All rights reserved. 4 Use of this source code is governed by a MIT license that can be found in the LICENSE file at the root of the repository. 5 6 */ 7 8 package sim 9 10 const ratingBase = 1000 11 const ratingFactor = 400 12 13 func (s *Simulation) calculatePlayerRating(p *Player) int { 14 if p.Recent.Len() == 0 { 15 return ratingBase 16 } 17 18 lastGame, _ := p.Recent.PeekBack() 19 var opponentRating, factor int 20 playerTeam := lastGame.PlayerTeam(p.ID) 21 22 if playerTeam == lastGame.Outcome { 23 factor = ratingFactor 24 } else { 25 factor = -ratingFactor 26 } 27 if playerTeam == TeamA { 28 opponentRating = lastGame.RatingTeamB 29 } else { 30 opponentRating = lastGame.RatingTeamA 31 } 32 33 var outputRating int 34 if p.Games > 1 { 35 outputRating = int(float64(p.Rating+opponentRating+factor) / 2.0) 36 } else { 37 outputRating = opponentRating + factor 38 } 39 if outputRating <= s.Config.PlayerMinimumRatingOrDefault() { 40 outputRating = s.Config.PlayerMinimumRatingOrDefault() 41 } 42 return outputRating 43 44 } 45 46 func (s *Simulation) calculateTeamRating(team []*Player) (output int) { 47 for _, p := range team { 48 output += p.Rating 49 } 50 output = int(float64(output) / float64(len(team))) 51 return 52 }