Implement game summary calculation

This commit is contained in:
kageru 2020-10-22 19:43:08 +02:00
parent c9e331a24e
commit fad1c38b65
Signed by: kageru
GPG Key ID: 8282A2BEA4ADA3D2

View File

@ -34,4 +34,9 @@ fun determineOutcome(first: Move, second: Move): Outcome = when {
else -> Outcome.LOSS
}
fun calculateGameSummary(turns: List<Outcome>): GameSummary = TODO()
// Note: This would be slightly more efficient (but a lot less elegant) with an imperative loop and three mutable integers.
fun calculateGameSummary(turns: List<Outcome>) = GameSummary(
wins = turns.count { it == Outcome.WIN },
draws = turns.count { it == Outcome.DRAW },
losses = turns.count { it == Outcome.LOSS },
)