Polish table and clarify showdown results
This commit is contained in:
@@ -1,7 +1,22 @@
|
||||
package com.jsjdesigns.poker
|
||||
|
||||
import com.jsjdesigns.poker.core.HandEvaluator
|
||||
import com.jsjdesigns.poker.game.HandResult
|
||||
|
||||
data class AwardWinner(
|
||||
val seat: Int,
|
||||
val label: String,
|
||||
val amountWon: Int,
|
||||
val hole: List<Int>,
|
||||
val handDescription: String?,
|
||||
)
|
||||
|
||||
data class PotAwardSummary(
|
||||
val label: String,
|
||||
val amount: Int,
|
||||
val winners: List<AwardWinner>,
|
||||
)
|
||||
|
||||
/**
|
||||
* Immutable, presentation-ready outcome for one completed hand.
|
||||
*
|
||||
@@ -18,6 +33,8 @@ data class HandSummary(
|
||||
val potSize: Int,
|
||||
val heroNet: Int,
|
||||
val wentToShowdown: Boolean,
|
||||
/** Main/side-pot breakdown with public winning cards and evaluated hand names. */
|
||||
val awards: List<PotAwardSummary>,
|
||||
) {
|
||||
val title: String
|
||||
get() = when {
|
||||
@@ -47,6 +64,40 @@ fun handSummaryFor(
|
||||
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" }
|
||||
require(result.potAwards.isNotEmpty()) { "a completed hand must award at least one pot" }
|
||||
require(result.potAwards.sumOf { it.amount } == result.potSize) {
|
||||
"pot awards must account for the contested pot"
|
||||
}
|
||||
val showdownBySeat = result.showdownHands.associateBy { it.seat }
|
||||
if (result.wentToShowdown) {
|
||||
require(result.potAwards.flatMap { it.payouts }.all { it.seat in showdownBySeat }) {
|
||||
"every showdown winner must include its public hand"
|
||||
}
|
||||
}
|
||||
val multiplePots = result.potAwards.size > 1
|
||||
val awards = result.potAwards.mapIndexed { index, award ->
|
||||
require(award.payouts.all { it.seat in seatNames.indices }) {
|
||||
"pot winner seat is outside the roster"
|
||||
}
|
||||
PotAwardSummary(
|
||||
label = when {
|
||||
!multiplePots -> "Pot"
|
||||
index == 0 -> "Main pot"
|
||||
else -> "Side pot $index"
|
||||
},
|
||||
amount = award.amount,
|
||||
winners = award.payouts.map { payout ->
|
||||
val showdown = showdownBySeat[payout.seat]
|
||||
AwardWinner(
|
||||
seat = payout.seat,
|
||||
label = if (payout.seat == heroSeat) "You" else seatNames[payout.seat],
|
||||
amountWon = payout.amount,
|
||||
hole = showdown?.hole.orEmpty(),
|
||||
handDescription = showdown?.let { HandEvaluator.describe(it.score) },
|
||||
)
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
return HandSummary(
|
||||
handNumber = handNumber,
|
||||
@@ -57,5 +108,6 @@ fun handSummaryFor(
|
||||
potSize = result.potSize,
|
||||
heroNet = result.net[heroSeat],
|
||||
wentToShowdown = result.wentToShowdown,
|
||||
awards = awards,
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user