SHOW:
|
|
- or go back to the newest paste.
1 | -- | Projected result of valuation A vs valuation B, with 1 = sure win | |
2 | -- for A, 0 = sure win for B. | |
3 | -- | |
4 | -- This is the core formula of Elo. | |
5 | projected :: Float -> Float -> Float | |
6 | - | projected :: Double -> Double -> Double |
6 | + | |
7 | where e = 400 | |
8 | ||
9 | -- | Points to grant the first player for a given result of a 1vs1 | |
10 | points1vs1 :: Float -> Float -> Float -> Float | |
11 | - | points1vs1 :: Double -> Double -> Double -> Double |
11 | + | points1vs1 a b d = d - projected a b |
12 | - | points1vs1 a b d = c * (d - projected a b) |
12 | + | |
13 | - | where c = 4 |
13 | + | |
14 | -- player finishing in j-th place. | |
15 | -- | |
16 | -- It's important that "result i j = 1 - result j i" holds! | |
17 | result :: Int -> Int -> Float | |
18 | result i j | |
19 | - | result :: Int -> Int -> Double |
19 | + | |
20 | | otherwise = 0 | |
21 | ||
22 | -- | Weight to put on a 1vs1 pairing. We assume that players finishing | |
23 | -- fast have played less long, and therefore reduce the weight on | |
24 | -- their results. | |
25 | - | pointsNvsN :: [Double] -> [Double] |
25 | + | |
26 | - | pointsNvsN rs = |
26 | + | -- It's important that "weight i j = weight j i" |
27 | - | [ sum [ points1vs1 a b (result i j) |
27 | + | weight :: Int -> Int -> Float |
28 | - | | (j, b) <- rps, i /= j] |
28 | + | weight i j = 20 / fromIntegral (max i j) |
29 | ||
30 | -- | Bonus for players close to seed level. Make it so players can never | |
31 | -- fall under 0 points. | |
32 | seedBonus :: Float -> Float -> Float | |
33 | seedBonus a v | |
34 | | v >= 0 = v | |
35 | | a < f = v * a / f | |
36 | | otherwise = v | |
37 | where f = 300 | |
38 | ||
39 | -- | NvsN evaluation. Assumes valuations are sorted by finishing placement. | |
40 | pointsFree :: [Float] -> [Float] | |
41 | pointsFree rs = | |
42 | [ seedBonus a $ sum [ weight i j * points1vs1 a b (result i j) | |
43 | | (j, b) <- rps, i /= j] | |
44 | | (i, a) <- rps] | |
45 | where rps = zip [1..] rs |