Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 36 additions & 10 deletions core/src/main/scala/TournamentClock.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,54 @@ import cats.syntax.all.*

import Clock.{ LimitSeconds, LimitMinutes, IncrementSeconds }

case class TournamentClock(limitSeconds: LimitSeconds, incrementSeconds: IncrementSeconds):
sealed trait TournamentClock:
def limit: Centis
def increment: Centis

def limit: Centis = Centis.ofSeconds(limitSeconds.value)
def increment: Centis = Centis.ofSeconds(incrementSeconds.value)
def incrementAtPly(ply: Ply): Centis

def incrementAtPly(ply: Ply): Centis = increment
def limitMinutes: LimitMinutes

def limitMinutes = LimitMinutes(limitSeconds.value / 60)
def toClockConfig: Option[Clock.Config]

def toClockConfig: Option[Clock.Config] = Clock.Config(limitSeconds, incrementSeconds).some

override def toString = s"$limitMinutes+$incrementSeconds"
case class GameStage(from: Int, to: Option[Int])

// support delay
object TournamentClock:
case class Single(limitSeconds: LimitSeconds, incrementSeconds: IncrementSeconds) extends TournamentClock:
def limit: Centis = Centis.ofSeconds(limitSeconds.value)
def increment: Centis = Centis.ofSeconds(incrementSeconds.value)

def incrementAtPly(ply: Ply): Centis = increment

def limitMinutes = LimitMinutes(limitSeconds.value / 60)

def toClockConfig: Option[Clock.Config] = Clock.Config(limitSeconds, incrementSeconds).some

case class Stages(stages: List[(GameStage, Single)]) extends TournamentClock:
def limit: Centis = ???
def increment: Centis = ???

def incrementAtPly(ply: Ply): Centis = ???

def limitMinutes = ???

def toClockConfig: Option[Clock.Config] = ???

case class Armageddon(white: Single, black: Single) extends TournamentClock:
def limit: Centis = ???
def increment: Centis = ???
def incrementAtPly(ply: Ply): Centis = ???
def limitMinutes = ???
def toClockConfig: Option[Clock.Config] = ???

object parse:

private val cleanRegex = "(/move|minutes|minute|min|m|seconds|second|sec|s|'|\")".r

private def make(strict: Boolean)(a: Int, b: Int) =
private def make(strict: Boolean)(a: Int, b: Int): TournamentClock =
val limit = if strict then LimitSeconds(a) else LimitSeconds(if a > 180 then a else a * 60)
TournamentClock(limit, IncrementSeconds(b))
TournamentClock.Single(limit, IncrementSeconds(b))

// `strict` uses PGN specification https://www.saremba.de/chessgml/standards/pgn/pgn-complete.htm#c9.6.1
// where time control is always in seconds
Expand Down
2 changes: 1 addition & 1 deletion test-kit/src/test/scala/TournamentClockTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class TournamentClockTest extends ChessTest:
val parseStrict = TournamentClock.parse(true)

def someClock(seconds: Int, inc: Int) = Some:
TournamentClock(LimitSeconds(seconds), IncrementSeconds(inc))
TournamentClock.Single(LimitSeconds(seconds), IncrementSeconds(inc))

test("parse empty"):
assertEquals(parse(""), None)
Expand Down