From acd97e6a5c00783044d2f30410e0d8a542b65c40 Mon Sep 17 00:00:00 2001 From: Laurent Date: Tue, 7 Apr 2020 11:17:10 +0200 Subject: [PATCH] Added pot test and fixed issue --- .../model/realm/handhistory/HandHistory.kt | 56 ++++++++++++------- .../pokeranalytics/android/HandHistoryTest.kt | 37 +++++++++++- 2 files changed, 73 insertions(+), 20 deletions(-) diff --git a/app/src/main/java/net/pokeranalytics/android/model/realm/handhistory/HandHistory.kt b/app/src/main/java/net/pokeranalytics/android/model/realm/handhistory/HandHistory.kt index 01d4f5cd..11c2521e 100644 --- a/app/src/main/java/net/pokeranalytics/android/model/realm/handhistory/HandHistory.kt +++ b/app/src/main/java/net/pokeranalytics/android/model/realm/handhistory/HandHistory.kt @@ -577,8 +577,7 @@ open class HandHistory : RealmObject(), Deletable, RowRepresentable, Filterable, this.winnerPots.addAll(wonPots) } - private fun getPots(eligiblePositions: List): List { - + fun getPots(eligiblePositions: List): List { var runningPotAmount = 0.0 val pots = mutableListOf() @@ -604,29 +603,48 @@ open class HandHistory : RealmObject(), Deletable, RowRepresentable, Filterable, val amount = positionAmount.amount val position = positionAmount.position - val isAllin = allinPositions.contains(position) - 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 + var rest = amount + var lastPotLevel = 0.0 + streetPots.forEach { pot -> + val added = pot.level - lastPotLevel + pot.amount += added + if (eligiblePositions.contains(position)) { + pot.positions.add(position) } + rest -= added + lastPotLevel = pot.level + } + runningPotAmount += rest - } else { - runningPotAmount += amount + val isAllin = allinPositions.contains(position) + if (isAllin) { streetPots.add(Pot(runningPotAmount, amount, mutableSetOf(position))) 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) } diff --git a/app/src/test/java/net/pokeranalytics/android/HandHistoryTest.kt b/app/src/test/java/net/pokeranalytics/android/HandHistoryTest.kt index 21456a50..6d47164e 100644 --- a/app/src/test/java/net/pokeranalytics/android/HandHistoryTest.kt +++ b/app/src/test/java/net/pokeranalytics/android/HandHistoryTest.kt @@ -14,7 +14,6 @@ fun HandHistory.addAction(street: Street, position: Int, type: Action.Type, effe action.street = street action.position = position action.type = type -// action.amount = amount action.effectiveAmount = effectiveAmount action.index = this.actions.size 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) + + } } \ No newline at end of file