fixed solver instantiation for dudd recomputation

This commit is contained in:
Theo Barollet
2023-12-29 15:16:37 +01:00
parent ddd7e74c09
commit 9908e983f0

View File

@@ -4,9 +4,12 @@ import com.republicate.kson.Json
import com.republicate.kson.toJsonArray import com.republicate.kson.toJsonArray
import kotlinx.datetime.LocalDate import kotlinx.datetime.LocalDate
import org.jeudego.pairgoth.api.ApiHandler.Companion.badRequest 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.MacMahonSolver
import org.jeudego.pairgoth.pairing.solver.SwissSolver import org.jeudego.pairgoth.pairing.solver.SwissSolver
import org.jeudego.pairgoth.store.Store import org.jeudego.pairgoth.store.Store
import kotlin.math.max
import kotlin.math.min
import kotlin.math.roundToInt import kotlin.math.roundToInt
sealed class Tournament <P: Pairable>( sealed class Tournament <P: Pairable>(
@@ -72,11 +75,12 @@ sealed class Tournament <P: Pairable>(
// Instantiate solver with game history // Instantiate solver with game history
// TODO cleaner solver instantiation // TODO cleaner solver instantiation
val history = games.map { games -> games.values.toList() } val history = games.map { games -> games.values.toList() }
val solver = when (pairing.type) { val solver = if (pairing is Swiss) {
PairingType.SWISS -> SwissSolver(round, history, pairables.values.toList(), pairing.pairingParams, pairing.placementParams) 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 if (pairing is MacMahon) {
else -> throw Exception("Invalid tournament type") MacMahonSolver(round, history, pairables.values.toList(), pairing.pairingParams, pairing.placementParams, pairing.mmBar, pairing.mmFloor)
} } else throw Exception("Invalid tournament type")
// Recomputes DUDD // Recomputes DUDD
val game = games(round)[gameID]!! val game = games(round)[gameID]!!
val whiteplayer = solver.pairables.find { p-> p.id == game.white }!! val whiteplayer = solver.pairables.find { p-> p.id == game.white }!!