-
Notifications
You must be signed in to change notification settings - Fork 5
/
player.go
78 lines (65 loc) · 1.87 KB
/
player.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package trueskill
import (
"fmt"
"github.com/fasmat/trueskill/stats"
)
// Player is a struct that reflects one contestant in a game. The skill level
// is assumed to be bell shaped (normal or Gaussian distributed) with a peak
// point µ (mu) and a spread σ (sigma). The actual skill of the player is
// therefore assumed to be within µ +/- 3σ with 99.7% accuracy.
type Player struct {
id int
g stats.Gaussian
}
// NewDefaultPlayer creates and returns a Player with default values for skill
// estimation.
func NewDefaultPlayer(id int) Player {
return Player{
id: id,
g: stats.NewGaussian(DefMu, DefSig),
}
}
// NewPlayer creates and returns a Player with a specified skill level.
func NewPlayer(id int, mu, sigma float64) Player {
return Player{
id: id,
g: stats.NewGaussian(mu, sigma),
}
}
// GetGaussian returns the Gaussian associated with the players skill.
func (p *Player) GetGaussian() stats.Gaussian {
return p.g
}
// GetID returns the ID of the player
func (p *Player) GetID() int {
return p.id
}
// GetSkill returns the skill of the player as single number
func (p *Player) GetSkill() float64 {
g := p.GetGaussian()
return g.GetConservativeEstimate()
}
// UpdateSkill updates the skill rating of player to the provided Gaussian.
func (p *Player) UpdateSkill(g stats.Gaussian) {
p.g = g
return
}
// GetMu is a convenience wrapper for Gaussian.GetMu()
func (p *Player) GetMu() float64 {
return p.g.GetMu()
}
// GetSigma is a convenience wrapper for Gaussian.GetSigma()
func (p *Player) GetSigma() float64 {
return p.g.GetSigma()
}
// GetVar is a convenience wrapper for Gaussian.GetVar()
func (p *Player) GetVar() float64 {
return p.g.GetVar()
}
func (p *Player) String() (s string) {
s = "Player [" + string(p.id)
s += "] Skill-Estimate:"
s += fmt.Sprintf(" %2.4f", p.GetSkill())
s += fmt.Sprintf("(μ=%2.4f, σ=%2.4f)", p.GetMu(), p.GetSigma())
return
}