Skip to content

Commit

Permalink
Code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
ddugovic committed Jan 2, 2025
1 parent cdbcda0 commit f7df444
Showing 1 changed file with 14 additions and 18 deletions.
32 changes: 14 additions & 18 deletions rating/src/main/scala/glicko/impl/RatingCalculator.scala
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ final private[glicko] class RatingCalculator(

private val ratingPeriodsPerMilli: Double = ratingPeriodsPerDay.value * DAYS_PER_MILLI

/** <p>Run through all players within a resultset and calculate their new ratings.</p> <p>Players within the
* resultset who did not compete during the rating period will have see their deviation increase (in line
* with Prof Glickman's paper).</p> <p>Note that this method will clear the results held in the association
* resultset.</p>
/** Run through all players within a resultset and calculate their new ratings.
* Players within the resultset who did not compete during the rating period
* will have see their deviation increase (in line with Prof Glickman's paper).
* Note that this method will clear the results held in the association resultset.
*
* @param results
*/
Expand Down Expand Up @@ -168,20 +168,17 @@ final private[glicko] class RatingCalculator(
private def vOf(player: Rating, results: List[Result]) =
var v = 0.0d
for result <- results do
v = v + ((Math.pow(g(result.getOpponent(player).getGlicko2RatingDeviation), 2))
val opponent = result.getOpponent(player)
v = v + ((Math.pow(g(opponent.getGlicko2RatingDeviation), 2))
* E(
player.getGlicko2RatingWithAdvantage(result.getAdvantage(colorAdvantage, player)),
result
.getOpponent(player)
.getGlicko2RatingWithAdvantage(result.getAdvantage(colorAdvantage, result.getOpponent(player))),
result.getOpponent(player).getGlicko2RatingDeviation
opponent.getGlicko2RatingWithAdvantage(result.getAdvantage(colorAdvantage, opponent)),
opponent.getGlicko2RatingDeviation
)
* (1.0 - E(
player.getGlicko2RatingWithAdvantage(result.getAdvantage(colorAdvantage, player)),
result
.getOpponent(player)
.getGlicko2RatingWithAdvantage(result.getAdvantage(colorAdvantage, result.getOpponent(player))),
result.getOpponent(player).getGlicko2RatingDeviation
opponent.getGlicko2RatingWithAdvantage(result.getAdvantage(colorAdvantage, opponent)),
opponent.getGlicko2RatingDeviation
)))
1 / v

Expand All @@ -198,14 +195,13 @@ final private[glicko] class RatingCalculator(
private def outcomeBasedRating(player: Rating, results: List[Result]) =
var outcomeBasedRating = 0d
for result <- results do
val opponent = result.getOpponent(player)
outcomeBasedRating = outcomeBasedRating
+ (g(result.getOpponent(player).getGlicko2RatingDeviation)
+ (g(opponent.getGlicko2RatingDeviation)
* (result.getScore(player) - E(
player.getGlicko2RatingWithAdvantage(result.getAdvantage(colorAdvantage, player)),
result
.getOpponent(player)
.getGlicko2RatingWithAdvantage(result.getAdvantage(colorAdvantage, result.getOpponent(player))),
result.getOpponent(player).getGlicko2RatingDeviation
opponent.getGlicko2RatingWithAdvantage(result.getAdvantage(colorAdvantage, opponent)),
opponent.getGlicko2RatingDeviation
)))
outcomeBasedRating

Expand Down

0 comments on commit f7df444

Please sign in to comment.