Added pot test and fixed issue

hh
Laurent 6 years ago
parent ce5a1d219b
commit acd97e6a5c
  1. 44
      app/src/main/java/net/pokeranalytics/android/model/realm/handhistory/HandHistory.kt
  2. 37
      app/src/test/java/net/pokeranalytics/android/HandHistoryTest.kt

@ -577,8 +577,7 @@ open class HandHistory : RealmObject(), Deletable, RowRepresentable, Filterable,
this.winnerPots.addAll(wonPots) this.winnerPots.addAll(wonPots)
} }
private fun getPots(eligiblePositions: List<Int>): List<Pot> { fun getPots(eligiblePositions: List<Int>): List<Pot> {
var runningPotAmount = 0.0 var runningPotAmount = 0.0
val pots = mutableListOf<Pot>() val pots = mutableListOf<Pot>()
@ -604,29 +603,48 @@ open class HandHistory : RealmObject(), Deletable, RowRepresentable, Filterable,
val amount = positionAmount.amount val amount = positionAmount.amount
val position = positionAmount.position val position = positionAmount.position
val isAllin = allinPositions.contains(position)
if (!isAllin) {
if (streetPots.isEmpty()) {
runningPotAmount += amount
} else {
var rest = amount var rest = amount
var lastPotLevel = 0.0
streetPots.forEach { pot -> streetPots.forEach { pot ->
pot.amount += pot.level val added = pot.level - lastPotLevel
pot.amount += added
if (eligiblePositions.contains(position)) { if (eligiblePositions.contains(position)) {
pot.positions.add(position) pot.positions.add(position)
} }
rest -= pot.level rest -= added
lastPotLevel = pot.level
} }
runningPotAmount += rest runningPotAmount += rest
}
} else { val isAllin = allinPositions.contains(position)
runningPotAmount += amount if (isAllin) {
streetPots.add(Pot(runningPotAmount, amount, mutableSetOf(position))) streetPots.add(Pot(runningPotAmount, amount, mutableSetOf(position)))
runningPotAmount = 0.0 runningPotAmount = 0.0
} }
// if (!isAllin) {
//
// if (streetPots.isEmpty()) {
// runningPotAmount += amount
// } else {
// var rest = amount
// streetPots.forEach { pot ->
// pot.amount += pot.level
// if (eligiblePositions.contains(position)) {
// pot.positions.add(position)
// }
// rest -= pot.level
// }
// runningPotAmount += rest
// }
//
// } else {
// runningPotAmount += amount
// streetPots.add(Pot(runningPotAmount, amount, mutableSetOf(position)))
// runningPotAmount = 0.0
// }
} }
pots.addAll(streetPots) pots.addAll(streetPots)
} }

@ -14,7 +14,6 @@ fun HandHistory.addAction(street: Street, position: Int, type: Action.Type, effe
action.street = street action.street = street
action.position = position action.position = position
action.type = type action.type = type
// action.amount = amount
action.effectiveAmount = effectiveAmount action.effectiveAmount = effectiveAmount
action.index = this.actions.size action.index = this.actions.size
this.actions.add(action) this.actions.add(action)
@ -159,4 +158,40 @@ class HandHistoryTest {
} }
@Test
fun potTest5() { // A multi allin pot
val hh = handHistoryInstance(5) // 3
hh.addAction(Street.PREFLOP, 0, Action.Type.BET_ALLIN, 1999.0)
hh.addAction(Street.PREFLOP, 1, Action.Type.CALL, 1998.0)
hh.addAction(Street.PREFLOP, 2, Action.Type.CALL_ALLIN, 1000.0) // 5000
hh.addAction(Street.PREFLOP, 3, Action.Type.CALL_ALLIN, 500.0) // 5500
hh.addAction(Street.PREFLOP, 4, Action.Type.RAISE_ALLIN, 4000.0)
hh.addAction(Street.PREFLOP, 1, Action.Type.CALL, 2000.0) // 11500
val ps0 = playerSetupInstance(0, listOf(card(14, 3), card(2, 1)))
val ps1 = playerSetupInstance(1, listOf(card(13, 3), card(3, 1)))
val ps2 = playerSetupInstance(2, listOf(card(11, 3), card(4, 1)))
val ps3 = playerSetupInstance(3, listOf(card(10, 3), card(5, 1)))
val ps4 = playerSetupInstance(4, listOf(card(8, 3), card(6, 1)))
hh.playerSetups.addAll(listOf(ps0, ps1, ps2, ps3, ps4))
hh.board.addAll(board(listOf(4, 5, 6, 7, 9), listOf(3, 3, 3, 3, 3)))
// hh.defineWinnerPositions()
val pots = hh.getPots(hh.positionIndexes.toList())
Assert.assertEquals(4, pots.size)
val mainPot = pots.any { it.amount == 2500.0 }
Assert.assertEquals(true, mainPot)
val pot1 = pots.any { it.amount == 2000.0 }
Assert.assertEquals(true, pot1)
val pot2 = pots.any { it.amount == 3000.0 }
Assert.assertEquals(true, pot2)
val pot3 = pots.any { it.amount == 4000.0 }
Assert.assertEquals(true, pot3)
}
} }
Loading…
Cancel
Save