File tree Expand file tree Collapse file tree 4 files changed +7
-15
lines changed
Expand file tree Collapse file tree 4 files changed +7
-15
lines changed Original file line number Diff line number Diff line change 11package chess
22
3- import cats .syntax .option .none
43import chess .Clock .Config
54
65import java .text .DecimalFormat
@@ -207,16 +206,6 @@ object Clock:
207206 if limitSeconds == 0 then increment.atLeast(Centis (300 ))
208207 else limit
209208
210- // [TimeControl "600+2"] -> 10+2
211- def readPgnConfig (str : String ): Option [Config ] =
212- str.split('+' ) match
213- case Array (initStr, incStr) =>
214- for
215- init <- initStr.toIntOption
216- inc <- incStr.toIntOption
217- yield Config (init, inc)
218- case _ => none
219-
220209 def apply (limit : LimitSeconds , increment : IncrementSeconds ): Clock = apply(Config (limit, increment))
221210
222211 def apply (config : Config ): Clock =
Original file line number Diff line number Diff line change @@ -4,7 +4,10 @@ import cats.syntax.all.*
44
55import Clock .{ LimitSeconds , IncrementSeconds }
66
7- case class TournamentClock (limitSeconds : LimitSeconds , incrementSeconds : IncrementSeconds )
7+ case class TournamentClock (limitSeconds : LimitSeconds , incrementSeconds : IncrementSeconds ):
8+
9+ def toClockConfig : Option [Clock .Config ] =
10+ Clock .Config (limitSeconds, incrementSeconds).some
811
912object TournamentClock :
1013
Original file line number Diff line number Diff line change @@ -45,4 +45,4 @@ object Reader:
4545
4646 private def makeGame (tags : Tags ) =
4747 val g = Game (variantOption = tags.variant, fen = tags.fen)
48- g.copy(startedAtPly = g.ply, clock = tags.clockConfig.map(Clock .apply))
48+ g.copy(startedAtPly = g.ply, clock = tags.clockConfig.flatMap(_.toClockConfig). map(Clock .apply))
Original file line number Diff line number Diff line change @@ -30,10 +30,10 @@ case class Tags(value: List[Tag]) extends AnyVal:
3030 val name = which(Tag )
3131 value.find(_.name == name).map(_.value)
3232
33- def clockConfig : Option [Clock . Config ] =
33+ def clockConfig : Option [TournamentClock ] =
3434 value
3535 .collectFirst { case Tag (Tag .TimeControl , str) => str }
36- .flatMap(Clock .readPgnConfig )
36+ .flatMap(TournamentClock .parse.apply )
3737
3838 def variant : Option [chess.variant.Variant ] =
3939 apply(_.Variant )
You can’t perform that action at this time.
0 commit comments