Identify hero results by seat
This commit is contained in:
@@ -11,16 +11,19 @@ import com.jsjdesigns.poker.game.HandResult
|
||||
*/
|
||||
data class HandSummary(
|
||||
val handNumber: Int,
|
||||
val winnerNames: List<String>,
|
||||
/** Display labels in the engine's winner order; the human seat is always "You". */
|
||||
val winnerLabels: List<String>,
|
||||
/** Derived from winner seat indices, never from a player-controlled name. */
|
||||
val heroWon: Boolean,
|
||||
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"
|
||||
winnerLabels.size == 1 && heroWon -> "You win"
|
||||
winnerLabels.size == 1 -> "${winnerLabels.single()} wins"
|
||||
else -> "${winnerLabels.joinToString(" & ")} win"
|
||||
}
|
||||
|
||||
val detail: String
|
||||
@@ -47,7 +50,10 @@ fun handSummaryFor(
|
||||
|
||||
return HandSummary(
|
||||
handNumber = handNumber,
|
||||
winnerNames = result.winners.map(seatNames::get),
|
||||
winnerLabels = result.winners.map { winner ->
|
||||
if (winner == heroSeat) "You" else seatNames[winner]
|
||||
},
|
||||
heroWon = heroSeat in result.winners,
|
||||
potSize = result.potSize,
|
||||
heroNet = result.net[heroSeat],
|
||||
wentToShowdown = result.wentToShowdown,
|
||||
|
||||
@@ -43,7 +43,7 @@ class HandSummaryTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `hero win and uncontested pot are explicit`() {
|
||||
fun `hero is identified by seat when the player uses a custom name`() {
|
||||
val summary = handSummaryFor(
|
||||
handNumber = 3,
|
||||
result = result(
|
||||
@@ -52,15 +52,16 @@ class HandSummaryTest {
|
||||
showdown = false,
|
||||
pot = 6,
|
||||
),
|
||||
seatNames = listOf("You", "Ada", "Bruno"),
|
||||
seatNames = listOf("Jay", "Ada", "Bruno"),
|
||||
)
|
||||
|
||||
assertEquals("You win", summary.title)
|
||||
assertTrue(summary.heroWon)
|
||||
assertEquals("Uncontested • Pot 6 • You won 5", summary.detail)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `several side-pot winners are not described as one split pot`() {
|
||||
fun `custom-named hero is labelled as you among several winners`() {
|
||||
val summary = handSummaryFor(
|
||||
handNumber = 9,
|
||||
result = result(
|
||||
@@ -68,17 +69,25 @@ class HandSummaryTest {
|
||||
winners = listOf(0, 1),
|
||||
pot = 40,
|
||||
),
|
||||
seatNames = listOf("You", "Ada", "Bruno"),
|
||||
seatNames = listOf("Jay", "Ada", "Bruno"),
|
||||
)
|
||||
|
||||
assertEquals("You & Ada win", summary.title)
|
||||
assertTrue(summary.heroWon)
|
||||
assertTrue(summary.detail.endsWith("You broke even"))
|
||||
}
|
||||
}
|
||||
|
||||
class VisibleHandSummaryTest {
|
||||
|
||||
private val summary = HandSummary(4, listOf("Ada"), 20, -4, true)
|
||||
private val summary = HandSummary(
|
||||
handNumber = 4,
|
||||
winnerLabels = listOf("Ada"),
|
||||
heroWon = false,
|
||||
potSize = 20,
|
||||
heroNet = -4,
|
||||
wentToShowdown = true,
|
||||
)
|
||||
|
||||
private fun snapshot(
|
||||
handNumber: Int = 4,
|
||||
|
||||
Reference in New Issue
Block a user