-
Notifications
You must be signed in to change notification settings - Fork 3
/
rating.go
59 lines (52 loc) · 975 Bytes
/
rating.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
//
// The USCF ELO implementation. For more details, see:
//
// http://www.glicko.net/ratings/rating.system.pdf
//
package uscf
type EloRating struct {
Score float64
Prov bool
}
// Construct a new rating
func NewRating() *EloRating {
return &EloRating{
750,
true,
}
}
func NewRatingEstimated(val float64) *EloRating {
return &EloRating{
val,
false,
}
}
// Convert from a FIDE ELO Rating.
func FromFide(fide float64) *EloRating {
converted := 0.0
if fide <= 2000 {
converted = fide*0.76 + 560
} else {
converted = fide + 80
}
return &EloRating{
converted,
false,
}
}
// For compatibility with the ratable interface.
func (t *EloRating) NumericScore() float64 {
return t.Score
}
// Players playing ol
func (t *EloRating) IsProvisional() bool {
return t.Prov
}
// Sets the provisional status from the number of games played
func (t *EloRating) SetProvFromGames(games int64) {
if games < 8 {
t.Prov = true
} else {
t.Prov = false
}
}