/
team.coffee
50 lines (42 loc) · 1.15 KB
/
team.coffee
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
class Team
constructor: (@number)->
@score = 0
@rounds = {}
@bonusApplied = false
numRounds: =>
n = 0
n++ for round of @rounds
n
numBonusRounds: =>
n = 0
for round of @rounds
n++ if @rounds[round].bonus
n
addRound: (round)=>
@score += round.total
@rounds[round.MatchNumber] =
matchNumber: round.MatchNumber
score: round.total
bonus: round.Bonus
removeRound: (matchNumber)=>
if @rounds[matchNumber]?
@score -= @rounds[matchNumber].score
delete @rounds[matchNumber]
else
return false
applyBonus: =>
unless @bonusApplied
maxBonus = 0.1
@bonusApplied = true
@score *= 1 + maxBonus * @numBonusRounds()/@numRounds()
bestRound: =>
best = -1
bestNumber = null
for number, round of @rounds
if round.score > best
best = round.score
bestNumber = number
bestNumber
bestScore: =>
@rounds[@bestRound()].score
module.exports = Team