Skip to content

Commit

Permalink
Merge pull request #586 from isaacl/scalalib_11.3.1
Browse files Browse the repository at this point in the history
16.3.2
  • Loading branch information
ornicar authored Oct 18, 2024
2 parents 8fbba2c + a0bf698 commit 48e62da
Show file tree
Hide file tree
Showing 10 changed files with 17 additions and 17 deletions.
4 changes: 2 additions & 2 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
inThisBuild(
Seq(
scalaVersion := "3.5.1",
version := "16.3.1",
version := "16.3.2",
organization := "org.lichess",
licenses += ("MIT" -> url("https://opensource.org/licenses/MIT")),
publishTo := Option(Resolver.file("file", new File(sys.props.getOrElse("publishTo", "")))),
Expand All @@ -10,7 +10,7 @@ inThisBuild(
)
)

val scalalibVersion = "11.2.9"
val scalalibVersion = "11.3.1"

val commonSettings = Seq(
scalacOptions := Seq(
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/scala/Centis.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import scala.concurrent.duration.*

// maximum centis = Int.MaxValue / 100 / 60 / 60 / 24 = 248 days
opaque type Centis = Int
object Centis extends OpaqueInt[Centis]:
object Centis extends RichOpaqueInt[Centis]:

extension (centis: Centis)

Expand Down
8 changes: 4 additions & 4 deletions core/src/main/scala/Clock.scala
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ case class Clock(
else toNow(t)
}

def moretimeable(c: Color) = players(c).remaining < 100 * 60 * 60 * 2
def moretimeable(c: Color) = players(c).remaining < Centis(100 * 60 * 60 * 2)

def isRunning = timer.isDefined

Expand Down Expand Up @@ -157,13 +157,13 @@ object Clock:
private val limitFormatter = DecimalFormat("#.##")

opaque type LimitSeconds = Int
object LimitSeconds extends OpaqueInt[LimitSeconds]
object LimitSeconds extends RelaxedOpaqueInt[LimitSeconds]

opaque type LimitMinutes = Int
object LimitMinutes extends OpaqueInt[LimitMinutes]
object LimitMinutes extends RelaxedOpaqueInt[LimitMinutes]

opaque type IncrementSeconds = Int
object IncrementSeconds extends OpaqueInt[IncrementSeconds]
object IncrementSeconds extends RelaxedOpaqueInt[IncrementSeconds]

// All unspecified durations are expressed in centi-seconds
case class Config(limitSeconds: LimitSeconds, incrementSeconds: IncrementSeconds):
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/scala/Drop.scala
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ case class Drop(
h.copy(
lastMove = Option(Uci.Drop(piece.role, square)),
unmovedRooks = before.unmovedRooks,
halfMoveClock = if piece.is(Pawn) then HalfMoveClock.initial else h.halfMoveClock + 1
halfMoveClock = if piece.is(Pawn) then HalfMoveClock.initial else h.halfMoveClock.map(_ + 1)
)
},
toUci,
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/scala/Elo.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ object KFactor extends OpaqueInt[KFactor]:
* https://handbook.fide.com/chapter/B022022
* https://ratings.fide.com/calc.phtml
* */
object Elo extends OpaqueInt[Elo]:
object Elo extends RelaxedOpaqueInt[Elo]:

def computeRatingDiff(player: Player, games: Seq[Game]): Int =
computeNewRating(player, games) - player.rating
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/scala/Move.scala
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ case class Move(
lastMove = Option(toUci),
halfMoveClock =
if piece.is(Pawn) || captures || promotes then HalfMoveClock.initial
else h1.halfMoveClock + 1
else h1.halfMoveClock.map(_ + 1)
)

var castleRights: Castles = h1.castles
Expand Down
4 changes: 2 additions & 2 deletions core/src/main/scala/format/FenReader.scala
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,10 @@ trait FenReader:
val halfMoveClock =
HalfMoveClock
.from(splitted.lift(0).flatMap(_.toIntOption))
.map(_.atLeast(HalfMoveClock.initial).atMost(100))
.map(_.atLeast(HalfMoveClock.initial).atMost(HalfMoveClock(100)))
val fullMoveNumber = FullMoveNumber
.from(splitted.lift(1).flatMap(_.toIntOption))
.map(_.atLeast(FullMoveNumber.initial).atMost(500))
.map(_.atLeast(FullMoveNumber.initial).atMost(FullMoveNumber(500)))
(halfMoveClock, fullMoveNumber)

def readPly(fen: FullFen): Option[Ply] =
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/scala/format/pgn/PgnNodeEncoder.scala
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,4 @@ object PgnNodeEncoder:
private def isWhiteTurn: Boolean =
ply.isOdd
private def turnNumber: FullMoveNumber =
ply.fullMoveNumber + ply.value % 2 - 1
ply.fullMoveNumber.map(_ + ply.value % 2 - 1)
6 changes: 3 additions & 3 deletions core/src/main/scala/model.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ import cats.kernel.Semigroup
/** Fullmove number: The number of the full move.
* It starts at 1, and is incremented after Black's move. */
opaque type FullMoveNumber = Int
object FullMoveNumber extends OpaqueInt[FullMoveNumber]:
object FullMoveNumber extends RichOpaqueInt[FullMoveNumber]:
val initial: FullMoveNumber = 1
extension (e: FullMoveNumber)
def ply(turn: Color) = Ply(e * 2 - turn.fold(2, 1))
def next: FullMoveNumber = e + 1

opaque type Ply = Int
object Ply extends OpaqueInt[Ply]:
object Ply extends RelaxedOpaqueInt[Ply]:
val initial: Ply = 0
val firstMove: Ply = 1
extension (e: Ply)
Expand All @@ -25,7 +25,7 @@ object Ply extends OpaqueInt[Ply]:
/* The halfmove clock specifies a decimal number of half moves with respect to the 50 move draw rule.
* It is reset to zero after a capture or a pawn move and incremented otherwise. */
opaque type HalfMoveClock = Int
object HalfMoveClock extends OpaqueInt[HalfMoveClock]:
object HalfMoveClock extends RichOpaqueInt[HalfMoveClock]:
val initial: HalfMoveClock = 0

opaque type Check = Boolean
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/scala/variant/Variant.scala
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ abstract class Variant private[variant] (
def applyVariantEffect(moves: List[Move]): List[Move] =
if hasMoveEffects then moves.map(addVariantEffect) else moves

def fiftyMoves(history: History): Boolean = history.halfMoveClock >= 100
def fiftyMoves(history: History): Boolean = history.halfMoveClock >= HalfMoveClock(100)

def isIrreversible(move: Move): Boolean =
(move.piece.is(Pawn)) || move.captures || move.promotes || move.castles
Expand Down

0 comments on commit 48e62da

Please sign in to comment.