Pause between hands and show results

This commit is contained in:
Jay
2026-07-26 11:11:48 -04:00
parent db1f96b421
commit 9eb77a27a2
6 changed files with 359 additions and 13 deletions
@@ -0,0 +1,55 @@
package com.jsjdesigns.poker
import com.jsjdesigns.poker.game.HandResult
/**
* Immutable, presentation-ready outcome for one completed hand.
*
* This is built from [HandResult], not inferred from the final table snapshot:
* side pots can produce several winners and a player's net can differ from the
* amount of any pot they won.
*/
data class HandSummary(
val handNumber: Int,
val winnerNames: List<String>,
val potSize: Int,
val heroNet: Int,
val wentToShowdown: Boolean,
) {
val title: String
get() = when {
winnerNames.size == 1 && winnerNames.single() == "You" -> "You win"
winnerNames.size == 1 -> "${winnerNames.single()} wins"
else -> "${winnerNames.joinToString(" & ")} win"
}
val detail: String
get() {
val ending = when {
heroNet > 0 -> "You won $heroNet"
heroNet < 0 -> "You lost ${-heroNet}"
else -> "You broke even"
}
val finish = if (wentToShowdown) "Showdown" else "Uncontested"
return "$finish • Pot $potSize$ending"
}
}
fun handSummaryFor(
handNumber: Int,
result: HandResult,
seatNames: List<String>,
heroSeat: Int = HERO_SEAT,
): HandSummary {
require(heroSeat in result.net.indices) { "hero seat is outside the result" }
require(result.winners.isNotEmpty()) { "a completed hand must have a winner" }
require(result.winners.all { it in seatNames.indices }) { "winner seat is outside the roster" }
return HandSummary(
handNumber = handNumber,
winnerNames = result.winners.map(seatNames::get),
potSize = result.potSize,
heroNet = result.net[heroSeat],
wentToShowdown = result.wentToShowdown,
)
}