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 047fc9d..267acb5 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 @@ -172,7 +172,7 @@ class Swiss( ): Pairing(SWISS, pairingParams, placementParams) { companion object {} override fun pair(tournament: Tournament<*>, round: Int, pairables: List): List { - return SwissSolver(round, tournament.historyBefore(round), pairables, pairingParams, placementParams, tournament.usedTables(round)).pair() + return SwissSolver(round, tournament.rounds, tournament.historyBefore(round), pairables, pairingParams, placementParams, tournament.usedTables(round)).pair() } } @@ -201,7 +201,7 @@ class MacMahon( ): Pairing(MAC_MAHON, pairingParams, placementParams) { companion object {} override fun pair(tournament: Tournament<*>, round: Int, pairables: List): List { - return MacMahonSolver(round, tournament.historyBefore(round), pairables, pairingParams, placementParams, tournament.usedTables(round), mmFloor, mmBar).pair() + return MacMahonSolver(round, tournament.rounds, tournament.historyBefore(round), pairables, pairingParams, placementParams, tournament.usedTables(round), mmFloor, mmBar).pair() } } diff --git a/api-webapp/src/main/kotlin/org/jeudego/pairgoth/model/Tournament.kt b/api-webapp/src/main/kotlin/org/jeudego/pairgoth/model/Tournament.kt index e24df49..35a9ee3 100644 --- a/api-webapp/src/main/kotlin/org/jeudego/pairgoth/model/Tournament.kt +++ b/api-webapp/src/main/kotlin/org/jeudego/pairgoth/model/Tournament.kt @@ -79,9 +79,9 @@ sealed class Tournament ( // TODO cleaner solver instantiation val history = historyBefore(round) val solver = if (pairing is Swiss) { - SwissSolver(round, history, pairables.values.toList(), pairing.pairingParams, pairing.placementParams, usedTables(round)) + SwissSolver(round, rounds, history, pairables.values.toList(), pairing.pairingParams, pairing.placementParams, usedTables(round)) } else if (pairing is MacMahon) { - MacMahonSolver(round, history, pairables.values.toList(), pairing.pairingParams, pairing.placementParams, usedTables(round), pairing.mmFloor, pairing.mmBar) + MacMahonSolver(round, rounds, history, pairables.values.toList(), pairing.pairingParams, pairing.placementParams, usedTables(round), pairing.mmFloor, pairing.mmBar) } else throw Exception("Invalid tournament type") // Recomputes DUDD and hd diff --git a/api-webapp/src/main/kotlin/org/jeudego/pairgoth/pairing/BasePairingHelper.kt b/api-webapp/src/main/kotlin/org/jeudego/pairgoth/pairing/BasePairingHelper.kt index 14ae0d0..ec61529 100644 --- a/api-webapp/src/main/kotlin/org/jeudego/pairgoth/pairing/BasePairingHelper.kt +++ b/api-webapp/src/main/kotlin/org/jeudego/pairgoth/pairing/BasePairingHelper.kt @@ -5,6 +5,7 @@ import java.util.* abstract class BasePairingHelper( val round: Int, + val totalRounds: Int, history: List>, // History of all games played for each round var pairables: List, // All pairables for this round, it may include the bye player val pairing: PairingParams, 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 bbc811e..f8b3e46 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 @@ -18,12 +18,13 @@ import kotlin.math.* sealed class BaseSolver( round: Int, + totalRounds: Int, history: List>, // History of all games played for each round pairables: List, // All pairables for this round, it may include the bye player pairing: PairingParams, placement: PlacementParams, val usedTables: BitSet - ) : BasePairingHelper(round, history, pairables, pairing, placement) { + ) : BasePairingHelper(round, totalRounds, history, pairables, pairing, placement) { companion object { val rand = Random(/* seed from properties - TODO */) @@ -192,6 +193,7 @@ sealed class BaseSolver( val hd1 = pairing.handicap.handicap(white = p1, black = p2) val hd2 = pairing.handicap.handicap(white = p2, black = p1) val potentialHd: Int = max(hd1, hd2) + val score = if (potentialHd == 0) { val wb1: Int = p1.colorBalance val wb2: Int = p2.colorBalance @@ -416,11 +418,11 @@ sealed class BaseSolver( var secCase = 0 val nbw2Threshold: Int - if (nbWinsThresholdActive) nbw2Threshold = round - else nbw2Threshold = 2 * round + if (nbWinsThresholdActive) nbw2Threshold = totalRounds + else nbw2Threshold = 2 * totalRounds - if( (2*p1.main >= nbw2Threshold) || - (2*p2.main >= nbw2Threshold) ) secCase = 1 + if( (2*p1.nbW >= nbw2Threshold) || + (2*p2.nbW >= nbw2Threshold) ) secCase = 1 if (secCase == 0) score = pairing.geo.apply(p1, p2) 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 cfd6940..dca12a1 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 @@ -7,13 +7,14 @@ import kotlin.math.min import kotlin.math.roundToInt class MacMahonSolver(round: Int, + totalRounds: Int, history: List>, pairables: List, pairingParams: PairingParams, placementParams: PlacementParams, usedTables: BitSet, private val mmFloor: Int, private val mmBar: Int) : - BaseSolver(round, history, pairables, pairingParams, placementParams, usedTables) { + BaseSolver(round, totalRounds, history, pairables, pairingParams, placementParams, usedTables) { override val scores: Map> by lazy { require (mmBar > mmFloor) { "MMFloor is higher than MMBar" } @@ -42,13 +43,14 @@ class MacMahonSolver(round: Int, var secCase = 0 val nbw2Threshold: Int - if (nbWinsThresholdActive) nbw2Threshold = round - else nbw2Threshold = 2 * round + if (nbWinsThresholdActive) nbw2Threshold = totalRounds + else nbw2Threshold = 2 * totalRounds - if( (2*p1.main >= nbw2Threshold) || - (2*p2.main >= nbw2Threshold) || - (p1.main >= mmBar) || - (p2.main >= mmBar) ) secCase = 1 + if( (2*p1.nbW >= nbw2Threshold) || + (2*p2.nbW >= nbw2Threshold) || + (p1.rank+p1.nbW >= mmBar) || + (p2.rank+p2.nbW >= mmBar) ) secCase = 1 + if (secCase == 0) score = pairing.geo.apply(p1, p2) diff --git a/api-webapp/src/main/kotlin/org/jeudego/pairgoth/pairing/solver/SwissSolver.kt b/api-webapp/src/main/kotlin/org/jeudego/pairgoth/pairing/solver/SwissSolver.kt index e7b63a6..3a8ef58 100644 --- a/api-webapp/src/main/kotlin/org/jeudego/pairgoth/pairing/solver/SwissSolver.kt +++ b/api-webapp/src/main/kotlin/org/jeudego/pairgoth/pairing/solver/SwissSolver.kt @@ -4,13 +4,14 @@ import org.jeudego.pairgoth.model.* import java.util.* class SwissSolver(round: Int, + totalRounds: Int, history: List>, pairables: List, pairingParams: PairingParams, placementParams: PlacementParams, usedTables: BitSet ): - BaseSolver(round, history, pairables, pairingParams, placementParams, usedTables) { + BaseSolver(round, totalRounds, history, pairables, pairingParams, placementParams, usedTables) { // In a Swiss tournament the main criterion is the number of wins and already computed