From 8dabd8931f747268c774c1dd97790dcc5b864da2 Mon Sep 17 00:00:00 2001 From: Laurent Date: Fri, 6 Mar 2020 15:59:04 +0100 Subject: [PATCH] Adds POT action --- .../android/model/realm/handhistory/Action.kt | 5 +++-- .../modules/handhistory/model/ActionList.kt | 19 ++++++++++++------- .../handhistory/model/ComputedAction.kt | 10 +++++++++- .../handhistory/model/HandHistoryViewModel.kt | 5 ++++- app/src/main/res/values/strings.xml | 7 ++++--- 5 files changed, 32 insertions(+), 14 deletions(-) diff --git a/app/src/main/java/net/pokeranalytics/android/model/realm/handhistory/Action.kt b/app/src/main/java/net/pokeranalytics/android/model/realm/handhistory/Action.kt index 218e447e..ce90eb68 100644 --- a/app/src/main/java/net/pokeranalytics/android/model/realm/handhistory/Action.kt +++ b/app/src/main/java/net/pokeranalytics/android/model/realm/handhistory/Action.kt @@ -43,6 +43,7 @@ open class Action : RealmObject() { CHECK(R.string.check), CALL(R.string.call), BET(R.string.bet), + POT(R.string.pot), RAISE(R.string.raise), UNDEFINED_ALLIN(R.string.allin), CALL_ALLIN(R.string.callin), @@ -60,7 +61,7 @@ open class Action : RealmObject() { val isSignificant: Boolean get() { return when (this) { - POST_SB, POST_BB, STRADDLE, BET, RAISE, BET_ALLIN, RAISE_ALLIN -> true + POST_SB, POST_BB, STRADDLE, BET, POT, RAISE, BET_ALLIN, RAISE_ALLIN -> true UNDEFINED_ALLIN -> throw PAIllegalStateException("Can't ask for UNDEFINED_ALLIN") else -> false } @@ -109,7 +110,7 @@ open class Action : RealmObject() { companion object { val defaultTypes: List by lazy { - listOf(FOLD, CHECK, BET, CALL, RAISE, UNDEFINED_ALLIN) + listOf(FOLD, CHECK, BET, POT, CALL, RAISE, UNDEFINED_ALLIN) } } diff --git a/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/model/ActionList.kt b/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/model/ActionList.kt index 998cf191..be31784a 100644 --- a/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/model/ActionList.kt +++ b/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/model/ActionList.kt @@ -17,6 +17,7 @@ interface ActionManager { fun allinAmountSet(positionIndex: Int) fun blindsUpdated(type: Action.Type, amount: Double) fun minimumBetAmount(index: Int): Double + fun totalPotSize(index: Int): Double } interface ActionListListener : PlayerSetupCreationListener { @@ -170,7 +171,7 @@ class ActionList(var listener: ActionListListener) : ArrayList() val lastSignificantAction: ComputedAction? = getStreetLastSignificantAction(computedAction.street, index - 1) return if (lastSignificantAction == null) { - setOf(Action.Type.FOLD, Action.Type.CHECK, Action.Type.BET, Action.Type.UNDEFINED_ALLIN) + setOf(Action.Type.FOLD, Action.Type.CHECK, Action.Type.BET, Action.Type.POT, Action.Type.UNDEFINED_ALLIN) } else { val remainingStack = getLastPlayerAction(index)?.playerRemainingStack val actionAmount = lastSignificantAction.action.amount @@ -178,16 +179,16 @@ class ActionList(var listener: ActionListListener) : ArrayList() when (lastSignificantAction.action.type) { Action.Type.POST_SB, Action.Type.POST_BB, Action.Type.STRADDLE -> { if (position == lastSignificantAction.position) { - setOf(Action.Type.FOLD, Action.Type.CHECK, Action.Type.BET, Action.Type.UNDEFINED_ALLIN) + setOf(Action.Type.FOLD, Action.Type.CHECK, Action.Type.BET, Action.Type.POT, Action.Type.UNDEFINED_ALLIN) } else { - setOf(Action.Type.FOLD, Action.Type.CALL, Action.Type.BET, Action.Type.UNDEFINED_ALLIN) + setOf(Action.Type.FOLD, Action.Type.CALL, Action.Type.BET, Action.Type.POT, Action.Type.UNDEFINED_ALLIN) } } - Action.Type.BET, Action.Type.RAISE -> { + Action.Type.BET, Action.Type.POT, Action.Type.RAISE -> { if (remainingStack != null && actionAmount != null && remainingStack <= actionAmount) { setOf(Action.Type.FOLD, Action.Type.CALL_ALLIN) } else { - setOf(Action.Type.FOLD, Action.Type.CALL, Action.Type.RAISE, Action.Type.UNDEFINED_ALLIN) + setOf(Action.Type.FOLD, Action.Type.CALL, Action.Type.POT, Action.Type.RAISE, Action.Type.UNDEFINED_ALLIN) } } Action.Type.RAISE_ALLIN, Action.Type.BET_ALLIN -> { @@ -196,11 +197,11 @@ class ActionList(var listener: ActionListListener) : ArrayList() } else if (activePositions(index).size == 2 && remainingStack != null && actionAmount != null && remainingStack > actionAmount) { setOf(Action.Type.FOLD, Action.Type.CALL) } else { - setOf(Action.Type.FOLD, Action.Type.CALL, Action.Type.RAISE, Action.Type.UNDEFINED_ALLIN) + setOf(Action.Type.FOLD, Action.Type.CALL, Action.Type.POT, Action.Type.RAISE, Action.Type.UNDEFINED_ALLIN) } } else -> { - throw PAIllegalStateException("We should not handle this action: ${lastSignificantAction.action.type}") + throw PAIllegalStateException("We do not handle this action: ${lastSignificantAction.action.type}") } } } @@ -551,6 +552,10 @@ class ActionList(var listener: ActionListListener) : ArrayList() } } + override fun totalPotSize(index: Int): Double { + return this.handHistory.anteSum + this.take(index).sumByDouble { it.action.effectiveAmount } + } + /*** * Returns the next significant player action in the street, if any, for the action at the provided [index] */ diff --git a/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/model/ComputedAction.kt b/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/model/ComputedAction.kt index 181a3cc3..18e2fed5 100644 --- a/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/model/ComputedAction.kt +++ b/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/model/ComputedAction.kt @@ -78,8 +78,16 @@ class ComputedAction(var manager: ActionManager, Action.Type.STRADDLE -> { // TODO } + Action.Type.POT -> { + val lastSignificantAction = this.getStreetLastSignificantAction() + val lastSignificantAmount = lastSignificantAction?.action?.amount ?: 0.0 + val potAmount = lastSignificantAmount * 2 + this.manager.totalPotSize(this.action.index) + this.setAmount(potAmount) + } Action.Type.BET_ALLIN, Action.Type.RAISE_ALLIN, Action.Type.UNDEFINED_ALLIN -> { - this.action.amount = this.playerRemainingStack + this.playerRemainingStack?.let { + this.setAmount(it) + } } else -> {} } diff --git a/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/model/HandHistoryViewModel.kt b/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/model/HandHistoryViewModel.kt index a59b51b3..365488e4 100644 --- a/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/model/HandHistoryViewModel.kt +++ b/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/model/HandHistoryViewModel.kt @@ -351,10 +351,13 @@ class HandHistoryViewModel : ViewModel(), RowRepresentableDataSource, CardCentra } + /*** + * Returns the formatted pot size at the given [street] + */ private fun formattedPotSizeForStreet(street: Street): String { val firstIndexOfStreet = this.sortedActions.firstOrNull { it.street == street }?.action?.index ?: this.sortedActions.size - val potSize = this.handHistory.anteSum + this.sortedActions.take(firstIndexOfStreet).sumByDouble { it.action.effectiveAmount } + val potSize = this.sortedActions.totalPotSize(firstIndexOfStreet) return if (potSize > 0) potSize.formatted() else "" // "" required otherwise random values come up } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index ac33c255..0f04d791 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -785,11 +785,12 @@ check call bet + pot raise allin - b_allin - c_allin - r_allin + allin + allin + allin mississipi Hero position