Skip to content

Commit

Permalink
Move.moveTime, 17.0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
ornicar committed Dec 29, 2024
1 parent 281351f commit 875aaa0
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 13 deletions.
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
inThisBuild(
Seq(
scalaVersion := "3.6.2",
version := "17.0.0",
version := "17.0.1",
organization := "org.lichess",
licenses += ("MIT" -> url("https://opensource.org/licenses/MIT")),
publishTo := Option(Resolver.file("file", new File(sys.props.getOrElse("publishTo", "")))),
Expand Down
17 changes: 9 additions & 8 deletions core/src/main/scala/format/pgn/Pgn.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package chess
package format.pgn

import monocle.syntax.all.*
import cats.syntax.all.*

type PgnTree = Node[Move]

Expand Down Expand Up @@ -55,19 +56,19 @@ case class Move(
glyphs: Glyphs = Glyphs.empty,
opening: Option[String] = None,
result: Option[String] = None,
// time left for the user who made the move, after he made it
secondsLeft: Option[Int] = None,
secondsLeft: Option[Int] = None, // %clk clock in seconds for the move player, after the move
moveTime: Option[Int] = None, // %emt estimated move time in seconds
variationComments: List[Comment] = Nil
):

private def clockString: Option[String] =
secondsLeft.map(seconds => "[%clk " + Move.formatPgnSeconds(seconds) + "]")
private def clockString: Option[String] = List(
secondsLeft.map(seconds => "[%clk " + Move.formatPgnSeconds(seconds) + "]"),
moveTime.map(seconds => "[%emt " + Move.formatPgnSeconds(seconds) + "]")
).flatten.some.filter(_.nonEmpty).map(_.mkString(" "))

def hasComment =
comments.nonEmpty || secondsLeft.isDefined
def hasComment = comments.nonEmpty || secondsLeft.isDefined || moveTime.isDefined

private def nonEmpty =
comments.nonEmpty || secondsLeft.isDefined || opening.isDefined || result.isDefined
private def nonEmpty = hasComment || opening.isDefined || result.isDefined

private def appendSanStr(builder: StringBuilder): Unit =
builder.append(san.value)
Expand Down
3 changes: 0 additions & 3 deletions core/src/main/scala/format/pgn/parsingModel.scala
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,6 @@ case class PgnNodeData(
san = x.toSanStr,
comments = comments,
glyphs = glyphs,
opening = None,
result = None,
secondsLeft = None,
variationComments = variationComments
)
)
Expand Down
2 changes: 1 addition & 1 deletion test-kit/src/main/scala/chess/ChessTreeArbitraries.scala
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ object ChessTreeArbitraries:
comments <- genComments(5)
glyphs <- Gen.someOf(Glyphs.all).map(xs => Glyphs.fromList(xs.toList))
clock <- Gen.posNum[Int]
yield WithMove(move, PgnMove(move.san, comments, glyphs, None, None, clock.some, Nil))
yield WithMove(move, PgnMove(move.san, comments, glyphs, secondsLeft = clock.some))

def genNode[A: Generator](value: A, variations: List[A] = Nil): Gen[Node[A]] =
value.next.flatMap: nextSeeds =>
Expand Down

0 comments on commit 875aaa0

Please sign in to comment.