don't start or add time to swiss clocks

but start them when they expire
pull/6572/head
Thibault Duplessis 2020-05-07 15:46:36 -06:00
parent 963b2eb7c1
commit b579c416fb
4 changed files with 17 additions and 9 deletions

View File

@ -249,6 +249,11 @@ case class Game(
mode = Mode(mode.rated && userIds.distinct.size == 2)
)
def startClock =
clock map { c =>
start.withClock(c.start)
}
def correspondenceClock: Option[CorrespondenceClock] =
daysPerTurn map { days =>
val increment = days * 24 * 60 * 60
@ -492,7 +497,9 @@ case class Game(
}
def expirable =
!bothPlayersHaveMoved && source.exists(Source.expirable.contains) && playable && nonAi && hasClock
!bothPlayersHaveMoved && source.exists(Source.expirable.contains) && playable && nonAi && clock.exists(
!_.isRunning
)
def timeBeforeExpiration: Option[Centis] =
expirable option {

View File

@ -26,7 +26,7 @@ object Source {
} toMap
val searchable = List(Lobby, Friend, Ai, Position, Import, Tournament, Simul, Pool, Swiss)
val expirable: Set[Source] = Set(Lobby, Tournament, Pool)
val expirable: Set[Source] = Set(Lobby, Tournament, Pool, Swiss)
def apply(id: Int): Option[Source] = byId get id
}

View File

@ -421,7 +421,12 @@ final private[round] class RoundDuct(
case NoStart =>
handle { game =>
game.timeBeforeExpiration.exists(_.centis == 0) ?? finisher.noStart(game)
game.timeBeforeExpiration.exists(_.centis == 0) ?? {
if (game.isSwiss) game.startClock ?? { g =>
proxy save g inject List(Event.Reload)
}
else finisher.noStart(game)
}
}
case FishnetStart =>

View File

@ -1,6 +1,6 @@
package lila.swiss
import chess.{ Black, Centis, Color, White }
import chess.{ Black, Color, White }
import org.joda.time.DateTime
import scala.util.chaining._
@ -106,11 +106,7 @@ final private class SwissDirector(
) pipe { g =>
val turns = g.player.fold(0, 1)
g.copy(
clock = swiss.clock.toClock
.giveTime(White, Centis(300))
.giveTime(Black, Centis(300))
.start
.some,
clock = swiss.clock.toClock.some,
turns = turns,
startedAtTurn = turns
)