@@ -6,6 +6,7 @@ import java.time.Instant
66
77// times are expressed in seconds
88case class CorrespondenceClock (
9+ base : Int ,
910 increment : Int ,
1011 whiteTime : Float ,
1112 blackTime : Float
@@ -27,19 +28,29 @@ case class CorrespondenceClock(
2728 )
2829
2930 // in seconds
30- def estimateTotalTime : Int = increment * 40 / 2
31+ def estimateTotalTime : Int = base + increment * 40 / 2
3132
3233 def incrementHours : Int = increment / 60 / 60
3334
3435object CorrespondenceClock :
3536 val hourSeconds = 60 * 60
3637 val daySeconds = 24 * hourSeconds
3738
38- def apply (daysPerTurn : Int , turnColor : Color , lastMoveAt : Instant ): CorrespondenceClock =
39- val increment = daysPerTurn * 24 * 60 * 60
39+ // TODO: specify which color to add days to, if allowing addition to either color
40+ def apply (
41+ base : Int ,
42+ increment : Int ,
43+ remainingTime : Float ,
44+ daysToAdd : Int ,
45+ turnColor : Color ,
46+ lastMoveAt : Instant
47+ ): CorrespondenceClock =
48+ val limit = base
49+ val incremented = (remainingTime + (daysToAdd * daySeconds)).max(limit * daySeconds).toInt.max(0 )
4050 val secondsLeft = (lastMoveAt.toSeconds + increment - nowSeconds).toInt.max(0 )
4151 CorrespondenceClock (
52+ base = base,
4253 increment = increment,
43- whiteTime = turnColor.fold(secondsLeft, increment ).toFloat,
44- blackTime = turnColor.fold(increment , secondsLeft).toFloat
54+ whiteTime = turnColor.fold(secondsLeft, incremented ).toFloat,
55+ blackTime = turnColor.fold(incremented , secondsLeft).toFloat
4556 )
0 commit comments