From 9008ee5cd65287910299d67ebf2316fddbc3154b Mon Sep 17 00:00:00 2001 From: Theo Barollet Date: Mon, 23 Oct 2023 10:40:40 +0200 Subject: [PATCH] Logistique pour le choix du bye player. --- .../org/jeudego/pairgoth/model/Pairable.kt | 4 +++ .../org/jeudego/pairgoth/pairing/Solver.kt | 29 ++++++++++++++++--- 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/api-webapp/src/main/kotlin/org/jeudego/pairgoth/model/Pairable.kt b/api-webapp/src/main/kotlin/org/jeudego/pairgoth/model/Pairable.kt index 2db36f3..8eac241 100644 --- a/api-webapp/src/main/kotlin/org/jeudego/pairgoth/model/Pairable.kt +++ b/api-webapp/src/main/kotlin/org/jeudego/pairgoth/model/Pairable.kt @@ -17,6 +17,10 @@ sealed class Pairable(val id: ID, val name: String, open val rating: Int, open v return name } val skip = mutableSetOf() // skipped rounds + + fun equals(other: Pairable): Boolean { + return id == other.id + } } object ByePlayer: Pairable(0, "bye", 0, Int.MIN_VALUE) { diff --git a/api-webapp/src/main/kotlin/org/jeudego/pairgoth/pairing/Solver.kt b/api-webapp/src/main/kotlin/org/jeudego/pairgoth/pairing/Solver.kt index 6243bfa..6d26e69 100644 --- a/api-webapp/src/main/kotlin/org/jeudego/pairgoth/pairing/Solver.kt +++ b/api-webapp/src/main/kotlin/org/jeudego/pairgoth/pairing/Solver.kt @@ -36,11 +36,12 @@ private fun nonDetRandom(max: Double) = else Math.random() * (max + 1.0) sealed class Solver( - val round: Int, - val history: List>, - val pairables: List, + val round: Int, // Round number + val history: List>, // History of all games played for each round + var pairables: List, // All pairables for this round, it may include the bye player val pairing: PairingParams, - val placement: PlacementParams + val placement: PlacementParams, + val forcedBye: Pairable? = null, // This parameter is non-null to force the given pairable to be chosen as a bye player. ) { companion object { @@ -112,7 +113,23 @@ sealed class Solver( val Pairable.main: Double get() = scores[id] ?: 0.0 abstract val mainLimits: Pair // SOS and variants will be computed based on this score + fun pair(): List { + // The byeGame is a list of one game with the bye player or an empty list + val byeGame: List = if (pairables.size % 2 != 0) { + // We must choose a bye player + val physicalByePlayer = forcedBye ?: chooseByePlayer() + // Remove the bye from the pairables + pairables = pairables.filterNot { it == physicalByePlayer } + // Assign a special game to the bye player + listOf( Game(Store.nextGameId, physicalByePlayer.id, ByePlayer.id) ) + } else { + listOf() + } + + return listOf(pairEvenNumberOfPlayers(), byeGame).flatten() // Add the bye game to the actual paired games + } + fun pairEvenNumberOfPlayers(): List { // check that at this stage, we have an even number of pairables if (pairables.size % 2 != 0) throw Error("expecting an even number of pairables") val builder = GraphBuilder(SimpleDirectedWeightedGraph(DefaultWeightedEdge::class.java)) @@ -171,6 +188,10 @@ sealed class Solver( } + fun chooseByePlayer(): Pairable { + return ByePlayer + } + // base criteria open fun BaseCritParams.apply(p1: Pairable, p2: Pairable): Double {