score.gno
1.40 Kb · 53 lines
1package flag
2
3// Points a challenge starts at, by difficulty.
4const (
5 EasyPoints = 100
6 MediumPoints = 250
7 HardPoints = 500
8)
9
10// DecaySolves is the number of solves after which a challenge settles at
11// its floor value.
12const DecaySolves = 20
13
14// Initial returns the value of a challenge nobody has solved yet.
15func (d Difficulty) Initial() int {
16 switch d {
17 case Easy:
18 return EasyPoints
19 case Medium:
20 return MediumPoints
21 case Hard:
22 return HardPoints
23 }
24 return 0
25}
26
27// Floor returns the lowest value a challenge of difficulty d decays to:
28// two fifths of its initial value.
29func (d Difficulty) Floor() int { return d.Initial() * 2 / 5 }
30
31// Value returns what a challenge of difficulty d is worth to every one of
32// its solvers once it has solves solvers. It follows the CTFd dynamic
33// curve: the value falls with the square of the solve count and settles at
34// the floor after DecaySolves solves. A lone solver keeps the full value,
35// and the value applies retroactively to all solvers.
36func Value(d Difficulty, solves int) int {
37 initial, floor := d.Initial(), d.Floor()
38 n := solves - 1
39 if n <= 0 {
40 return initial
41 }
42 if n >= DecaySolves {
43 return floor
44 }
45 v := initial - (initial-floor)*n*n/(DecaySolves*DecaySolves)
46 if v < floor {
47 return floor
48 }
49 return v
50}
51
52// FirstBloodBonus returns the one-time bonus for the first solver.
53func (d Difficulty) FirstBloodBonus() int { return d.Initial() / 10 }