Skip to content
Merged
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
10 changes: 10 additions & 0 deletions app/views/simul/form.scala
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,16 @@ object form:
)(
form3.select(_, clockExtraChoices)
),
form3.group(
form("clockExtraPerPlayer"),
trans.simulHostExtraTimePerPlayer(),
help = trans.simulAddExtraTimePerPlayer().some,
half = true
)(
form3.select(_, clockExtraPerPlayerChoices)
)
),
form3.split(
form3.group(form("color"), trans.simulHostcolor(), half = true)(
form3.select(_, colorChoices)
)
Expand Down
17 changes: 14 additions & 3 deletions app/views/simul/show.scala
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,24 @@ object show:
),
trans.simulHostExtraTime(),
": ",
pluralize("minute", sim.clock.hostExtraMinutes),
pluralize("minute", sim.clock.hostExtraMinutes.value),
br,
trans.hostColorX(sim.color match {
sim.clock.hostExtraTimePerPlayerForDisplay.map { time =>
frag(
trans.simulHostExtraTimePerPlayer(),
": ",
time match
case Left(minutes) => pluralize("minute", minutes.value)
case Right(seconds) => pluralize("second", seconds.value)
,
br
)
},
trans.hostColorX(sim.color match
case Some("white") => trans.white()
case Some("black") => trans.black()
case _ => trans.randomColor()
}),
),
sim.position.flatMap(p => lila.tournament.Thematic.byFen(p.opening)) map { pos =>
frag(br, a(targetBlank, href := pos.url)(pos.name))
} orElse sim.position.map { fen =>
Expand Down
2 changes: 2 additions & 0 deletions modules/i18n/src/main/I18nKeys.scala
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,8 @@ object I18nKeys:
val `simulClockHint` = I18nKey("simulClockHint")
val `simulAddExtraTime` = I18nKey("simulAddExtraTime")
val `simulHostExtraTime` = I18nKey("simulHostExtraTime")
val `simulAddExtraTimePerPlayer` = I18nKey("simulAddExtraTimePerPlayer")
val `simulHostExtraTimePerPlayer` = I18nKey("simulHostExtraTimePerPlayer")
val `lichessTournaments` = I18nKey("lichessTournaments")
val `tournamentFAQ` = I18nKey("tournamentFAQ")
val `timeBeforeTournamentStarts` = I18nKey("timeBeforeTournamentStarts")
Expand Down
1 change: 1 addition & 0 deletions modules/simul/src/main/Simul.scala
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ case class Simul(
status = SimulStatus.Started,
startedAt = nowDate.some,
applicants = Nil,
clock = clock.adjustedForPlayers(nbAccepted),
pairings = applicants collect {
case a if a.accepted => SimulPairing(a.player)
},
Expand Down
20 changes: 15 additions & 5 deletions modules/simul/src/main/SimulClock.scala
Original file line number Diff line number Diff line change
@@ -1,23 +1,33 @@
package lila.simul

import chess.{ Centis, Clock, Color }
import chess.Clock.{ LimitSeconds, LimitMinutes }

// All durations are expressed in seconds
case class SimulClock(
config: Clock.Config,
hostExtraTime: Int
hostExtraTime: LimitSeconds,
hostExtraTimePerPlayer: LimitSeconds
):

def chessClockOf(hostColor: Color) =
config.toClock.giveTime(
hostColor,
Centis.ofSeconds {
hostExtraTime.atLeast(-config.limitSeconds.value + 20)
hostExtraTime.atLeast(-config.limitSeconds + 20).value
}
)

def hostExtraMinutes = hostExtraTime / 60
def hostExtraMinutes = LimitMinutes(hostExtraTime.value / 60)
def hostExtraTimePerPlayerForDisplay: Option[Either[LimitMinutes, LimitSeconds]] =
hostExtraTimePerPlayer > 0 option (
if hostExtraTimePerPlayer.value % 60 == 0 then Left(LimitMinutes(hostExtraTimePerPlayer.value / 60))
else Right(LimitSeconds(hostExtraTimePerPlayer.value))
)

def adjustedForPlayers(numberOfPlayers: Int) =
copy(hostExtraTime = hostExtraTime + numberOfPlayers * hostExtraTimePerPlayer.value)

def valid =
if (config.limitSeconds.value + hostExtraTime == 0) config.incrementSeconds >= 10
if config.limitSeconds + hostExtraTime == LimitSeconds(0)
then config.incrementSeconds >= 10
else config.limitSeconds + hostExtraTime > 0
31 changes: 19 additions & 12 deletions modules/simul/src/main/SimulForm.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,25 @@ import chess.Clock.{ LimitMinutes, LimitSeconds, IncrementSeconds }

object SimulForm:

val clockTimes = LimitMinutes.from((5 to 15 by 5) ++ (20 to 90 by 10) ++ (120 to 180 by 20))
val clockTimeChoices = options((5 to 15 by 5) ++ (20 to 90 by 10) ++ (120 to 180 by 20), "%d minute{s}")
val clockTimeDefault = LimitMinutes(20)
val clockTimeChoices = options(LimitMinutes raw clockTimes, "%d minute{s}")

val clockIncrements = IncrementSeconds.from(
(0 to 2 by 1) ++ (3 to 7) ++ (10 to 30 by 5) ++ (40 to 60 by 10) ++ (90 to 180 by 30)
val clockIncrementChoices = options(
(0 to 2 by 1) ++ (3 to 7) ++ (10 to 30 by 5) ++ (40 to 60 by 10) ++ (90 to 180 by 30),
"%d second{s}"
)
val clockIncrementDefault = IncrementSeconds(60)
val clockIncrementChoices = options(IncrementSeconds raw clockIncrements, "%d second{s}")

val clockExtrasPositive = (0 to 15 by 5) ++ (20 to 60 by 10) ++ (90 to 120 by 30)
val clockExtras = clockExtrasPositive.tail.map(-_).reverse concat clockExtrasPositive
val clockExtraChoices = options(clockExtras, "%d minute{s}") map {
case (d, str) if d > 0 => (d, s"+$str")
case pair => pair
}
val clockExtraDefault = 0
val clockExtraDefault = LimitMinutes(0)

val clockExtraPerPlayerChoices = options((0 to 60 by 10) ++ Seq(90, 120, 180, 240, 300), "%d second{s}")
val clockExtraPerPlayerDefault = LimitSeconds(0)

val colors = List("white", "random", "black")
val colorChoices = List(
Expand Down Expand Up @@ -63,6 +65,7 @@ object SimulForm:
clockTime = clockTimeDefault,
clockIncrement = clockIncrementDefault,
clockExtra = clockExtraDefault,
clockExtraPerPlayer = clockExtraPerPlayerDefault,
variants = List(chess.variant.Standard.id),
position = none,
color = colorDefault,
Expand All @@ -78,6 +81,7 @@ object SimulForm:
clockTime = LimitMinutes(simul.clock.config.limitInMinutes.toInt),
clockIncrement = simul.clock.config.incrementSeconds,
clockExtra = simul.clock.hostExtraMinutes,
clockExtraPerPlayer = simul.clock.hostExtraTimePerPlayer,
variants = simul.variants.map(_.id),
position = simul.position,
color = simul.color | "random",
Expand All @@ -90,10 +94,11 @@ object SimulForm:
private def baseForm(host: User, teams: List[LeaderTeam]) =
Form(
mapping(
"name" -> nameType(host),
"clockTime" -> numberIn(clockTimeChoices).into[LimitMinutes],
"clockIncrement" -> numberIn(clockIncrementChoices).into[IncrementSeconds],
"clockExtra" -> numberIn(clockExtraChoices),
"name" -> nameType(host),
"clockTime" -> numberIn(clockTimeChoices).into[LimitMinutes],
"clockIncrement" -> numberIn(clockIncrementChoices).into[IncrementSeconds],
"clockExtra" -> numberIn(clockExtraChoices).into[LimitMinutes],
"clockExtraPerPlayer" -> numberIn(clockExtraPerPlayerChoices).into[LimitSeconds],
"variants" -> list {
typeIn(Variant.list.all.filter(chess.variant.FromPosition != _).map(_.id).toSet)
}.verifying("At least one variant", _.nonEmpty),
Expand All @@ -113,7 +118,8 @@ object SimulForm:
name: String,
clockTime: LimitMinutes,
clockIncrement: IncrementSeconds,
clockExtra: Int,
clockExtra: LimitMinutes,
clockExtraPerPlayer: LimitSeconds,
variants: List[Variant.Id],
position: Option[Fen.Epd],
color: String,
Expand All @@ -126,7 +132,8 @@ object SimulForm:
def clock =
SimulClock(
config = Clock.Config(LimitSeconds(clockTime.value * 60), clockIncrement),
hostExtraTime = clockExtra * 60
hostExtraTime = LimitSeconds(clockExtra.value * 60),
hostExtraTimePerPlayer = clockExtraPerPlayer
)

def actualVariants = variants.flatMap { Variant(_) }
Expand Down
6 changes: 4 additions & 2 deletions translation/source/site.xml
Original file line number Diff line number Diff line change
Expand Up @@ -661,8 +661,10 @@ computer analysis, game chat and shareable URL.</string>
<string name="whenCreateSimul">When you create a Simul, you get to play several players at once.</string>
<string name="simulVariantsHint">If you select several variants, each player gets to choose which one to play.</string>
<string name="simulClockHint">Fischer Clock setup. The more players you take on, the more time you may need.</string>
<string name="simulAddExtraTime">You may add extra time to your clock to help you cope with the simul.</string>
<string name="simulHostExtraTime">Host extra clock time</string>
<string name="simulAddExtraTime">You may add extra initial time to your clock to help you cope with the simul.</string>
<string name="simulHostExtraTime">Host extra initial clock time</string>
<string name="simulAddExtraTimePerPlayer">Add initial time to your clock for each player joining the simul.</string>
<string name="simulHostExtraTimePerPlayer">Host extra clock time per player</string>
<string name="lichessTournaments">Lichess tournaments</string>
<string name="tournamentFAQ">Arena tournament FAQ</string>
<string name="timeBeforeTournamentStarts">Time before tournament starts</string>
Expand Down