Do not renumber tables when the new forced table is free
This commit is contained in:
@@ -105,23 +105,30 @@ object PairingHandler: PairgothApiHandler {
|
|||||||
}
|
}
|
||||||
tournament.dispatchEvent(GameUpdated, request, Json.Object("round" to round, "game" to game.toJson()))
|
tournament.dispatchEvent(GameUpdated, request, Json.Object("round" to round, "game" to game.toJson()))
|
||||||
if (game.table != previousTable) {
|
if (game.table != previousTable) {
|
||||||
val sortedPairables = tournament.getSortedPairables(round)
|
val tableWasOccupied = ( tournament.games(round).values.find { g -> g != game && g.table == game.table } != null )
|
||||||
val sortedMap = sortedPairables.associateBy {
|
if (tableWasOccupied) {
|
||||||
it.getID()!!
|
// some renumbering is necessary
|
||||||
}
|
val sortedPairables = tournament.getSortedPairables(round)
|
||||||
val changed = tournament.renumberTables(round, game) { game ->
|
val sortedMap = sortedPairables.associateBy {
|
||||||
val whitePosition = sortedMap[game.white]?.getInt("num") ?: Int.MIN_VALUE
|
it.getID()!!
|
||||||
val blackPosition = sortedMap[game.black]?.getInt("num") ?: Int.MIN_VALUE
|
}
|
||||||
(whitePosition + blackPosition)
|
val changed = tournament.renumberTables(round, game) { game ->
|
||||||
}
|
val whitePosition = sortedMap[game.white]?.getInt("num") ?: Int.MIN_VALUE
|
||||||
if (changed) {
|
val blackPosition = sortedMap[game.black]?.getInt("num") ?: Int.MIN_VALUE
|
||||||
val games = tournament.games(round).values.sortedBy {
|
(whitePosition + blackPosition)
|
||||||
if (it.table == 0) Int.MAX_VALUE else it.table
|
}
|
||||||
|
if (changed) {
|
||||||
|
val games = tournament.games(round).values.sortedBy {
|
||||||
|
if (it.table == 0) Int.MAX_VALUE else it.table
|
||||||
|
}
|
||||||
|
tournament.dispatchEvent(
|
||||||
|
TablesRenumbered, request,
|
||||||
|
Json.Object(
|
||||||
|
"round" to round,
|
||||||
|
"games" to games.map { it.toJson() }.toCollection(Json.MutableArray())
|
||||||
|
)
|
||||||
|
)
|
||||||
}
|
}
|
||||||
tournament.dispatchEvent(
|
|
||||||
TablesRenumbered, request,
|
|
||||||
Json.Object("round" to round, "games" to games.map { it.toJson() }.toCollection(Json.MutableArray()))
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return Json.Object("success" to true)
|
return Json.Object("success" to true)
|
||||||
|
Reference in New Issue
Block a user