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