Refactor past bye players list handling

This commit is contained in:
Claude Brisson
2024-03-24 14:53:07 +01:00
parent 3f0b8da68a
commit 8cd0b7d15e
3 changed files with 23 additions and 7 deletions

View File

@@ -12,7 +12,10 @@ abstract class BasePairingHelper(
) {
abstract val scores: Map<ID, Pair<Double, Double>>
val historyHelper = if (pairables.first().let { it is TeamTournament.Team && it.teamOfIndividuals }) TeamOfIndividualsHistoryHelper(history) { scores }
val historyHelper =
if (pairables.first().let { it is TeamTournament.Team && it.teamOfIndividuals }) TeamOfIndividualsHistoryHelper(
history
) { scores }
else HistoryHelper(history) { scores }
// Extend pairables with members from all rounds
@@ -26,10 +29,12 @@ abstract class BasePairingHelper(
protected val sortedPairables by lazy {
pairables.sortedWith(::sort)
}
// pairables sorted for pairing purposes
protected val pairingSortedPairables by lazy {
pairables.sortedWith(::pairingSort).toMutableList()
}
// pairables sorted for pairing purposes
protected val nameSortedPairables by lazy {
pairables.sortedWith(::nameSort).toMutableList()
@@ -79,7 +84,7 @@ abstract class BasePairingHelper(
protected val Pairable.group: Int get() = _groups[id]!!
protected val Pairable.drawnUpDown: Pair<Int,Int> get() = historyHelper.drawnUpDown(this) ?: Pair(0,0)
protected val Pairable.drawnUpDown: Pair<Int, Int> get() = historyHelper.drawnUpDown(this) ?: Pair(0, 0)
protected val Pairable.nbBye: Int get() = historyHelper.nbPlayedWithBye(this) ?: 0
@@ -93,8 +98,11 @@ abstract class BasePairingHelper(
val Pairable.sodos: Double get() = historyHelper.sodos[id] ?: 0.0
val Pairable.cums: Double get() = historyHelper.cumScore[id] ?: 0.0
fun Pairable.missedRounds(upToRound: Int, pairing: Set<ID>): Int = (1..upToRound).map { round ->
if (historyHelper.playersPerRound.getOrNull(round - 1)?.contains(id) == true || round == upToRound && pairing.contains(id)) 0 else 1
if (historyHelper.playersPerRound.getOrNull(round - 1)
?.contains(id) == true || round == upToRound && pairing.contains(id)
) 0 else 1
}.sum()
fun Pairable.eval(criterion: Criterion) = evalCriterion(this, criterion)
open fun evalCriterion(pairable: Pairable, criterion: Criterion) = when (criterion) {
Criterion.NONE -> 0.0
@@ -121,6 +129,7 @@ abstract class BasePairingHelper(
}
return 0
}
open fun pairingSort(p: Pairable, q: Pairable): Int {
for (criterion in placement.criteria) {
val criterionP = p.eval(criterion)
@@ -141,6 +150,7 @@ abstract class BasePairingHelper(
}
return p.fullName().compareTo(q.fullName())
}
open fun nameSort(p: Pairable, q: Pairable): Int {
return p.fullName().compareTo(q.fullName())
}

View File

@@ -218,6 +218,14 @@ open class HistoryHelper(protected val history: List<List<Game>>, scoresGetter:
}
}
val byePlayers by lazy {
history.flatten().mapNotNull { game ->
if (game.white == ByePlayer.id) game.black
else if (game.black == ByePlayer.id) game.white
else null
}
}
}
// CB TODO - a big problem with the current naive implementation is that the team score is -for now- the sum of team members individual scores

View File

@@ -33,7 +33,6 @@ sealed class BaseSolver(
companion object {
val rand = Random(/* seed from properties - TODO */)
var byePlayers: MutableList<Pairable> = mutableListOf()
var weightsLogger: PrintWriter? = null
}
@@ -79,7 +78,7 @@ sealed class BaseSolver(
var byePlayerIndex = 0
for (p in nameSortedPairables){
weightForBye = p.rank + 2*(p.main + p.rank)
if (p in byePlayers) weightForBye += 1000
if (p.id in historyHelper.byePlayers) weightForBye += 1000
if (weightForBye <= minWeight){
minWeight = weightForBye
chosenByePlayer = p
@@ -87,7 +86,6 @@ sealed class BaseSolver(
// println("choose Bye: " + p.nameSeed() + " mms2 " +2*p.main+" "+ weightForBye)
}
println("Bye player : " + chosenByePlayer.fullName())
byePlayers.add(chosenByePlayer)
nameSortedPairables.remove(chosenByePlayer)
// Keep chosenByePlayer in pairingSortedPairables to be identical to opengotha
pairingSortedPairables.remove(ByePlayer)