Skip to content
Draft
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
4 changes: 3 additions & 1 deletion modules/tournament/src/main/PlanBuilder.scala
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ object PlanBuilder:
val s2 = si2.schedule
s1.variant == s2.variant && (
// prevent daily && weekly within X hours of each other
if s1.freq.isDailyOrBetter && s2.freq.isDailyOrBetter && s1.sameSpeed(s2) then
if s1.freq.isDailyOrBetter && s2.freq.isDailyOrBetter &&
(s1.variant.exotic || s1.sameSpeed(s2))
then
si2.startsAt.minusMinutes(SCHEDULE_DAILY_OVERLAP_MINS).isBefore(endsAt) &&
startsAt.minusMinutes(SCHEDULE_DAILY_OVERLAP_MINS).isBefore(si2.endsAt)
else
Expand Down
7 changes: 4 additions & 3 deletions modules/tournament/src/main/Schedule.scala
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,6 @@ object Schedule:

private val standardIncHours = Set(1, 7, 13, 19)
private def standardInc(s: Schedule) = standardIncHours(s.at.getHour)
private def zhInc(s: Schedule) = s.at.getHour % 2 == 0
private def bottomOfHour(s: Schedule) = s.at.getMinute > 29

private given Conversion[Int, LimitSeconds] = LimitSeconds(_)
Expand All @@ -211,10 +210,12 @@ object Schedule:
(s.freq, s.variant, s.speed) match
// Special cases.
case (Weekend, Crazyhouse, Blitz) => zhEliteTc(s)
case (Hourly, Crazyhouse, SuperBlitz) if zhInc(s) => TC(3 * 60, 1)
case (Hourly, Crazyhouse, Blitz) if zhInc(s) => TC(4 * 60, 2)
case (Hourly, Standard, Blitz) if standardInc(s) => TC(3 * 60, 2)
case (Hourly, Standard, Bullet) if s.hasMaxRating && bottomOfHour(s) => TC(60, 1)
case (Hourly, variant, Blitz) if variant.exotic => TC(3 * 60, 2)
case (Hourly, Antichess | Atomic, Bullet) if bottomOfHour(s) => TC(0, 2)
case (Hourly, variant, HippoBullet) if variant.exotic => TC(60, 2)
case (Hourly, Antichess, Bullet) if bottomOfHour(s) => TC(0, 2)

case (Shield, variant, Blitz) if variant.exotic => TC(3 * 60, 2)

Expand Down
185 changes: 108 additions & 77 deletions modules/tournament/src/main/TournamentScheduler.scala
Original file line number Diff line number Diff line change
Expand Up @@ -258,21 +258,21 @@ Thank you all, you rock!""".some,
// Note: these should be scheduled close to the hour of weekly variant tournaments
// to avoid two dailies being cancelled in a row from a single higher importance tourney
List( // daily variant tournaments!
at(today, 20).pipe: date =>
Schedule(Daily, Blitz, Crazyhouse, none, date.pipe(orTomorrow)).plan,
at(today, 21).pipe: date =>
Schedule(Daily, Blitz, Chess960, none, date.pipe(orTomorrow)).plan,
at(today, 22).pipe: date =>
Schedule(Daily, SuperBlitz, KingOfTheHill, none, date.pipe(orTomorrow)).plan,
at(today, 23).pipe: date =>
at(today, 18).pipe: date =>
Schedule(Daily, SuperBlitz, Crazyhouse, none, date.pipe(orTomorrow)).plan,
at(today, 18).pipe: date =>
Schedule(Daily, SuperBlitz, Atomic, none, date.pipe(orTomorrow)).plan,
at(today, 0).pipe: date =>
at(today, 19).pipe: date =>
Schedule(Daily, SuperBlitz, Chess960, none, date.pipe(orTomorrow)).plan,
at(today, 19).pipe: date =>
Schedule(Daily, SuperBlitz, Antichess, none, date.pipe(orTomorrow)).plan,
at(tomorrow, 1).pipe: date =>
at(tomorrow, 20).pipe: date =>
Schedule(Daily, SuperBlitz, ThreeCheck, none, date).plan,
at(tomorrow, 2).pipe: date =>
at(tomorrow, 20).pipe: date =>
Schedule(Daily, SuperBlitz, Horde, none, date).plan,
at(tomorrow, 3).pipe: date =>
at(today, 21).pipe: date =>
Schedule(Daily, SuperBlitz, KingOfTheHill, none, date.pipe(orTomorrow)).plan,
at(today, 21).pipe: date =>
Schedule(Daily, SuperBlitz, RacingKings, none, date).plan
),
List( // eastern tournaments!
Expand Down Expand Up @@ -361,75 +361,106 @@ Thank you all, you rock!""".some,
// Because berserking lowers the player rating
_.map { _.copy(noBerserk = true) }
},
// hourly crazyhouse/chess960/KingOfTheHill tournaments!
(0 to 6).toList.flatMap { hourDelta =>
val when = atTopOfHour(rightNow, hourDelta)
val speed = when.getHour % 7 match
case 0 => HippoBullet
case 1 | 4 => Bullet
case 2 | 5 => SuperBlitz
case 3 | 6 => Blitz
val variant = when.getHour % 3 match
case 0 => Chess960
case 1 => KingOfTheHill
case _ => Crazyhouse
List(Schedule(Hourly, speed, variant, none, when).plan) :::
(speed == Bullet).so:
List(
Schedule(
Hourly,
if when.getHour == 17 then HyperBullet else Bullet,
variant,
none,
when.plusMinutes(30)
).plan
)
},
// hourly atomic/antichess variant tournaments!
(0 to 6).toList.flatMap { hourDelta =>
val when = atTopOfHour(rightNow, hourDelta)
val speed = when.getHour % 7 match
case 0 | 4 => Blitz

// fast popular variant tournaments -- 2/3 of the time
for
variant <- List(Antichess)
hourDelta <- (-1 to 6).toList
when = atTopOfHour(rightNow, hourDelta)
// Offsets should be balanced mod 3 between all 6 variants at 2/3 hours
variantCycle = when.getHour + variant.match
case Antichess => 2
if variantCycle % 3 != 0
// assignments for TCs when variantCycle % 3 == 0 don't currently
// matter, as those hours are excluded from the schedule.
// Meaning values of 0, 3, 6, 9 do not occur, and there are
// just 8 relevant hours in the repeating cycle.
speed = variantCycle % 12 match
// 8 should be assigned to bullet, so that the hyperbullet check succeeds
case 2 | 5 | 8 | 11 => Bullet
case 1 => HippoBullet
case 2 | 5 => Bullet
case 3 | 6 => SuperBlitz
val variant = if when.getHour % 2 == 0 then Atomic else Antichess
List(Schedule(Hourly, speed, variant, none, when).plan) :::
(speed == Bullet).so:
List(
Schedule(
Hourly,
if when.getHour == 18 then HyperBullet else Bullet,
variant,
none,
when.plusMinutes(30)
).plan
)
},
// hourly threecheck/horde/racing variant tournaments!
(0 to 6).toList.flatMap { hourDelta =>
val when = atTopOfHour(rightNow, hourDelta)
val speed = when.getHour % 7 match
case 0 | 4 => SuperBlitz
case 1 | 5 => Blitz
case 4 | 7 => Blitz
case _ => SuperBlitz
first = Schedule(Hourly, speed, variant, none, when)
second = Option.when(speed == Bullet):
val speed = if variantCycle % 12 == 8 then HyperBullet else Bullet
Schedule(Hourly, speed, variant, none, when.plusMinutes(30))
schedule <- first :: second.toList
yield schedule.plan,

// medium speed variants
for
variant <- List(Atomic, ThreeCheck)
hourDelta <- (-1 to 6).toList
when = atTopOfHour(rightNow, hourDelta)
// Offsets should be balanced mod 3 between all 6 variants at 2/3 hours
variantCycle = when.getHour + variant.match
case Atomic => 0
case ThreeCheck => 2
if variantCycle % 3 != 0
// assignments for TCs when variantCycle % 3 == 0 don't currently
// matter, as those hours are excluded from the schedule.
// Meaning values of 0, 3, 6, 9 do not occur, and there are
// just 8 relevant hours in the repeating cycle.
speed = variantCycle % 12 match
case 2 | 5 => Blitz
case 1 | 8 => SuperBlitz
case 4 => HippoBullet
case 7 | 11 | _ => Bullet
first = Schedule(Hourly, speed, variant, none, when)
second = Option.when(speed == Bullet):
val speed = if variantCycle % 12 == 7 then HyperBullet else Bullet
Schedule(Hourly, speed, variant, none, when.plusMinutes(30))
schedule <- first :: second.toList
yield schedule.plan,

// slow variant hourlies
for
variant <- List(Crazyhouse, Chess960, KingOfTheHill)
hourDelta <- (-1 to 6).toList
when = atTopOfHour(rightNow, hourDelta)
// Offsets should be balanced mod 3 between all 6 variants at 2/3 hours
variantCycle = when.getHour + variant.match
case Crazyhouse => 1
case Chess960 => 0
case KingOfTheHill => 1
if variantCycle % 3 != 0
// assignments for TCs when variantCycle % 3 == 0 don't currently
// matter, as those hours are excluded from the schedule.
// Meaning values of 0, 3, 6, 9 do not occur, and there are
// just 8 relevant hours in the repeating cycle.
speed = variantCycle % 12 match
case 2 | 5 | 8 => Blitz
case 1 | 7 => SuperBlitz
case 4 | 11 => HippoBullet
case _ => Bullet
first = Schedule(Hourly, speed, variant, none, when)
second = Option.when(speed == Bullet):
val speed = if variantCycle % 12 == 10 then HyperBullet else Bullet
Schedule(Hourly, speed, variant, none, when.plusMinutes(30))
schedule <- first :: second.toList
yield schedule.plan,

// hourly exotic variant tournaments
for
hourDelta <- (-1 to 6).toList
when = atTopOfHour(rightNow, hourDelta)
// Avoid grouping TCs by mod 2, so that the distribution doesn't
// get skewed as we alternate between 2 variants.
speed = when.getHour % 5 match
case 0 => SuperBlitz
case 1 => Blitz
case 2 => HippoBullet
case 3 | 6 => Bullet
val variant = when.getHour % 3 match
case 0 => ThreeCheck
case 1 => Horde
case 3 | _ => Bullet
variant = when.getHour % 2 match
case 0 => Horde
case _ => RacingKings
List(Schedule(Hourly, speed, variant, none, when).plan) :::
(speed == Bullet).so:
List(
Schedule(
Hourly,
if when.getHour == 19 then HyperBullet else Bullet,
variant,
none,
when.plusMinutes(30)
).plan
)
}
first = Schedule(Hourly, speed, variant, none, when)
second = Option.when(speed == Bullet):
val speed = if when.getHour == 19 then HyperBullet else Bullet
Schedule(Hourly, speed, variant, none, when.plusMinutes(30))
schedule <- first :: second.toList
yield schedule.plan
).flatten.filter(_.schedule.at.isAfter(rightNow))

private def atTopOfHour(rightNow: LocalDateTime, hourDelta: Int): LocalDateTime =
Expand Down
Loading