use clock configs in tournaments
parent
f8832191d7
commit
fbe25f5370
|
@ -1 +1 @@
|
|||
Subproject commit 2ebb26f57d76680e63b3527eae83ca47e4d73516
|
||||
Subproject commit fd402c6243e2491c325700961047afed70444edd
|
|
@ -247,7 +247,7 @@ case class Game(
|
|||
def playableCorrespondenceClock: Option[CorrespondenceClock] =
|
||||
playable ?? correspondenceClock
|
||||
|
||||
def speed = chess.Speed(clock)
|
||||
def speed = chess.Speed(clock.map(_.config))
|
||||
|
||||
def perfKey = PerfPicker.key(this)
|
||||
def perfType = PerfType(perfKey)
|
||||
|
@ -317,7 +317,7 @@ case class Game(
|
|||
|
||||
def abortable = status == Status.Started && playedTurns < 2 && nonMandatory
|
||||
|
||||
def berserkable = clock.??(_.berserkable) && status == Status.Started && playedTurns < 2
|
||||
def berserkable = clock.??(_.config.berserkable) && status == Status.Started && playedTurns < 2
|
||||
|
||||
def goBerserk(color: Color) =
|
||||
clock.ifTrue(berserkable && !player(color).berserk).map { c =>
|
||||
|
|
|
@ -62,7 +62,7 @@ private[lobby] object Biter {
|
|||
private def makeGame(hook: Hook) = Game.make(
|
||||
game = ChessGame(
|
||||
board = Board init hook.realVariant,
|
||||
clock = hook.clock.some),
|
||||
clock = hook.clock.toClock.some),
|
||||
whitePlayer = Player.white,
|
||||
blackPlayer = Player.black,
|
||||
mode = hook.realMode,
|
||||
|
|
|
@ -17,7 +17,7 @@ case class Hook(
|
|||
uid: String, // owner socket uid
|
||||
sid: Option[String], // owner cookie (used to prevent multiple hooks)
|
||||
variant: Int,
|
||||
clock: Clock,
|
||||
clock: Clock.Config,
|
||||
mode: Int,
|
||||
allowAnon: Boolean,
|
||||
color: String,
|
||||
|
@ -88,7 +88,7 @@ object Hook {
|
|||
def make(
|
||||
uid: String,
|
||||
variant: chess.variant.Variant,
|
||||
clock: Clock,
|
||||
clock: Clock.Config,
|
||||
mode: Mode,
|
||||
allowAnon: Boolean,
|
||||
color: String,
|
||||
|
|
|
@ -33,7 +33,7 @@ final class AutoPairing(
|
|||
) |> { g =>
|
||||
val turns = g.player.fold(0, 1)
|
||||
g.copy(
|
||||
clock = tour.clock.chessClock.some,
|
||||
clock = tour.clock.toClock.some,
|
||||
turns = turns,
|
||||
startedAtTurn = turns)
|
||||
},
|
||||
|
|
|
@ -28,7 +28,10 @@ object BSONHandlers {
|
|||
def write(x: Schedule.Speed) = BSONString(x.name)
|
||||
}
|
||||
|
||||
private implicit val tournamentClockBSONHandler = Macros.handler[TournamentClock]
|
||||
private implicit val tournamentClockBSONHandler = {
|
||||
import chess.Clock.Config
|
||||
Macros.handler[Config]
|
||||
}
|
||||
|
||||
private implicit val spotlightBSONHandler = Macros.handler[Spotlight]
|
||||
|
||||
|
@ -50,7 +53,7 @@ object BSONHandlers {
|
|||
name = r str "name",
|
||||
status = r.get[Status]("status"),
|
||||
system = r.intO("system").fold[System](System.default)(System.orDefault),
|
||||
clock = r.get[TournamentClock]("clock"),
|
||||
clock = r.get[chess.Clock.Config]("clock"),
|
||||
minutes = r int "minutes",
|
||||
variant = variant,
|
||||
position = position,
|
||||
|
|
|
@ -5,6 +5,7 @@ import org.joda.time.format.ISODateTimeFormat
|
|||
import play.api.libs.json._
|
||||
import scala.concurrent.duration._
|
||||
|
||||
import chess.Clock.{ Config => TournamentClock }
|
||||
import lila.common.LightUser
|
||||
import lila.common.PimpedJson._
|
||||
import lila.game.{ Game, GameRepo, Pov }
|
||||
|
@ -59,7 +60,7 @@ final class JsonView(
|
|||
"perf" -> tour.perfType,
|
||||
"nbPlayers" -> tour.nbPlayers,
|
||||
"minutes" -> tour.minutes,
|
||||
"clock" -> clockJson(tour.clock),
|
||||
"clock" -> tour.clock,
|
||||
"position" -> tour.position.some.filterNot(_.initial).map(positionJson),
|
||||
"private" -> tour.`private`.option(true),
|
||||
"verdicts" -> verdicts,
|
||||
|
@ -318,9 +319,7 @@ object JsonView {
|
|||
"freq" -> s.freq.name,
|
||||
"speed" -> s.speed.name)
|
||||
|
||||
private[tournament] def clockJson(c: TournamentClock) = Json.obj(
|
||||
"limit" -> c.limit,
|
||||
"increment" -> c.increment)
|
||||
private[tournament] implicit val clockWriter: Writes[TournamentClock] = Json.writes[TournamentClock]
|
||||
|
||||
private[tournament] def positionJson(s: chess.StartingPosition) = Json.obj(
|
||||
"eco" -> s.eco,
|
||||
|
|
|
@ -103,8 +103,8 @@ object Schedule {
|
|||
case (Bullet, HyperBullet) => true
|
||||
case _ => false
|
||||
}
|
||||
def fromClock(clock: TournamentClock) = {
|
||||
val time = clock.chessClock.estimateTotalTime
|
||||
def fromClock(clock: chess.Clock.Config) = {
|
||||
val time = clock.estimateTotalTime
|
||||
if (time < 60) HyperBullet
|
||||
else if (time < 180) Bullet
|
||||
else if (time < 480) Blitz
|
||||
|
@ -180,7 +180,7 @@ object Schedule {
|
|||
import Freq._, Speed._
|
||||
import chess.variant._
|
||||
|
||||
val TC = TournamentClock
|
||||
val TC = chess.Clock.Config
|
||||
|
||||
(s.freq, s.variant, s.speed) match {
|
||||
// Special cases.
|
||||
|
|
|
@ -24,7 +24,7 @@ final class ScheduleJsonView(
|
|||
"createdBy" -> tour.createdBy,
|
||||
"system" -> tour.system.toString.toLowerCase,
|
||||
"minutes" -> tour.minutes,
|
||||
"clock" -> clockJson(tour.clock),
|
||||
"clock" -> tour.clock,
|
||||
"position" -> tour.position.some.filterNot(_.initial).map(positionJson),
|
||||
"rated" -> tour.mode.rated,
|
||||
"fullName" -> tour.fullName,
|
||||
|
|
|
@ -26,7 +26,7 @@ private[tournament] final class Socket(
|
|||
private var delayedCrowdNotification = false
|
||||
private var delayedReloadNotification = false
|
||||
|
||||
private var clock = none[chess.Clock]
|
||||
private var clock = none[chess.Clock.Config]
|
||||
|
||||
private var waitingUsers = WaitingUsers.empty
|
||||
|
||||
|
@ -43,8 +43,7 @@ private[tournament] final class Socket(
|
|||
|
||||
def receiveSpecific = ({
|
||||
|
||||
case SetTournament(Some(tour)) =>
|
||||
clock = tour.clock.chessClock.some
|
||||
case SetTournament(Some(tour)) => clock = tour.clock.some
|
||||
|
||||
case StartGame(game) =>
|
||||
game.players foreach { player =>
|
||||
|
|
|
@ -3,6 +3,7 @@ package lila.tournament
|
|||
import org.joda.time.{ DateTime, Duration, Interval }
|
||||
import ornicar.scalalib.Random
|
||||
|
||||
import chess.Clock.{ Config => TournamentClock }
|
||||
import chess.{ Speed, Mode, StartingPosition }
|
||||
import lila.game.{ PovRef, PerfPicker }
|
||||
import lila.user.User
|
||||
|
@ -82,7 +83,7 @@ case class Tournament(
|
|||
case _ => false
|
||||
}
|
||||
|
||||
def speed = Speed(clock.chessClock.some)
|
||||
def speed = Speed(clock.some)
|
||||
|
||||
def perfType = PerfPicker.perfType(speed, variant, none)
|
||||
def perfLens = PerfPicker.mainOrDefault(speed, variant, none)
|
||||
|
@ -91,7 +92,7 @@ case class Tournament(
|
|||
if (minutes < 60) s"${minutes}m"
|
||||
else s"${minutes / 60}h" + (if (minutes % 60 != 0) s" ${(minutes % 60)}m" else "")
|
||||
|
||||
def berserkable = system.berserkable && clock.chessClock.berserkable
|
||||
def berserkable = system.berserkable && clock.berserkable
|
||||
|
||||
def clockStatus = secondsToFinish |> { s => "%02d:%02d".format(s / 60, s % 60) }
|
||||
|
||||
|
|
|
@ -44,7 +44,7 @@ final class TournamentApi(
|
|||
var variant = chess.variant.Variant orDefault setup.variant
|
||||
val tour = Tournament.make(
|
||||
createdByUserId = me.id,
|
||||
clock = TournamentClock((setup.clockTime * 60).toInt, setup.clockIncrement),
|
||||
clock = chess.Clock.Config((setup.clockTime * 60).toInt, setup.clockIncrement),
|
||||
minutes = setup.minutes,
|
||||
waitMinutes = setup.waitMinutes,
|
||||
mode = setup.mode.fold(Mode.default)(Mode.orDefault),
|
||||
|
|
|
@ -1,15 +0,0 @@
|
|||
package lila.tournament
|
||||
|
||||
// All durations are expressed in seconds
|
||||
case class TournamentClock(limit: Int, increment: Int) {
|
||||
|
||||
def limitInMinutes = chessClock.limitInMinutes
|
||||
|
||||
def show = chessClock.show
|
||||
|
||||
lazy val chessClock = chess.Clock(limit, increment)
|
||||
|
||||
def hasIncrement = increment > 0
|
||||
|
||||
override def toString = show
|
||||
}
|
|
@ -2,11 +2,12 @@ package lila.tournament
|
|||
|
||||
import org.joda.time.DateTime
|
||||
|
||||
import chess.Clock.{ Config => TournamentClock }
|
||||
import lila.user.User
|
||||
|
||||
private[tournament] case class WaitingUsers(
|
||||
hash: Map[User.ID, DateTime],
|
||||
clock: Option[chess.Clock],
|
||||
clock: Option[TournamentClock],
|
||||
date: DateTime) {
|
||||
|
||||
// hyperbullet -> 10
|
||||
|
@ -43,13 +44,13 @@ private[tournament] case class WaitingUsers(
|
|||
}.toList
|
||||
}
|
||||
|
||||
def update(us: Set[User.ID], clock: Option[chess.Clock]) = {
|
||||
def update(us: Set[User.ID], clock: Option[TournamentClock]) = {
|
||||
val newDate = DateTime.now
|
||||
copy(
|
||||
date = newDate,
|
||||
clock = clock,
|
||||
hash = hash.filterKeys(us.contains) ++
|
||||
us.filterNot(hash.contains).map { _ -> newDate }
|
||||
us.filterNot(hash.contains).map { _ -> newDate }
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
@ -36,7 +36,7 @@ final class CrudApi {
|
|||
|
||||
private def empty = Tournament.make(
|
||||
createdByUserId = "lichess",
|
||||
clock = TournamentClock(0, 0),
|
||||
clock = chess.Clock.Config(0, 0),
|
||||
minutes = 0,
|
||||
system = System.Arena,
|
||||
variant = chess.variant.Standard,
|
||||
|
@ -48,7 +48,7 @@ final class CrudApi {
|
|||
|
||||
private def updateTour(tour: Tournament, data: CrudForm.Data) = {
|
||||
import data._
|
||||
val clock = TournamentClock((clockTime * 60).toInt, clockIncrement)
|
||||
val clock = chess.Clock.Config((clockTime * 60).toInt, clockIncrement)
|
||||
val v = chess.variant.Variant.orDefault(variant)
|
||||
tour.copy(
|
||||
name = name,
|
||||
|
|
Loading…
Reference in New Issue