From 8d577f32ab7671bb049950fe2ea3f93655120978 Mon Sep 17 00:00:00 2001 From: Claude Brisson Date: Sun, 10 Mar 2024 20:19:41 +0100 Subject: [PATCH] Fix sosos --- .../jeudego/pairgoth/pairing/HistoryHelper.kt | 30 ++++++++++++++----- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/api-webapp/src/main/kotlin/org/jeudego/pairgoth/pairing/HistoryHelper.kt b/api-webapp/src/main/kotlin/org/jeudego/pairgoth/pairing/HistoryHelper.kt index b861587..a315e1b 100644 --- a/api-webapp/src/main/kotlin/org/jeudego/pairgoth/pairing/HistoryHelper.kt +++ b/api-webapp/src/main/kotlin/org/jeudego/pairgoth/pairing/HistoryHelper.kt @@ -107,10 +107,10 @@ open class HistoryHelper(protected val history: List>, scoresGetter: acc + next.second }.mapValues { (id, score) -> // "If the player does not participate in a round, the opponent's score is replaced by the starting score of the player himself." - score + playersPerRound.map { players -> + score + playersPerRound.sumOf { players -> if (players.contains(id)) 0.0 else scores[id]?.first ?: 0.0 - }.sum() + } } } @@ -122,9 +122,13 @@ open class HistoryHelper(protected val history: List>, scoresGetter: Pair(game.white, scores[game.black]?.second ?: 0.0) }).groupBy { it.first - }.mapValues { - val scores = it.value.map { it.second }.sorted() - scores.sum() - (scores.firstOrNull() ?: 0.0) + }.mapValues { (id, pairs) -> + val oppScores = pairs.map { it.second }.sortedDescending() + oppScores.sum() - (oppScores.firstOrNull() ?: 0.0) + + playersPerRound.sumOf { players -> + if (players.contains(id)) 0.0 + else scores[id]?.first ?: 0.0 + } } } @@ -136,9 +140,13 @@ open class HistoryHelper(protected val history: List>, scoresGetter: Pair(game.white, scores[game.black]?.second ?: 0.0) }).groupBy { it.first - }.mapValues { - val scores = it.value.map { it.second }.sorted() - scores.sum() - scores.getOrElse(0) { 0.0 } - scores.getOrElse(1) { 0.0 } + }.mapValues { (id, pairs) -> + val oppScores = pairs.map { it.second }.sorted() + oppScores.sum() - oppScores.getOrElse(0) { 0.0 } - oppScores.getOrElse(1) { 0.0 } + + playersPerRound.sumOf { players -> + if (players.contains(id)) 0.0 + else scores[id]?.first ?: 0.0 + } } } @@ -159,6 +167,7 @@ open class HistoryHelper(protected val history: List>, scoresGetter: // sosos val sosos by lazy { + val currentRound = history.size (history.flatten().filter { game -> game.white != 0 // Remove games against byePlayer }.map { game -> @@ -169,6 +178,11 @@ open class HistoryHelper(protected val history: List>, scoresGetter: Pair(game.white, sos[game.black] ?: 0.0) }).groupingBy { it.first }.fold(0.0) { acc, next -> acc + next.second + }.mapValues { (id, sosos) -> + sosos + playersPerRound.sumOf { players -> + if (players.contains(id)) 0.0 + else (scores[id]?.first ?: 0.0) * currentRound + } } }