Check out the Pastebin Gadgets Shop. We have thousands of fun, geeky & affordable gadgets on sale :-)Want more features on Pastebin? Sign Up, it's FREE!
tweet

# Simple NvsN elo

By: a guest on Feb 9th, 2012  |  syntax: Haskell  |  size: 0.92 KB  |  views: 104  |  expires: Never
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
1.
2. -- | Projected result of valuation A vs valuation B, with 1 = sure win
3. -- for A, 0 = sure win for B.
4. --
5. -- This is the core formula of Elo.
6. projected :: Double -> Double -> Double
7. projected a b = 1 / (1 + exp ( log 10 / e * (b-a) ) )
8.  where e = 400
9.
10. -- | Points to grant the first player for a given result of a 1vs1
11. points1vs1 :: Double -> Double -> Double -> Double
12. points1vs1 a b d = c * (d - projected a b)
13.  where c = 4
14.
15. -- | 1vs1 result to assume for a player finishing in i-th place vs a
16. -- player finishing in j-th place.
17. --
18. -- It's important that "result i j = 1 - result j i" holds!
19. result :: Int -> Int -> Double
20. result i j
21.   | i < j     = 1
22.   | otherwise = 0
23.
24. -- | NvsN evaluation. Assumes valuations are sorted by finishing placement.
25. pointsNvsN :: [Double] -> [Double]
26. pointsNvsN rs =
27.   [ sum [ points1vs1 a b (result i j)
28.         | (j, b) <- rps, i /= j]
29.   | (i, a) <- rps]
30.  where rps = zip [1..] rs
clone this paste RAW Paste Data
Top