An implementation of the Glicko-2 rating system for Scala and Scala.js.
Install the library
Add the dependency in the
libraryDependencies += "com.github.mrdimosthenis" %% "glicko2" % "1.0.1"
For Scala.js use the
%%% operator instead of
Import the package
Player is a case class with three parameters (
- We can create a player by defining their parameters.
val player = Player(1464, 151, 0.06)
- We can also create a player with the default initial parameters.
val newPlayer = Player.newEntry() // Player(1500.0, 350.0, 0.06)
Result is an enum with three values (
To create results, we need to specify their kind, their opponent and place them inside a
val res = List(Result.WonAgainst(newPlayer))
Calculate player params after a period of results
We can see how results affect a player.
val playerUpdated = player.afterPeriod(res) // Player(1507.5, 145.3, 0.06)
Suppose a player rated
1500 competes against players rated
the first game and losing the next two. Assume the
1500-rated player’s rating deviation
200, and his opponents’ are
300, respectively. Assume the
1500 player has
volatility σ =
0.06, and his opponents have
Let's see how this example is translated and what happens to the first player when the period ends.
val p = Player(1500, 200, 0.06) val opp1 = Player(1400, 30, 0.07) val opp2 = Player(1550, 100, 0.08) val opp3 = Player(1700, 300, 0.05) val res1 = Result.WonAgainst(opp1) val res2 = Result.DefeatedBy(opp2) val res3 = Result.DefeatedBy(opp3) val results = List(res1, res2, res3) val pUpdated = p.afterPeriod(results) // Player(1464.06, 151.52, 0.05999)
If the default values of the system do not serve us well, we can change them.
val tuning = Tuning.default(initRating = 1200, minDeviation = 30, tau = 0.75) // Tuning(1200.0, 350.0, 30.0, 0.06, 0.75, 0.000001)
In that case, we need to pass
tuning as a parameter to
These are the parameters of
Tuning and their default values: