From 9908e983f0df590f166d8c64d74305ec84c038f0 Mon Sep 17 00:00:00 2001 From: Theo Barollet Date: Fri, 29 Dec 2023 15:16:37 +0100 Subject: [PATCH] fixed solver instantiation for dudd recomputation --- .../org/jeudego/pairgoth/model/Tournament.kt | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/api-webapp/src/main/kotlin/org/jeudego/pairgoth/model/Tournament.kt b/api-webapp/src/main/kotlin/org/jeudego/pairgoth/model/Tournament.kt index b380dd6..2b80e20 100644 --- a/api-webapp/src/main/kotlin/org/jeudego/pairgoth/model/Tournament.kt +++ b/api-webapp/src/main/kotlin/org/jeudego/pairgoth/model/Tournament.kt @@ -4,9 +4,12 @@ import com.republicate.kson.Json import com.republicate.kson.toJsonArray import kotlinx.datetime.LocalDate import org.jeudego.pairgoth.api.ApiHandler.Companion.badRequest +import org.jeudego.pairgoth.pairing.HistoryHelper import org.jeudego.pairgoth.pairing.solver.MacMahonSolver import org.jeudego.pairgoth.pairing.solver.SwissSolver import org.jeudego.pairgoth.store.Store +import kotlin.math.max +import kotlin.math.min import kotlin.math.roundToInt sealed class Tournament ( @@ -72,11 +75,12 @@ sealed class Tournament ( // Instantiate solver with game history // TODO cleaner solver instantiation val history = games.map { games -> games.values.toList() } - val solver = when (pairing.type) { - PairingType.SWISS -> SwissSolver(round, history, pairables.values.toList(), pairing.pairingParams, pairing.placementParams) - PairingType.MAC_MAHON -> MacMahonSolver(round, history, pairables.values.toList(), pairing.pairingParams, pairing.placementParams, mmBar = 3, mmFloor = -20) - else -> throw Exception("Invalid tournament type") - } + val solver = if (pairing is Swiss) { + SwissSolver(round, history, pairables.values.toList(), pairing.pairingParams, pairing.placementParams) + } else if (pairing is MacMahon) { + MacMahonSolver(round, history, pairables.values.toList(), pairing.pairingParams, pairing.placementParams, pairing.mmBar, pairing.mmFloor) + } else throw Exception("Invalid tournament type") + // Recomputes DUDD val game = games(round)[gameID]!! val whiteplayer = solver.pairables.find { p-> p.id == game.white }!!