diff --git a/api-webapp/src/main/kotlin/org/jeudego/pairgoth/model/Game.kt b/api-webapp/src/main/kotlin/org/jeudego/pairgoth/model/Game.kt index 23ca869..3d2f770 100644 --- a/api-webapp/src/main/kotlin/org/jeudego/pairgoth/model/Game.kt +++ b/api-webapp/src/main/kotlin/org/jeudego/pairgoth/model/Game.kt @@ -9,7 +9,8 @@ data class Game( var white: ID, var black: ID, var handicap: Int = 0, - var result: Result = UNKNOWN + var result: Result = UNKNOWN, + var drawnUpDown: Int = 0 // counted for white (black gets the opposite) ) { companion object {} enum class Result(val symbol: Char) { @@ -26,11 +27,6 @@ data class Game( fun fromSymbol(c: Char) = byChar[c] ?: throw Error("unknown result symbol: $c") } } - // pairing needs to know if there has been a draw-up or a draw-down - internal var blackDrawnUp = false - internal var blackDrawnDown = false - internal var whiteDrawnUp = false - internal var whiteDrawnDown = false } // serialization 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 5c7c0b5..f0949d1 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 @@ -22,6 +22,8 @@ open class HistoryHelper(protected val history: List>, scoresGetter: open fun colorBalance(p: Pairable) = colorBalance[p.id] open fun nbW(p: Pairable) = wins[p.id] + fun drawnUpDown(p: Pairable) = drawnUpDown[p.id] + protected val paired: Set> by lazy { (history.flatten().map { game -> Pair(game.black, game.white) @@ -135,6 +137,24 @@ open class HistoryHelper(protected val history: List>, scoresGetter: .toMap() } } + + // drawn up down: map ID -> Pair(sum of drawn up, sum of drawn down) + val drawnUpDown by lazy { + (history.flatten().map { game -> + Pair(game.white, Pair( + Math.max(0, game.drawnUpDown), + Math.max(0, -game.drawnUpDown) + )) + } + history.flatten().map { game -> + Pair(game.black, Pair( + Math.max(0, -game.drawnUpDown), + Math.max(0, game.drawnUpDown) + )) + }).groupingBy { it.first }.fold(Pair(0, 0)) { acc, next -> + Pair(acc.first + next.second.first, acc.second + next.second.second) + } + } + } // 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