Manual tables handling

This commit is contained in:
Claude Brisson
2024-07-28 00:07:01 +02:00
parent 7643d88e34
commit ecd973dd22
3 changed files with 18 additions and 6 deletions

View File

@@ -103,6 +103,7 @@ object PairingHandler: PairgothApiHandler {
if (payload.containsKey("h")) game.handicap = payload.getString("h")?.toIntOrNull() ?: badRequest("invalid handicap")
if (payload.containsKey("t")) {
game.table = payload.getString("t")?.toIntOrNull() ?: badRequest("invalid table number")
game.forcedTable = true
}
tournament.dispatchEvent(GameUpdated, request, Json.Object("round" to round, "game" to game.toJson()))
if (game.table != previousTable) {

View File

@@ -11,8 +11,10 @@ data class Game(
var black: ID,
var handicap: Int = 0,
var result: Result = UNKNOWN,
var drawnUpDown: Int = 0 // counted for white (black gets the opposite)
var drawnUpDown: Int = 0, // counted for white (black gets the opposite)
var forcedTable: Boolean = false
) {
companion object {}
enum class Result(val symbol: Char) {
UNKNOWN('?'),
@@ -43,7 +45,8 @@ fun Game.toJson() = Json.Object(
"b" to black,
"h" to handicap,
"r" to "${result.symbol}",
"dd" to drawnUpDown
"dd" to drawnUpDown,
"ft" to forcedTable
)
fun Game.Companion.fromJson(json: Json.Object) = Game(
@@ -53,5 +56,6 @@ fun Game.Companion.fromJson(json: Json.Object) = Game(
black = json.getID("b") ?: throw Error("missing black player"),
handicap = json.getInt("h") ?: 0,
result = json.getChar("r")?.let { Game.Result.fromSymbol(it) } ?: UNKNOWN,
drawnUpDown = json.getInt("dd") ?: 0
drawnUpDown = json.getInt("dd") ?: 0,
forcedTable = json.getBoolean("ft") ?: false
)

View File

@@ -130,11 +130,18 @@ sealed class Tournament <P: Pairable>(
var changed = false
var nextTable = 1
val excluded = excludedTables(round)
games(round).values.filter{ game -> pivot?.let { pivot.id != game.id } ?: true }.sortedBy(orderBY).forEach { game ->
while (excluded.contains(nextTable)) ++nextTable
val forcedTablesGames = games(round).values.filter { game -> game.forcedTable && (pivot == null || game != pivot && game.table != pivot.table) }
val forcedTables = forcedTablesGames.map { game -> game.table }.toSet()
val excludedAndForced = excluded union forcedTables
games(round).values
.filter { game -> pivot?.let { pivot.id != game.id } ?: true }
.filter { game -> !forcedTablesGames.contains(game) }
.sortedBy(orderBY)
.forEach { game ->
while (excludedAndForced.contains(nextTable)) ++nextTable
if (pivot != null && nextTable == pivot.table) {
++nextTable
while (excluded.contains(nextTable)) ++nextTable
while (excludedAndForced.contains(nextTable)) ++nextTable
}
if (game.table != 0) {
changed = changed || game.table != nextTable