Skip to content

Commit 1dfe5ee

Browse files
committed
lower-case enum values like lila did
keeps compatibility with existing data in DB, and potentially URLs
1 parent 83e0aaf commit 1dfe5ee

File tree

3 files changed

+10
-10
lines changed

3 files changed

+10
-10
lines changed

core/src/main/scala/model.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ opaque type FideId = Int
4242
object FideId extends OpaqueInt[FideId]
4343

4444
enum FideTC:
45-
case Standard, Rapid, Blitz
45+
case standard, rapid, blitz
4646

4747
opaque type PlayerName = String
4848
object PlayerName extends OpaqueString[PlayerName]

rating/src/main/scala/Elo.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ object Elo extends RichOpaqueInt[Elo]:
2828
def computeNewRating(tc: FideTC)(player: Player, games: Seq[Game]): Elo =
2929
val playerElo = player.rating
3030
def rnbUnratedCondition(opponentElo: Elo): Boolean =
31-
tc != FideTC.Standard &&
31+
tc != FideTC.standard &&
3232
(opponentElo - playerElo).abs >= 600 && List(playerElo, opponentElo).exists(_ > 2600)
3333
val expectedScore = games.foldMap: game =>
3434
if rnbUnratedCondition(game.opponentRating)
@@ -46,7 +46,7 @@ object Elo extends RichOpaqueInt[Elo]:
4646
*/
4747
def adjustedRatingDiff(tc: FideTC)(playerElo: Elo, opponentElo: Elo): Int =
4848
val ratingDiff = opponentElo - playerElo
49-
if tc == FideTC.Standard && playerElo >= 2650 then ratingDiff
49+
if tc == FideTC.standard && playerElo >= 2650 then ratingDiff
5050
else ratingDiff.atLeast(-400).atMost(400)
5151

5252
def getExpectedScore(ratingDiff: Int): Float =

test-kit/src/test/scala/rating/EloTest.scala

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class EloTest extends ChessTest:
2121

2222
private def ratingDiffStandard(r: Int, k: Int, opRating: Int, points: Outcome.Points, expected: Int)(using
2323
munit.Location
24-
) = ratingDiff(r, k, opRating, points, FideTC.Standard, expected)
24+
) = ratingDiff(r, k, opRating, points, FideTC.standard, expected)
2525

2626
test("new rating calculation over one game"):
2727
ratingDiffStandard(1500, 40, 1500, One, 20)
@@ -49,19 +49,19 @@ class EloTest extends ChessTest:
4949

5050
test("new rating calculation over multiple games"):
5151
assertEquals(
52-
Elo.computeRatingDiff(FideTC.Standard)(
52+
Elo.computeRatingDiff(FideTC.standard)(
5353
Elo.Player(Elo(2800), KFactor(10)),
5454
List.fill(11)(Elo.Game(One, Elo(1800)))
5555
),
5656
0
5757
)
5858

5959
test("new rating calculation rapid/blitz"):
60-
ratingDiff(1800, 40, 2601, Zero, FideTC.Rapid, 0)
61-
ratingDiff(2601, 10, 1800, One, FideTC.Rapid, 0)
62-
ratingDiff(2600, 10, 1900, One, FideTC.Rapid, 1)
63-
ratingDiff(1500, 40, 1500, One, FideTC.Rapid, 20)
64-
ratingDiff(1500, 40, 1900, Half, FideTC.Blitz, 17)
60+
ratingDiff(1800, 40, 2601, Zero, FideTC.rapid, 0)
61+
ratingDiff(2601, 10, 1800, One, FideTC.rapid, 0)
62+
ratingDiff(2600, 10, 1900, One, FideTC.rapid, 1)
63+
ratingDiff(1500, 40, 1500, One, FideTC.rapid, 20)
64+
ratingDiff(1500, 40, 1900, Half, FideTC.blitz, 17)
6565

6666
private def expectedScore(ratingDiff: Int, expScore: Float)(using munit.Location) =
6767
assertCloseTo(Elo.getExpectedScore(ratingDiff), expScore, 0.001f)

0 commit comments

Comments
 (0)