Take handicap into account in SOS, SOSOS, SODOS

This commit is contained in:
Claude Brisson
2024-05-10 09:17:27 +02:00
parent b5cd04050d
commit 2b0030bd4e

View File

@@ -100,9 +100,9 @@ open class HistoryHelper(protected val history: List<List<Game>>, scoresGetter:
// SOS related functions given a score function // SOS related functions given a score function
val sos by lazy { val sos by lazy {
(history.flatten().map { game -> (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 -> } + 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 -> }).groupingBy { it.first }.fold(0.0) { acc, next ->
acc + next.second acc + next.second
}.mapValues { (id, score) -> }.mapValues { (id, score) ->
@@ -117,9 +117,9 @@ open class HistoryHelper(protected val history: List<List<Game>>, scoresGetter:
// sos-1 // sos-1
val sosm1 by lazy { val sosm1 by lazy {
(history.flatten().map { game -> (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 -> } + 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 { }).groupBy {
it.first it.first
}.mapValues { (id, pairs) -> }.mapValues { (id, pairs) ->
@@ -135,9 +135,9 @@ open class HistoryHelper(protected val history: List<List<Game>>, scoresGetter:
// sos-2 // sos-2
val sosm2 by lazy { val sosm2 by lazy {
(history.flatten().map { game -> (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 -> } + 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 { }).groupBy {
it.first it.first
}.mapValues { (id, pairs) -> }.mapValues { (id, pairs) ->
@@ -155,11 +155,11 @@ open class HistoryHelper(protected val history: List<List<Game>>, scoresGetter:
(history.flatten().filter { game -> (history.flatten().filter { game ->
game.white != 0 // Remove games against byePlayer game.white != 0 // Remove games against byePlayer
}.map { game -> }.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 -> } + history.flatten().filter { game ->
game.white != 0 // Remove games against byePlayer game.white != 0 // Remove games against byePlayer
}.map { game -> }.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 -> }).groupingBy { it.first }.fold(0.0) { acc, next ->
acc + next.second acc + next.second
} }