Changed to smaller float
This commit is contained in:
@@ -19,13 +19,13 @@ import (
|
||||
)
|
||||
|
||||
var eloCfg = struct {
|
||||
Mu0 float64
|
||||
Scale float64 // KNew applies to players during burn-in (first BurnInGames matches).
|
||||
KNew float64
|
||||
KStd float64
|
||||
Mu0 float32
|
||||
Scale float32 // KNew applies to players during burn-in (first BurnInGames matches).
|
||||
KNew float32
|
||||
KStd float32
|
||||
BurnInGames int
|
||||
RatingFloor float64
|
||||
MaxPerMatchDelta float64
|
||||
RatingFloor float32
|
||||
MaxPerMatchDelta float32
|
||||
MaxGoals int
|
||||
}{
|
||||
Mu0: 1500,
|
||||
@@ -41,16 +41,16 @@ var eloCfg = struct {
|
||||
type Team struct {
|
||||
Players []*repository.GameUser
|
||||
Score int
|
||||
AverageRating float64
|
||||
AverageRating float32
|
||||
}
|
||||
|
||||
func NewTeam(players []*repository.GameUser, score int) *Team {
|
||||
var t1s float64 = 0
|
||||
var t1s float32 = 0
|
||||
for _, player := range players {
|
||||
t1s += float64(player.User.Elo)
|
||||
t1s += float32(player.User.Elo)
|
||||
|
||||
}
|
||||
t1a := t1s / float64(len(players))
|
||||
t1a := t1s / float32(len(players))
|
||||
|
||||
return &Team{Players: players, Score: score, AverageRating: t1a}
|
||||
}
|
||||
@@ -80,9 +80,9 @@ func GetNewElo(t1, t2 *Team) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func CalculateRating(rA, rB float64, goalsA, goalsB, gamesA int) (newrA float64, err error) {
|
||||
func CalculateRating(rA, rB float32, goalsA, goalsB, gamesA int) (newrA float32, err error) {
|
||||
// Observed score (no draws)
|
||||
var sA float64
|
||||
var sA float32
|
||||
if goalsA > goalsB {
|
||||
sA = 1.0
|
||||
} else {
|
||||
@@ -105,7 +105,7 @@ func CalculateRating(rA, rB float64, goalsA, goalsB, gamesA int) (newrA float64,
|
||||
eA := expected(eloCfg.Scale, rA, rB)
|
||||
mov := movFactor(rA, rB, diff)
|
||||
|
||||
var Keff float64
|
||||
var Keff float32
|
||||
if gamesA <= eloCfg.BurnInGames {
|
||||
Keff = eloCfg.KNew
|
||||
} else {
|
||||
@@ -124,13 +124,15 @@ func CalculateRating(rA, rB float64, goalsA, goalsB, gamesA int) (newrA float64,
|
||||
return rA + delta, nil
|
||||
}
|
||||
|
||||
// expected returns the win probability for player A against B
|
||||
func expected(scale, rA, rB float64) float64 {
|
||||
return 1.0 / (1.0 + math.Pow(10.0, -(rA-rB)/scale))
|
||||
func expected(scale, rA, rB float32) float32 {
|
||||
return float32(
|
||||
1.0 / (1.0 + math.Pow(10.0, float64(-(rA-rB)/scale))),
|
||||
)
|
||||
}
|
||||
|
||||
// movFactor returns a bounded margin-of-victory multiplier.
|
||||
func movFactor(rA, rB float64, diff int) float64 {
|
||||
func movFactor(rA, rB float32, diff int) float32 {
|
||||
fd := float64(diff)
|
||||
return math.Log(fd+1.0) * 2.2 / (math.Abs(rA-rB)*0.001 + 2.2)
|
||||
return float32(
|
||||
math.Log(fd+1.0) * 2.2 / (math.Abs(float64(rA-rB))*0.001 + 2.2),
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user