Skip to content

Commit 5b8c9cb

Browse files
committed
Updated code to recent changes on stats package
1 parent 8b2d11e commit 5b8c9cb

File tree

3 files changed

+37
-18
lines changed

3 files changed

+37
-18
lines changed

draws_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66
)
77

88
const (
9-
errTolerance float64 = 1e-06
9+
ErrTolerance float64 = 1e-06
1010
)
1111

1212
func TestDrawMarginFromDrawProbability(t *testing.T) {
@@ -24,7 +24,7 @@ func TestDrawMarginFromDrawProbability(t *testing.T) {
2424

2525
for i, p := range pDraw {
2626
e := GetDrawMargin(p, beta, 2)
27-
if math.Abs(e-epsilon[i]) > errTolerance {
27+
if math.Abs(e-epsilon[i]) > ErrTolerance {
2828
t.Error("Expected draw margin for", p, "=", epsilon[i], "got", e)
2929
}
3030
}

player.go

+27-16
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,55 @@
11
package trueskill
22

3-
import "strconv"
3+
import (
4+
"fmt"
5+
6+
"github.com/fasmat/trueskill/stats"
7+
)
48

59
// Player is a struct that reflects one contestant in a game. The skill level
610
// is assumed to be bell shaped (normal or Gaussian distributed) with a peak
711
// point µ (mu) and a spread σ (sigma). The actual skill of the player is
812
// therefore assumed to be within µ +/- 3σ with 99.7% accuracy.
913
type Player struct {
10-
id uint
11-
g Gaussian
14+
id int
15+
g stats.Gaussian
1216
}
1317

1418
// NewDefaultPlayer creates and returns a Player with default values for skill
1519
// estimation.
16-
func NewDefaultPlayer(id uint) Player {
20+
func NewDefaultPlayer(id int) Player {
1721
return Player{
1822
id: id,
19-
g: NewGaussian(DefMu, DefSig),
23+
g: stats.NewGaussian(DefMu, DefSig),
2024
}
2125
}
2226

2327
// 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 {
2529
return Player{
2630
id: id,
27-
g: NewGaussian(mu, sigma),
31+
g: stats.NewGaussian(mu, sigma),
2832
}
2933
}
3034

3135
// GetGaussian returns the Gaussian associated with the players skill.
32-
func (p *Player) GetGaussian() Gaussian {
36+
func (p *Player) GetGaussian() stats.Gaussian {
3337
return p.g
3438
}
3539

3640
// GetID returns the ID of the player
37-
func (p *Player) GetID() uint {
41+
func (p *Player) GetID() int {
3842
return p.id
3943
}
4044

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+
4151
// 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) {
4353
p.g = g
4454
return
4555
}
@@ -54,14 +64,15 @@ func (p *Player) GetSigma() float64 {
5464
return p.g.GetSigma()
5565
}
5666

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+
}
5971

72+
func (p *Player) String() (s string) {
6073
s = "Player [" + string(p.id)
6174
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())
6677
return
6778
}

team.go

+8
Original file line numberDiff line numberDiff line change
@@ -59,3 +59,11 @@ func (t *Team) GetVar() (sum float64) {
5959
}
6060
return
6161
}
62+
63+
func (t *Team) String() (s string) {
64+
s = "Team of " + string(len(t.GetPlayers())) + " Players:"
65+
for _, p := range t.GetPlayers() {
66+
s += "\t" + p.String()
67+
}
68+
return
69+
}

0 commit comments

Comments
 (0)