From 09cf006af70cb54b4817e418078054f339c55953 Mon Sep 17 00:00:00 2001 From: Brian Hicks Date: Tue, 15 Sep 2020 08:57:20 -0500 Subject: [PATCH] calculate k-factor based on matches played and ranking --- src/League.elm | 46 +++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 41 insertions(+), 5 deletions(-) diff --git a/src/League.elm b/src/League.elm index 0a0545c..6cba5b3 100644 --- a/src/League.elm +++ b/src/League.elm @@ -172,9 +172,6 @@ new match. nextMatch : League -> Generator (Maybe Match) nextMatch (League league) = let - playInMatches = - 5 - allPlayers = Dict.values league.players in @@ -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 } @@ -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 } @@ -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