diff --git a/api-webapp/src/main/kotlin/org/jeudego/pairgoth/model/Pairable.kt b/api-webapp/src/main/kotlin/org/jeudego/pairgoth/model/Pairable.kt index 8eac241..bee62a4 100644 --- a/api-webapp/src/main/kotlin/org/jeudego/pairgoth/model/Pairable.kt +++ b/api-webapp/src/main/kotlin/org/jeudego/pairgoth/model/Pairable.kt @@ -9,6 +9,7 @@ import org.jeudego.pairgoth.store.Store sealed class Pairable(val id: ID, val name: String, open val rating: Int, open val rank: Int) { companion object { val MIN_RANK: Int = -30 // 30k + val MAX_RANK: Int = 20 } abstract fun toJson(): Json.Object abstract val club: String? 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 3fb12cb..5b07929 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 @@ -40,7 +40,7 @@ sealed class BaseSolver( open fun weight(p1: Pairable, p2: Pairable) = openGothaWeight(p1, p2) + - pairing.base.applyByeWeight(p1, p2) + + //pairing.base.applyByeWeight(p1, p2) + pairing.handicap.color(p1, p2) fun pair(): List { @@ -149,7 +149,9 @@ sealed class BaseSolver( return if (p1.id == ByePlayer.id || p2.id == ByePlayer.id) { val actualPlayer = if (p1.id == ByePlayer.id) p2 else p1 // TODO maybe use a different formula than opengotha - BaseCritParams.MAX_BYE_WEIGHT - (1000 * actualPlayer.nbBye + actualPlayer.rank + 2*actualPlayer.main) + val x = (actualPlayer.rank - Pairable.MIN_RANK + actualPlayer.main) / (Pairable.MAX_RANK - Pairable.MIN_RANK + mainLimits.second) + concavityFunction(x, BaseCritParams.MAX_BYE_WEIGHT) + BaseCritParams.MAX_BYE_WEIGHT - (actualPlayer.rank + 2*actualPlayer.main) } else { 0.0 } @@ -188,8 +190,7 @@ sealed class BaseSolver( // TODO check category equality if category are used in SwissCat if (scoreRange!=0){ val x = abs(p1.group - p2.group).toDouble() / scoreRange.toDouble() - val k: Double = pairing.base.nx1 - score = scoreWeight * (1.0 - x) * (1.0 + k * x) + score = concavityFunction(x, scoreWeight) } return score @@ -441,6 +442,11 @@ sealed class BaseSolver( return score } + fun concavityFunction(x: Double, scale: Double) : Double { + val k = pairing.base.nx1 + return scale * (1.0 - x) * (1.0 + k * x) + } + open fun games(black: Pairable, white: Pairable): List { // CB TODO team of individuals pairing return listOf(Game(id = Store.nextGameId, black = black.id, white = white.id, handicap = pairing.handicap.handicap(black, white)))