From bb259494e325891b807c93bfe2b3c0f97fde5ee1 Mon Sep 17 00:00:00 2001 From: Quentin Rendu Date: Fri, 24 May 2024 22:32:36 +0200 Subject: [PATCH] Update secondary weight to match Opengotha v3.52 --- .../pairgoth/pairing/solver/BaseSolver.kt | 23 +++++++-------- .../pairgoth/pairing/solver/MacMahonSolver.kt | 28 +++++++++++-------- 2 files changed, 26 insertions(+), 25 deletions(-) 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 adcdc0d..a46e12a 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 @@ -410,23 +410,20 @@ sealed class BaseSolver( open fun SecondaryCritParams.apply(p1: Pairable, p2: Pairable): Double { - // Do we apply Secondary Criteria - // secCase = 0 : No player is above thresholds -> apply secondary criteria - // secCase = 1 : At least one player is above thresholds -> do not apply + // playersMeetCriteria = 0 : No player is above thresholds -> apply secondary criteria + // playersMeetCriteria = 1 : 1 player is above thresholds -> apply half the weight + // playersMeetCriteria = 2 : Both players is above thresholds -> apply the full weight - var score = 0.0 - var secCase = 0 + var playersMeetCriteria = 0 - val nbw2Threshold: Int - if (nbWinsThresholdActive) nbw2Threshold = totalRounds - else nbw2Threshold = 2 * totalRounds + val nbw2Threshold = + if (nbWinsThresholdActive) totalRounds + else 2 * totalRounds - if( (2*p1.nbW >= nbw2Threshold) || - (2*p2.nbW >= nbw2Threshold) ) secCase = 1 + if (2*p1.nbW >= nbw2Threshold) playersMeetCriteria++ + if (2*p2.nbW >= nbw2Threshold) playersMeetCriteria++ - if (secCase == 0) score = pairing.geo.apply(p1, p2) - - return score + return 0.5*playersMeetCriteria*pairing.geo.apply(p1, p2) } fun GeographicalParams.apply(p1: Pairable, p2: Pairable): Double { 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 761b9c7..eab364e 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 @@ -35,24 +35,28 @@ class MacMahonSolver(round: Int, override fun SecondaryCritParams.apply(p1: Pairable, p2: Pairable): Double { - // Do we apply Secondary Criteria? - // - no player is above thresholds -> apply secondary criteria - // - at least one player is above thresholds -> do not apply + // playersMeetCriteria = 0 : No player is above thresholds -> apply the full weight + // playersMeetCriteria = 1 : 1 player is above thresholds -> apply half the weight + // playersMeetCriteria = 2 : Both players are above thresholds -> do not apply weight + + var playersMeetCriteria = 0 val nbw2Threshold = if (nbWinsThresholdActive) totalRounds else 2 * totalRounds - val skipSecondary = - (2 * p1.nbW >= nbw2Threshold) || - (2 * p2.nbW >= nbw2Threshold) || - barThresholdActive && ( - (p1.rank + p1.nbW >= mmBar) || - (p2.rank + p2.nbW >= mmBar) - ) + // Test whether each pairable meets one of the criteria + // subtract Pairable.MIN_RANK to thresholds to convert ranks to MMS score + if (2 * p1.nbW >= nbw2Threshold + || barThresholdActive && (p1.mms >= mmBar - Pairable.MIN_RANK) + || p1.mms >= rankSecThreshold - Pairable.MIN_RANK) playersMeetCriteria++ - return if (skipSecondary) 0.0 - else pairing.geo.apply(p1, p2) + if (2 * p2.nbW >= nbw2Threshold + || barThresholdActive && (p2.mms >= mmBar - Pairable.MIN_RANK) + || p2.mms >= rankSecThreshold - Pairable.MIN_RANK) playersMeetCriteria++ + + return if (playersMeetCriteria==2) 0.0 + else 0.5*(2-playersMeetCriteria)*pairing.geo.apply(p1, p2) } override fun HandicapParams.pseudoRank(pairable: Pairable): Int {