Guest User

Elo for free-for-all, 2

a guest
Feb 9th, 2012
110
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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 a b = 1 / (1 + exp ( log 10 / e * (b-a) ) )
  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 a b d = d - projected a b
  12.  
  13. -- | 1vs1 result to assume for a player finishing in i-th place vs a
  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.   | i < j     = 1
  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. --
  26. -- It's important that "weight i j = weight j i"
  27. weight :: Int -> Int -> Float
  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
RAW Paste Data