Implement rounding option

This commit is contained in:
Claude Brisson
2024-02-08 12:23:49 +01:00
parent 4f66852e6d
commit be40411237
4 changed files with 21 additions and 5 deletions

View File

@@ -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}"/>
<HandicapParameterSet hdBasedOnMMS="${tournament.pairing.pairingParams.handicap.useMMS}" hdCeiling="${tournament.pairing.pairingParams.handicap.ceiling}" hdCorrection="${tournament.pairing.pairingParams.handicap.correction}" hdNoHdRankThreshold="${displayRank(tournament.pairing.pairingParams.handicap.rankThreshold)}"/>
<PlacementParameterSet>
<PlacementCriteria>

View File

@@ -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(

View File

@@ -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

View File

@@ -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
}