Skip to content

Commit

Permalink
Rating color advantage test WIP (lichess-org#598)
Browse files Browse the repository at this point in the history
  • Loading branch information
ddugovic committed Nov 22, 2024
1 parent 5746f15 commit 06c1662
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 2 deletions.
2 changes: 1 addition & 1 deletion rating/src/main/scala/glicko/model.scala
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ val cluelessDeviation = 230

case class Player(
glicko: Glicko,
numberOfResults: Int,
numberOfResults: Int = 0,
lastRatingPeriodEnd: Option[Instant] = None
):
export glicko.*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
package chess.rating.glicko
package chess
package rating.glicko

import cats.syntax.all.*
import munit.ScalaCheckSuite
Expand All @@ -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)

0 comments on commit 06c1662

Please sign in to comment.