Drawn up down info in game, and related history getter
This commit is contained in:
@@ -9,7 +9,8 @@ data class Game(
|
|||||||
var white: ID,
|
var white: ID,
|
||||||
var black: ID,
|
var black: ID,
|
||||||
var handicap: Int = 0,
|
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 {}
|
companion object {}
|
||||||
enum class Result(val symbol: Char) {
|
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")
|
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
|
// serialization
|
||||||
|
@@ -22,6 +22,8 @@ open class HistoryHelper(protected val history: List<List<Game>>, scoresGetter:
|
|||||||
open fun colorBalance(p: Pairable) = colorBalance[p.id]
|
open fun colorBalance(p: Pairable) = colorBalance[p.id]
|
||||||
open fun nbW(p: Pairable) = wins[p.id]
|
open fun nbW(p: Pairable) = wins[p.id]
|
||||||
|
|
||||||
|
fun drawnUpDown(p: Pairable) = drawnUpDown[p.id]
|
||||||
|
|
||||||
protected val paired: Set<Pair<ID, ID>> by lazy {
|
protected val paired: Set<Pair<ID, ID>> by lazy {
|
||||||
(history.flatten().map { game ->
|
(history.flatten().map { game ->
|
||||||
Pair(game.black, game.white)
|
Pair(game.black, game.white)
|
||||||
@@ -135,6 +137,24 @@ open class HistoryHelper(protected val history: List<List<Game>>, scoresGetter:
|
|||||||
.toMap()
|
.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
|
// 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
|
||||||
|
Reference in New Issue
Block a user