Identify hero results by seat
This commit is contained in:
@@ -11,16 +11,19 @@ import com.jsjdesigns.poker.game.HandResult
|
|||||||
*/
|
*/
|
||||||
data class HandSummary(
|
data class HandSummary(
|
||||||
val handNumber: Int,
|
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 potSize: Int,
|
||||||
val heroNet: Int,
|
val heroNet: Int,
|
||||||
val wentToShowdown: Boolean,
|
val wentToShowdown: Boolean,
|
||||||
) {
|
) {
|
||||||
val title: String
|
val title: String
|
||||||
get() = when {
|
get() = when {
|
||||||
winnerNames.size == 1 && winnerNames.single() == "You" -> "You win"
|
winnerLabels.size == 1 && heroWon -> "You win"
|
||||||
winnerNames.size == 1 -> "${winnerNames.single()} wins"
|
winnerLabels.size == 1 -> "${winnerLabels.single()} wins"
|
||||||
else -> "${winnerNames.joinToString(" & ")} win"
|
else -> "${winnerLabels.joinToString(" & ")} win"
|
||||||
}
|
}
|
||||||
|
|
||||||
val detail: String
|
val detail: String
|
||||||
@@ -47,7 +50,10 @@ fun handSummaryFor(
|
|||||||
|
|
||||||
return HandSummary(
|
return HandSummary(
|
||||||
handNumber = handNumber,
|
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,
|
potSize = result.potSize,
|
||||||
heroNet = result.net[heroSeat],
|
heroNet = result.net[heroSeat],
|
||||||
wentToShowdown = result.wentToShowdown,
|
wentToShowdown = result.wentToShowdown,
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ class HandSummaryTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@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(
|
val summary = handSummaryFor(
|
||||||
handNumber = 3,
|
handNumber = 3,
|
||||||
result = result(
|
result = result(
|
||||||
@@ -52,15 +52,16 @@ class HandSummaryTest {
|
|||||||
showdown = false,
|
showdown = false,
|
||||||
pot = 6,
|
pot = 6,
|
||||||
),
|
),
|
||||||
seatNames = listOf("You", "Ada", "Bruno"),
|
seatNames = listOf("Jay", "Ada", "Bruno"),
|
||||||
)
|
)
|
||||||
|
|
||||||
assertEquals("You win", summary.title)
|
assertEquals("You win", summary.title)
|
||||||
|
assertTrue(summary.heroWon)
|
||||||
assertEquals("Uncontested • Pot 6 • You won 5", summary.detail)
|
assertEquals("Uncontested • Pot 6 • You won 5", summary.detail)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@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(
|
val summary = handSummaryFor(
|
||||||
handNumber = 9,
|
handNumber = 9,
|
||||||
result = result(
|
result = result(
|
||||||
@@ -68,17 +69,25 @@ class HandSummaryTest {
|
|||||||
winners = listOf(0, 1),
|
winners = listOf(0, 1),
|
||||||
pot = 40,
|
pot = 40,
|
||||||
),
|
),
|
||||||
seatNames = listOf("You", "Ada", "Bruno"),
|
seatNames = listOf("Jay", "Ada", "Bruno"),
|
||||||
)
|
)
|
||||||
|
|
||||||
assertEquals("You & Ada win", summary.title)
|
assertEquals("You & Ada win", summary.title)
|
||||||
|
assertTrue(summary.heroWon)
|
||||||
assertTrue(summary.detail.endsWith("You broke even"))
|
assertTrue(summary.detail.endsWith("You broke even"))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class VisibleHandSummaryTest {
|
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(
|
private fun snapshot(
|
||||||
handNumber: Int = 4,
|
handNumber: Int = 4,
|
||||||
|
|||||||
Reference in New Issue
Block a user