From 2b0030bd4ed0025cc407c5f64ef8957b6a52f1fd Mon Sep 17 00:00:00 2001 From: Claude Brisson Date: Fri, 10 May 2024 09:17:27 +0200 Subject: [PATCH] Take handicap into account in SOS, SOSOS, SODOS --- .../jeudego/pairgoth/pairing/HistoryHelper.kt | 16 ++++++++-------- 1 file changed, 8 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 b95f844..d505aac 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 @@ -100,9 +100,9 @@ open class HistoryHelper(protected val history: List>, scoresGetter: // SOS related functions given a score function val sos by lazy { (history.flatten().map { game -> - Pair(game.black, scores[game.white]?.second ?: 0.0) + Pair(game.black, scores[game.white]?.second?.let { it - game.handicap } ?: 0.0) } + history.flatten().map { game -> - Pair(game.white, scores[game.black]?.second ?: 0.0) + Pair(game.white, scores[game.black]?.second?.let { it + game.handicap } ?: 0.0) }).groupingBy { it.first }.fold(0.0) { acc, next -> acc + next.second }.mapValues { (id, score) -> @@ -117,9 +117,9 @@ open class HistoryHelper(protected val history: List>, scoresGetter: // sos-1 val sosm1 by lazy { (history.flatten().map { game -> - Pair(game.black, scores[game.white]?.second ?: 0.0) + Pair(game.black, scores[game.white]?.second?.let { it - game.handicap } ?: 0.0) } + history.flatten().map { game -> - Pair(game.white, scores[game.black]?.second ?: 0.0) + Pair(game.white, scores[game.black]?.second?.let { it + game.handicap } ?: 0.0) }).groupBy { it.first }.mapValues { (id, pairs) -> @@ -135,9 +135,9 @@ open class HistoryHelper(protected val history: List>, scoresGetter: // sos-2 val sosm2 by lazy { (history.flatten().map { game -> - Pair(game.black, scores[game.white]?.second ?: 0.0) + Pair(game.black, scores[game.white]?.second?.let { it - game.handicap } ?: 0.0) } + history.flatten().map { game -> - Pair(game.white, scores[game.black]?.second ?: 0.0) + Pair(game.white, scores[game.black]?.second?.let { it + game.handicap } ?: 0.0) }).groupBy { it.first }.mapValues { (id, pairs) -> @@ -155,11 +155,11 @@ open class HistoryHelper(protected val history: List>, scoresGetter: (history.flatten().filter { game -> game.white != 0 // Remove games against byePlayer }.map { game -> - Pair(game.black, if (game.result == Game.Result.BLACK) scores[game.white]?.second ?: 0.0 else 0.0) + Pair(game.black, if (game.result == Game.Result.BLACK) scores[game.white]?.second?.let { it - game.handicap } ?: 0.0 else 0.0) } + history.flatten().filter { game -> game.white != 0 // Remove games against byePlayer }.map { game -> - Pair(game.white, if (game.result == Game.Result.WHITE) scores[game.black]?.second ?: 0.0 else 0.0) + Pair(game.white, if (game.result == Game.Result.WHITE) scores[game.black]?.second?.let { it + game.handicap } ?: 0.0 else 0.0) }).groupingBy { it.first }.fold(0.0) { acc, next -> acc + next.second }