From be40411237eea869ace658519cb08ff9c5eace35 Mon Sep 17 00:00:00 2001 From: Claude Brisson Date: Thu, 8 Feb 2024 12:23:49 +0100 Subject: [PATCH] Implement rounding option --- .../main/kotlin/org/jeudego/pairgoth/ext/OpenGotha.kt | 7 +++++-- .../main/kotlin/org/jeudego/pairgoth/model/Pairing.kt | 7 +++++-- .../org/jeudego/pairgoth/pairing/solver/BaseSolver.kt | 10 ++++++++++ .../jeudego/pairgoth/pairing/solver/MacMahonSolver.kt | 2 +- 4 files changed, 21 insertions(+), 5 deletions(-) diff --git a/api-webapp/src/main/kotlin/org/jeudego/pairgoth/ext/OpenGotha.kt b/api-webapp/src/main/kotlin/org/jeudego/pairgoth/ext/OpenGotha.kt index 4719356..1c759b4 100644 --- a/api-webapp/src/main/kotlin/org/jeudego/pairgoth/ext/OpenGotha.kt +++ b/api-webapp/src/main/kotlin/org/jeudego/pairgoth/ext/OpenGotha.kt @@ -85,7 +85,8 @@ object OpenGotha { seedSystem2 = parseSeedSystem(pairParams.paiMaSeedSystem2 ?: "SPLITANDSLIP"), additionalPlacementCritSystem1 = Criterion.valueOf(pairParams.paiMaAdditionalPlacementCritSystem1.uppercase()), additionalPlacementCritSystem2 = Criterion.valueOf(pairParams.paiMaAdditionalPlacementCritSystem2.uppercase().replace("NULL", "NONE")), - mmsValueAbsent = genParams.genMMS2ValueAbsent.toDouble() / 2.0 + mmsValueAbsent = genParams.genMMS2ValueAbsent.toDouble() / 2.0, + roundDownScore = genParams.genRoundDownNBWMMS.toBoolean() ), secondary = SecondaryCritParams( barThresholdActive = pairParams.paiSeBarThresholdActive.toBoolean(), @@ -304,7 +305,9 @@ object OpenGotha { ).uppercase(Locale.ROOT) }" genMMS2ValueAbsent="${ (tournament.pairing.pairingParams.main.mmsValueAbsent * 2).roundToInt() - }" genMMS2ValueBye="2" genMMZero="30K" genNBW2ValueAbsent="0" genNBW2ValueBye="2" genRoundDownNBWMMS="true" komi="${tournament.komi}" location="${tournament.location}" name="${tournament.name}" nbMovesCanTime="${tournament.timeSystem.stones}" numberOfCategories="1" numberOfRounds="${tournament.rounds}" shortName="${tournament.shortName}" size="${tournament.gobanSize}" stdByoYomiTime="${tournament.timeSystem.byoyomi}"/> + }" genMMS2ValueBye="2" genMMZero="30K" genNBW2ValueAbsent="0" genNBW2ValueBye="2" genRoundDownNBWMMS="${ + tournament.pairing.pairingParams.main.roundDownScore + }" komi="${tournament.komi}" location="${tournament.location}" name="${tournament.name}" nbMovesCanTime="${tournament.timeSystem.stones}" numberOfCategories="1" numberOfRounds="${tournament.rounds}" shortName="${tournament.shortName}" size="${tournament.gobanSize}" stdByoYomiTime="${tournament.timeSystem.byoyomi}"/> diff --git a/api-webapp/src/main/kotlin/org/jeudego/pairgoth/model/Pairing.kt b/api-webapp/src/main/kotlin/org/jeudego/pairgoth/model/Pairing.kt index b28e94a..e30b440 100644 --- a/api-webapp/src/main/kotlin/org/jeudego/pairgoth/model/Pairing.kt +++ b/api-webapp/src/main/kotlin/org/jeudego/pairgoth/model/Pairing.kt @@ -51,6 +51,7 @@ data class MainCritParams( val additionalPlacementCritSystem1: Criterion = Criterion.RATING, val additionalPlacementCritSystem2: Criterion = Criterion.NONE, val mmsValueAbsent: Double = 0.5, + val roundDownScore: Boolean = true ) { enum class DrawUpDown { TOP, MIDDLE, BOTTOM } enum class SeedMethod { SPLIT_AND_FOLD, SPLIT_AND_RANDOM, SPLIT_AND_SLIP } @@ -243,7 +244,8 @@ fun MainCritParams.Companion.fromJson(json: Json.Object, localDefault: MainCritP seedSystem2 = json.getString("secondSeed")?.let { MainCritParams.SeedMethod.valueOf(it) } ?: localDefault?.seedSystem2 ?: default.seedSystem2, additionalPlacementCritSystem1 = json.getString("firstSeedAddCrit")?.let { Criterion.valueOf(it) } ?: localDefault?.additionalPlacementCritSystem1 ?: default.additionalPlacementCritSystem1, additionalPlacementCritSystem2 = json.getString("secondSeedAddCrit")?.let { Criterion.valueOf(it) } ?: localDefault?.additionalPlacementCritSystem2 ?: default.additionalPlacementCritSystem2, - mmsValueAbsent = json.getDouble("mmsValueAbsent") ?: localDefault?.mmsValueAbsent ?: default.mmsValueAbsent + mmsValueAbsent = json.getDouble("mmsValueAbsent") ?: localDefault?.mmsValueAbsent ?: default.mmsValueAbsent, + roundDownScore = json.getBoolean("roundDownScore") ?: localDefault?.roundDownScore ?: default.roundDownScore ) fun MainCritParams.toJson() = Json.Object( @@ -259,7 +261,8 @@ fun MainCritParams.toJson() = Json.Object( "secondSeed" to seedSystem2, "firstSeedAddCrit" to additionalPlacementCritSystem1, "secondSeedAddCrit" to additionalPlacementCritSystem2, - "mmsValueAbsent" to mmsValueAbsent + "mmsValueAbsent" to mmsValueAbsent, + "roundDownScore" to roundDownScore ) fun SecondaryCritParams.Companion.fromJson(json: Json.Object, localDefault: SecondaryCritParams? = null) = SecondaryCritParams( diff --git a/api-webapp/src/main/kotlin/org/jeudego/pairgoth/pairing/solver/BaseSolver.kt b/api-webapp/src/main/kotlin/org/jeudego/pairgoth/pairing/solver/BaseSolver.kt index 41a43f9..b005731 100644 --- a/api-webapp/src/main/kotlin/org/jeudego/pairgoth/pairing/solver/BaseSolver.kt +++ b/api-webapp/src/main/kotlin/org/jeudego/pairgoth/pairing/solver/BaseSolver.kt @@ -15,8 +15,11 @@ import java.io.PrintWriter import java.text.DecimalFormat import java.util.* import kotlin.math.abs +import kotlin.math.ceil +import kotlin.math.floor import kotlin.math.max import kotlin.math.min +import kotlin.math.roundToInt sealed class BaseSolver( val round: Int, // Round number @@ -492,6 +495,13 @@ sealed class BaseSolver( return pairable.rank } + fun roundScore(score: Double): Int { + val epsilon = 0.00001 + // Note: this works for now because we only have .0 and .5 fractional parts + return if (pairing.main.roundDownScore) floor(score + epsilon).roundToInt() + else ceil(score - epsilon).roundToInt() + } + open fun HandicapParams.clamp(input: Int): Int { var hd = input if (hd >= correction) hd -= correction diff --git a/api-webapp/src/main/kotlin/org/jeudego/pairgoth/pairing/solver/MacMahonSolver.kt b/api-webapp/src/main/kotlin/org/jeudego/pairgoth/pairing/solver/MacMahonSolver.kt index f0e97be..9f37120 100644 --- a/api-webapp/src/main/kotlin/org/jeudego/pairgoth/pairing/solver/MacMahonSolver.kt +++ b/api-webapp/src/main/kotlin/org/jeudego/pairgoth/pairing/solver/MacMahonSolver.kt @@ -28,7 +28,7 @@ class MacMahonSolver(round: Int, override fun HandicapParams.pseudoRank(pairable: Pairable): Int { if (useMMS) { - return (pairable.mms + Pairable.MIN_RANK).toInt() + return roundScore(pairable.mms + Pairable.MIN_RANK) } else { return pairable.rank }