From fad1c38b659741ccc9157ff305c69a65ca0ea81e Mon Sep 17 00:00:00 2001 From: kageru Date: Thu, 22 Oct 2020 19:43:08 +0200 Subject: [PATCH] Implement game summary calculation --- src/main/kotlin/rps/Game.kt | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/main/kotlin/rps/Game.kt b/src/main/kotlin/rps/Game.kt index 9fff147..7f4d0a5 100644 --- a/src/main/kotlin/rps/Game.kt +++ b/src/main/kotlin/rps/Game.kt @@ -34,4 +34,9 @@ fun determineOutcome(first: Move, second: Move): Outcome = when { else -> Outcome.LOSS } -fun calculateGameSummary(turns: List): 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) = GameSummary( + wins = turns.count { it == Outcome.WIN }, + draws = turns.count { it == Outcome.DRAW }, + losses = turns.count { it == Outcome.LOSS }, +)