/
score.go
243 lines (227 loc) · 5.99 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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
package drum
import (
"image/color"
"github.com/hndada/gosu/input"
"github.com/hndada/gosu/mode"
)
// Todo: let users use custom windows
// Todo: need to find best value for DotHitWindow
var (
Cool = mode.Judgment{Flow: 0.01, Acc: 1, Window: 25}
Good = mode.Judgment{Flow: 0.01, Acc: 0.25, Window: 60}
Miss = mode.Judgment{Flow: -1, Acc: 0, Window: 100}
DotHitWindow int64 = 35 // 25
)
var Judgments = []mode.Judgment{Cool, Good, Miss}
var JudgmentColors = []color.NRGBA{
mode.ColorCool,
mode.ColorGood,
mode.ColorBad,
}
const (
Cools = iota // Stands for Cool counts.
Goods
Misses
CoolPartials
GoodPartials
TickHits
TickDrops
)
var JudgmentCountKinds = []string{
"Cools", "Goods", "Misses",
"CoolPartials", "GoodPartials",
"TickHits", "TickDrops",
}
// When hit big notes only with one press, the note gives half the score only.
// For example, when hit a Big note by one press with Good, it will gives 0.25 * 0.5 = 0.125.
// No Flow decrease for hitting Big note by one press.
// When one side of judgment is Cool, Good on the other hand, overall judgment of Big note goes Good.
// In other word, to get Cool at Big note, you have to hit it Cool with both sides.
// Todo: judge for Big note when judgment goes different depending on selecting 2 key actions
const MaxBigHitDuration = 25
func (s *ScenePlay) UpdateKeyActions() {
var hits [4]bool
for k := range hits {
if s.KeyLogger.KeyAction(k) == input.Hit {
hits[k] = true
s.LastHitTimes[k] = s.Now
}
}
for color, keys := range [][]int{{1, 2}, {0, 3}} {
if hits[keys[0]] || hits[keys[1]] {
if hits[keys[0]] && s.Now-s.LastHitTimes[keys[1]] < MaxBigHitDuration ||
hits[keys[1]] && s.Now-s.LastHitTimes[keys[0]] < MaxBigHitDuration {
s.KeyActions[color] = Big
} else {
s.KeyActions[color] = Regular
}
} else {
s.KeyActions[color] = SizeNone
}
}
// for color, a := range s.KeyActions {
// if a != SizeNone {
// fmt.Printf("%d: %s at color %s\n", s.time, []string{"regular", "hit"}[a], []string{"red", "blue"}[color])
// }
// }
}
func IsColorHit(actions [2]int, color int) bool {
return actions[color] != SizeNone
}
func IsOtherColorHit(actions [2]int, color int) bool {
switch color {
case Red:
return IsColorHit(actions, Blue)
case Blue:
return IsColorHit(actions, Red)
}
return false
}
func VerdictNote(n *Note, actions [2]int, td int64) (j mode.Judgment, big bool) {
if td > Miss.Window {
return
}
if td < -Miss.Window {
return Miss, false
}
if IsOtherColorHit(actions, n.Color) {
return Miss, false
}
if !IsColorHit(actions, n.Color) {
return
}
j = mode.Judge(Judgments, input.Hit, td)
if n.Size == Big && actions[n.Color] == Big {
big = true
}
// fmt.Println(n.Time, n.Size, n.Color, actions, j, big)
return
}
func (s *ScenePlay) MarkNote(n *Note, j mode.Judgment, big bool) {
const (
flowBonus = 2
)
if j == Miss {
s.BreakCombo()
} else {
s.AddCombo()
}
s.CalcScore(mode.Flow, j.Flow, flowBonus*n.Weight())
if n.Size == Big && !big {
j.Acc /= 2
}
s.CalcScore(mode.Acc, j.Acc, n.Weight())
switch j.Window {
case Cool.Window:
s.JudgmentCounts[Cools]++
if n.Size == Big && !big {
s.JudgmentCounts[CoolPartials]++
}
case Good.Window:
s.JudgmentCounts[Goods]++
if n.Size == Big && !big {
s.JudgmentCounts[GoodPartials]++
}
case Miss.Window:
s.JudgmentCounts[Misses]++
}
n.scored = true
s.StagedNote = s.StagedNote.Next
}
func VerdictDot(dot *Dot, actions [2]int, td int64) (marked int) {
switch {
case td < -DotHitWindow:
return DotMiss
case td < DotHitWindow:
if actions[Red] != SizeNone || actions[Blue] != SizeNone {
return DotHit
}
}
return DotReady
}
// Roll affects only at Extra score.
func (s *ScenePlay) MarkDot(dot *Dot, marked int) {
switch marked {
case DotHit:
s.JudgmentCounts[TickHits]++
s.CalcScore(mode.Extra, 1, dot.Weight())
dot.scored = DotHit
case DotMiss:
s.JudgmentCounts[TickDrops]++
s.CalcScore(mode.Extra, 0, dot.Weight())
dot.scored = DotMiss
}
if marked != DotReady {
s.StagedDot = s.StagedDot.Next
}
}
func VerdictShake(shake *Note, actions [2]int, waitingColor int) (nextColor int) {
if waitingColor == Red || waitingColor == ColorNone {
if actions[Red] != SizeNone {
return Blue
}
}
if waitingColor == Blue || waitingColor == ColorNone {
if actions[Blue] != SizeNone {
return Red
}
}
return waitingColor
}
// Shake affects only at Extra score.
func (s *ScenePlay) MarkShake(shake *Note, flush bool) {
if flush {
remained := shake.Tick - shake.HitTick
s.JudgmentCounts[TickDrops] += remained
s.CalcScore(mode.Extra, 0, shake.Weight()*float64(remained)/float64(shake.Tick))
} else {
shake.HitTick++
s.JudgmentCounts[TickHits]++
s.CalcScore(mode.Extra, 1, shake.Weight()/float64(shake.Tick))
}
if flush || shake.HitTick == shake.Tick {
shake.scored = true
s.StagedShake = s.StagedShake.Next
}
}
// If a chart has not enough Shake and Roll, max score of Extra will shrink.
// Margin will be distributed to Flow and Acc score by 7:3.
func ExtraScoreRate(nws, ews float64) float64 {
const factor = 10 * 1.5
if nws == 0 {
if ews == 0 {
return 0
}
return 1
}
rate := factor * ews / nws
if rate > 1 {
rate = 1
}
return rate
}
func (s *ScenePlay) SetMaxScores() {
nws := s.MaxWeights[mode.Flow]
ews := s.MaxWeights[mode.Extra]
extraMax := mode.DefaultMaxScores[mode.Extra]
extraRate := ExtraScoreRate(nws, ews)
extraScore := extraMax * extraRate
extraRemained := extraMax * (1 - extraRate)
s.MaxScores[mode.Flow] += extraRemained * 0.7
s.MaxScores[mode.Acc] += extraRemained * 0.3
s.MaxScores[mode.Extra] = extraScore
if nws == 0 {
s.MaxScores[mode.Extra] += s.MaxScores[mode.Flow] + s.MaxScores[mode.Acc]
s.MaxScores[mode.Flow] = 0
s.MaxScores[mode.Acc] = 0
}
s.Scorer.SetMaxScores(s.MaxScores)
}
// func (s ScenePlay) LinearScore() float64 {
// var sum float64
// for i, c := range s.NoteCount{
// max:=float64(s.MaxNoteCount[i])
// sum+=
// }
// return s.ScoreBounds[mode.Total] * float64(s.NoteCount) / float64(s.MaxNoteCount)
// }