From 06c166210f4eabd05943da72e5e18ff2a57b3b2d Mon Sep 17 00:00:00 2001 From: Daniel Dugovic Date: Thu, 21 Nov 2024 22:55:30 -0600 Subject: [PATCH] Rating color advantage test WIP (#598) --- rating/src/main/scala/glicko/model.scala | 2 +- ...ickoCalculatorWithColorAdvantageTest.scala | 43 ++++++++++++++++++- 2 files changed, 43 insertions(+), 2 deletions(-) diff --git a/rating/src/main/scala/glicko/model.scala b/rating/src/main/scala/glicko/model.scala index 387e25b1e..34f7e2707 100644 --- a/rating/src/main/scala/glicko/model.scala +++ b/rating/src/main/scala/glicko/model.scala @@ -34,7 +34,7 @@ val cluelessDeviation = 230 case class Player( glicko: Glicko, - numberOfResults: Int, + numberOfResults: Int = 0, lastRatingPeriodEnd: Option[Instant] = None ): export glicko.* diff --git a/test-kit/src/test/scala/rating/glicko/GlickoCalculatorWithColorAdvantageTest.scala b/test-kit/src/test/scala/rating/glicko/GlickoCalculatorWithColorAdvantageTest.scala index 568641f46..3973d4fe4 100644 --- a/test-kit/src/test/scala/rating/glicko/GlickoCalculatorWithColorAdvantageTest.scala +++ b/test-kit/src/test/scala/rating/glicko/GlickoCalculatorWithColorAdvantageTest.scala @@ -1,4 +1,5 @@ -package chess.rating.glicko +package chess +package rating.glicko import cats.syntax.all.* import munit.ScalaCheckSuite @@ -12,3 +13,43 @@ class RatingCalculatorWithColorAdvantageTest extends ScalaCheckSuite with chess. ) // test that the rating calculator correctly applies the color advantage + import Outcome.* + // http://www.glicko.net/glicko/glicko2.pdf + // If the player is unrated, set the rating to 1500 + // and the RD to 350. Set the player’s volatility to + // 0.06 (this value depends on the particular application) + val RD: Double = 350d + val V: Double = 0.06d + + private def ratingDiff(r: Int, opRating: Int, outcome: Outcome, expected: Int)(using + munit.Location + ) = + val player = Player(Glicko(r, RD, V)) + val opponent = Player(Glicko(opRating, RD, V)) + val game = Game(ByColor(player, opponent), outcome) + // TODO: calculator with color advantage + val calculator = GlickoCalculator() + calculator.computeGame(game) + + test("new rating calculation over one game"): + ratingDiff(1500, 1500, white, 20) + ratingDiff(1500, 1500, black, -20) + ratingDiff(1500, 1500, draw, 0) + ratingDiff(1500, 1900, white, 37) + ratingDiff(1500, 1900, black, -3) + ratingDiff(1500, 1900, draw, 17) + ratingDiff(1500, 2900, white, 37) + ratingDiff(1500, 2900, black, -3) + ratingDiff(1500, 2900, draw, 17) + ratingDiff(1500, 1600, white, 26) + ratingDiff(1500, 1600, black, -14) + ratingDiff(1500, 1600, draw, 6) + ratingDiff(2000, 1600, white, 3) + ratingDiff(2000, 1600, black, -37) + ratingDiff(2000, 1600, draw, -17) + ratingDiff(2000, 1000, white, 3) + ratingDiff(2000, 1000, black, -37) + ratingDiff(2000, 1000, draw, -17) + ratingDiff(2000, 1900, white, 14) + ratingDiff(2000, 1900, black, -26) + ratingDiff(2000, 1900, draw, -6)