Table handling
This commit is contained in:
@@ -151,6 +151,7 @@ object OpenGotha {
|
|||||||
it.value.map { game ->
|
it.value.map { game ->
|
||||||
Game(
|
Game(
|
||||||
id = Store.nextGameId,
|
id = Store.nextGameId,
|
||||||
|
table = game.tableNumber,
|
||||||
black = canonicMap[game.blackPlayer] ?: throw Error("player not found: ${game.blackPlayer}"),
|
black = canonicMap[game.blackPlayer] ?: throw Error("player not found: ${game.blackPlayer}"),
|
||||||
white = canonicMap[game.whitePlayer] ?: throw Error("player not found: ${game.whitePlayer}"),
|
white = canonicMap[game.whitePlayer] ?: throw Error("player not found: ${game.whitePlayer}"),
|
||||||
handicap = game.handicap,
|
handicap = game.handicap,
|
||||||
|
@@ -6,6 +6,7 @@ import java.util.*
|
|||||||
|
|
||||||
data class Game(
|
data class Game(
|
||||||
val id: ID,
|
val id: ID,
|
||||||
|
var table: Int,
|
||||||
var white: ID,
|
var white: ID,
|
||||||
var black: ID,
|
var black: ID,
|
||||||
var handicap: Int = 0,
|
var handicap: Int = 0,
|
||||||
@@ -33,6 +34,7 @@ data class Game(
|
|||||||
|
|
||||||
fun Game.toJson() = Json.Object(
|
fun Game.toJson() = Json.Object(
|
||||||
"id" to id,
|
"id" to id,
|
||||||
|
"t" to table,
|
||||||
"w" to white,
|
"w" to white,
|
||||||
"b" to black,
|
"b" to black,
|
||||||
"h" to handicap,
|
"h" to handicap,
|
||||||
@@ -42,6 +44,7 @@ fun Game.toJson() = Json.Object(
|
|||||||
|
|
||||||
fun Game.Companion.fromJson(json: Json.Object) = Game(
|
fun Game.Companion.fromJson(json: Json.Object) = Game(
|
||||||
id = json.getID("id") ?: throw Error("missing game id"),
|
id = json.getID("id") ?: throw Error("missing game id"),
|
||||||
|
table = json.getInt("t") ?: throw Error("missing game table"),
|
||||||
white = json.getID("w") ?: throw Error("missing white player"),
|
white = json.getID("w") ?: throw Error("missing white player"),
|
||||||
black = json.getID("b") ?: throw Error("missing black player"),
|
black = json.getID("b") ?: throw Error("missing black player"),
|
||||||
handicap = json.getInt("h") ?: 0,
|
handicap = json.getInt("h") ?: 0,
|
||||||
|
@@ -1,6 +1,7 @@
|
|||||||
package org.jeudego.pairgoth.pairing
|
package org.jeudego.pairgoth.pairing
|
||||||
|
|
||||||
import org.jeudego.pairgoth.model.*
|
import org.jeudego.pairgoth.model.*
|
||||||
|
import java.util.*
|
||||||
|
|
||||||
abstract class BasePairingHelper(
|
abstract class BasePairingHelper(
|
||||||
history: List<List<Game>>, // History of all games played for each round
|
history: List<List<Game>>, // History of all games played for each round
|
||||||
@@ -131,4 +132,11 @@ abstract class BasePairingHelper(
|
|||||||
open fun nameSort(p: Pairable, q: Pairable): Int {
|
open fun nameSort(p: Pairable, q: Pairable): Int {
|
||||||
return if (p.name > q.name) 1 else -1
|
return if (p.name > q.name) 1 else -1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val tables = history.mapTo(mutableListOf()) { games ->
|
||||||
|
games.map { it.table }.fold(BitSet()) { acc, table ->
|
||||||
|
acc.set(table)
|
||||||
|
acc
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
@@ -121,7 +121,7 @@ sealed class BaseSolver(
|
|||||||
|
|
||||||
var result = sorted.flatMap { games(white = it[0], black = it[1]) }
|
var result = sorted.flatMap { games(white = it[0], black = it[1]) }
|
||||||
// add game for ByePlayer
|
// add game for ByePlayer
|
||||||
if (chosenByePlayer != ByePlayer) result += Game(id = Store.nextGameId, white = ByePlayer.id, black = chosenByePlayer.id, result = Game.Result.fromSymbol('b'))
|
if (chosenByePlayer != ByePlayer) result += Game(id = Store.nextGameId, table = 0, white = ByePlayer.id, black = chosenByePlayer.id, result = Game.Result.fromSymbol('b'))
|
||||||
|
|
||||||
if (DEBUG_EXPORT_WEIGHT) {
|
if (DEBUG_EXPORT_WEIGHT) {
|
||||||
println("DUDD debug")
|
println("DUDD debug")
|
||||||
@@ -510,7 +510,9 @@ sealed class BaseSolver(
|
|||||||
|
|
||||||
open fun games(black: Pairable, white: Pairable): List<Game> {
|
open fun games(black: Pairable, white: Pairable): List<Game> {
|
||||||
// CB TODO team of individuals pairing
|
// CB TODO team of individuals pairing
|
||||||
|
val usedTables = tables.getOrNull(round - 1) ?: BitSet().also { tables.add(it) }
|
||||||
return listOf(Game(id = Store.nextGameId, black = black.id, white = white.id, handicap = pairing.handicap.handicap(black, white), drawnUpDown = white.group-black.group))
|
val table = if (black.id == 0 || white.id == 0) 0 else usedTables.nextClearBit(1)
|
||||||
|
usedTables.set(table)
|
||||||
|
return listOf(Game(id = Store.nextGameId, table = table, black = black.id, white = white.id, handicap = pairing.handicap.handicap(white, black), drawnUpDown = white.group-black.group))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -90,11 +90,15 @@ class FileStore(pathStr: String): StoreImplementation {
|
|||||||
}
|
}
|
||||||
val games = json["games"] as Json.Array? ?: Json.Array()
|
val games = json["games"] as Json.Array? ?: Json.Array()
|
||||||
(1..games.size).forEach { round ->
|
(1..games.size).forEach { round ->
|
||||||
|
var nextDefaultTable = 1;
|
||||||
val roundGames = games[round - 1] as Json.Array
|
val roundGames = games[round - 1] as Json.Array
|
||||||
tournament.games(round).putAll(
|
tournament.games(round).putAll(
|
||||||
roundGames.associate {
|
roundGames.associate {
|
||||||
(it as Json.Object).let { game ->
|
(it as Json.Object).let { game ->
|
||||||
Pair(game.getID("id") ?: throw Error("invalid tournament file"), Game.fromJson(game)).also {
|
val fixedGame =
|
||||||
|
if (game.containsKey("t")) game
|
||||||
|
else Json.MutableObject(game).set("t", nextDefaultTable++)
|
||||||
|
Pair(game.getID("id") ?: throw Error("invalid tournament file"), Game.fromJson(fixedGame)).also {
|
||||||
maxGameId = max(maxGameId, it.first)
|
maxGameId = max(maxGameId, it.first)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user