Convert pairing criteria to double instead of int

This commit is contained in:
Theo Barollet
2023-06-14 10:03:31 +02:00
parent c6ec89cb9d
commit 526f4990b0
4 changed files with 28 additions and 28 deletions

View File

@@ -4,20 +4,20 @@ import org.jeudego.pairgoth.model.*
open class HistoryHelper(protected val history: List<Game>, computeScore: () -> Map<ID, Double>) {
fun getCriterionValue(p: Pairable, crit: PlacementCriterion): Int {
fun getCriterionValue(p: Pairable, crit: PlacementCriterion): Double {
// Returns generic criterion
// Specific criterion are computed by solvers directly
return when (crit) {
PlacementCriterion.NULL -> 0
PlacementCriterion.NULL -> 0.0
PlacementCriterion.CATEGORY -> TODO()
PlacementCriterion.RANK -> p.rank
PlacementCriterion.RATING -> p.rating
PlacementCriterion.RANK -> p.rank.toDouble()
PlacementCriterion.RATING -> p.rating.toDouble()
PlacementCriterion.EXT -> TODO()
PlacementCriterion.EXR -> TODO()
PlacementCriterion.SDC -> TODO()
PlacementCriterion.DC -> TODO()
else -> -1
else -> -1.0
}
}
// Generic helper functions

View File

@@ -23,17 +23,17 @@ class MacMahonSolver(round: Int, history: List<Game>, pairables: List<Pairable>,
TODO("Not yet implemented")
}
override fun getSpecificCriterionValue(p: Pairable, criterion: PlacementCriterion): Int {
override fun getSpecificCriterionValue(p: Pairable, criterion: PlacementCriterion): Double {
// TODO solve this double/int conflict
return when (criterion) {
PlacementCriterion.MMS -> TODO()
PlacementCriterion.SOSM -> p.sos.toInt()
PlacementCriterion.SOSMM1 -> p.sosm1.toInt()
PlacementCriterion.SOSMM2 -> p.sosm2.toInt()
PlacementCriterion.SODOSM -> p.sodos.toInt()
PlacementCriterion.SOSOSM -> p.sosos.toInt()
PlacementCriterion.CUSSM -> p.cums.toInt()
else -> -1
PlacementCriterion.SOSM -> p.sos
PlacementCriterion.SOSMM1 -> p.sosm1
PlacementCriterion.SOSMM2 -> p.sosm2
PlacementCriterion.SODOSM -> p.sodos
PlacementCriterion.SOSOSM -> p.sosos
PlacementCriterion.CUSSM -> p.cums
else -> -1.0
}
}

View File

@@ -61,7 +61,7 @@ sealed class Solver(
val criterionP = getCriterionValue(p, criterion)
val criterionQ = getCriterionValue(q, criterion)
if (criterionP != criterionQ) {
return criterionP - criterionQ
return (criterionP - criterionQ).toInt()
}
}
return 0
@@ -83,20 +83,20 @@ sealed class Solver(
// SOS and variants will be computed based on this score
abstract fun computeStandingScore(): Map<ID, Double>
// This function needs to be overridden for criterion specific to the current pairing mode
open fun getSpecificCriterionValue(p1: Pairable, criterion: PlacementCriterion): Int {
return -1
open fun getSpecificCriterionValue(p1: Pairable, criterion: PlacementCriterion): Double {
return -1.0
}
private fun getCriterionValue(p1: Pairable, criterion: PlacementCriterion): Int {
private fun getCriterionValue(p1: Pairable, criterion: PlacementCriterion): Double {
val genericCritVal = historyHelper.getCriterionValue(p1, criterion)
// If the value from the history helper is > 0 it means that it is a generic criterion
// Just returns the value
if (genericCritVal != -1) {
if (genericCritVal < 0) {
return genericCritVal
}
// Otherwise we have to delegate it to the solver
val critVal = getSpecificCriterionValue(p1, criterion)
if (critVal == -1) throw Error("Couldn't compute criterion value")
if (critVal < 0) throw Error("Couldn't compute criterion value")
return critVal
}

View File

@@ -23,17 +23,17 @@ class SwissSolver(round: Int,
return historyHelper.numberWins
}
override fun getSpecificCriterionValue(p: Pairable, criterion: PlacementCriterion): Int {
override fun getSpecificCriterionValue(p: Pairable, criterion: PlacementCriterion): Double {
// TODO solve this double/int conflict
return when (criterion) {
PlacementCriterion.NBW -> p.nbW.toInt()
PlacementCriterion.SOSW -> p.sos.toInt()
PlacementCriterion.SOSWM1 -> p.sosm1.toInt()
PlacementCriterion.SOSWM2 -> p.sosm2.toInt()
PlacementCriterion.SODOSW -> p.sodos.toInt()
PlacementCriterion.SOSOSW -> p.sosos.toInt()
PlacementCriterion.CUSSW -> p.cums.toInt()
else -> -1
PlacementCriterion.NBW -> p.nbW
PlacementCriterion.SOSW -> p.sos
PlacementCriterion.SOSWM1 -> p.sosm1
PlacementCriterion.SOSWM2 -> p.sosm2
PlacementCriterion.SODOSW -> p.sodos
PlacementCriterion.SOSOSW -> p.sosos
PlacementCriterion.CUSSW -> p.cums
else -> -1.0
}
}
}