-
Notifications
You must be signed in to change notification settings - Fork 14
/
score.go
85 lines (63 loc) · 1.66 KB
/
score.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
79
80
81
82
83
84
85
// Copyright (c) 2014-2018 by Michael Dvorkin. All Rights Reserved.
// Use of this source code is governed by a MIT-style license that can
// be found in the LICENSE file.
//
// I am making my contributions/submissions to this project solely in my
// personal capacity and am not conveying any rights to any intellectual
// property of any third parties.
package donna
type Score struct {
midgame int
endgame int
}
// Reference methods that change the score receiver in place and return a
// pointer to the updated score.
func (s *Score) clear() *Score {
s.midgame, s.endgame = 0, 0
return s
}
func (s *Score) add(score Score) *Score {
s.midgame += score.midgame
s.endgame += score.endgame
return s
}
func (s *Score) sub(score Score) *Score {
s.midgame -= score.midgame
s.endgame -= score.endgame
return s
}
func (s *Score) apply(weight Score) *Score {
s.midgame = s.midgame * weight.midgame / 100
s.endgame = s.endgame * weight.endgame / 100
return s
}
func (s *Score) adjust(n int) *Score {
s.midgame += n
s.endgame += n
return s
}
func (s *Score) scale(n int) *Score {
s.midgame = s.midgame * n / 100
s.endgame = s.endgame * n / 100
return s
}
// Value methods that return newly updated score value.
func (s Score) plus(score Score) Score {
s.midgame += score.midgame
s.endgame += score.endgame
return s
}
func (s Score) minus(score Score) Score {
s.midgame -= score.midgame
s.endgame -= score.endgame
return s
}
func (s Score) times(n int) Score {
s.midgame *= n
s.endgame *= n
return s
}
// Calculates normalized score based on the game phase.
func (s Score) blended(phase int) int {
return (s.midgame * phase + s.endgame * (256 - phase)) / 256
}