Skip to content

Commit

Permalink
calculate k-factor based on matches played and ranking
Browse files Browse the repository at this point in the history
  • Loading branch information
BrianHicks committed Sep 15, 2020
1 parent d516f3b commit 09cf006
Showing 1 changed file with 41 additions and 5 deletions.
46 changes: 41 additions & 5 deletions src/League.elm
Expand Up @@ -172,9 +172,6 @@ new match.
nextMatch : League -> Generator (Maybe Match)
nextMatch (League league) =
let
playInMatches =
5

allPlayers =
Dict.values league.players
in
Expand Down Expand Up @@ -272,7 +269,7 @@ finishMatch outcome league =
Win { won, lost } ->
let
newRatings =
Elo.win Elo.sensitiveKFactor
Elo.win (kFactor won)
{ won = won.rating
, lost = lost.rating
}
Expand All @@ -285,7 +282,7 @@ finishMatch outcome league =
Draw { playerA, playerB } ->
let
newRatings =
Elo.draw Elo.sensitiveKFactor
Elo.draw (kFactor (higherRankedPlayer playerA playerB))
{ playerA = playerA.rating
, playerB = playerB.rating
}
Expand All @@ -296,6 +293,45 @@ finishMatch outcome league =
|> clearMatch


{-| Chesterton's export
-}
playInMatches : Int
playInMatches =
5


{-| Chesterton's export
-}
kFactor : Player -> Int
kFactor player =
if player.matches < playInMatches then
-- players who are new to the league should move around more so that
-- they can get ranked closer to their actual correct position sooner.
Elo.sensitiveKFactor * 2

else if player.rating <= Elo.initialRating * 2 then
-- players who have been around a while should still be able to easily
-- move up in the rankings if it turns out they've been consistently
-- underrated.
Elo.sensitiveKFactor

else
-- players who are at the top of the ratings should be relatively
-- stable.
Elo.sensitiveKFactor // 2


{-| Chesterton's export
-}
higherRankedPlayer : Player -> Player -> Player
higherRankedPlayer a b =
if a.rating > b.rating then
a

else
b


{-| Chesterton's export
-}
clearMatch : League -> League
Expand Down

0 comments on commit 09cf006

Please sign in to comment.