-
Notifications
You must be signed in to change notification settings - Fork 5
/
team.go
69 lines (58 loc) · 1.49 KB
/
team.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
package trueskill
// Team is a composition of players that play together. The skill of a team
// (µ and σ) is determined by the skills of the players that form the team.
type Team struct {
players []Player
}
// NewEmptyTeam creates a team without any players. To add players use
// AddPlayers.
func NewEmptyTeam() Team {
return Team{
players: make([]Player, 0),
}
}
// NewTeam creates a team from a slice of players.
func NewTeam(p []Player) (t Team) {
t.players = p
return
}
// Size returns the number of players in the team
func (t *Team) Size() int {
return len(t.players)
}
// AddPlayer adds a single player to the team.
func (t *Team) AddPlayer(p Player) {
t.players = append(t.players, p)
return
}
// AddPlayers adds players to the team.
func (t *Team) AddPlayers(p []Player) {
t.players = append(t.players, p...)
return
}
// GetPlayers returns the players the team is composed of.
func (t *Team) GetPlayers() (p []Player) {
return t.players
}
// TODO: Add functions to remove players from a team
// GetMu returns the sum of all means of the team
func (t *Team) GetMu() (sum float64) {
for _, p := range t.players {
sum += p.GetMu()
}
return
}
// GetVar returns the combined variance of the team
func (t *Team) GetVar() (sum float64) {
for _, p := range t.players {
sum += p.GetSigma() * p.GetSigma()
}
return
}
func (t *Team) String() (s string) {
s = "Team of " + string(len(t.GetPlayers())) + " Players:"
for _, p := range t.GetPlayers() {
s += "\t" + p.String()
}
return
}