Refactor past bye players list handling
This commit is contained in:
@@ -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())
|
||||
}
|
||||
|
@@ -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
|
||||
|
@@ -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)
|
||||
|
Reference in New Issue
Block a user