From 93f17ef5222d44aa33a86fb488d5c35137a6e225 Mon Sep 17 00:00:00 2001 From: Laurent Date: Tue, 25 Feb 2020 17:46:21 +0100 Subject: [PATCH] Automatically defines a minimum amount if the user validates an empty amount --- .../android/model/realm/handhistory/Action.kt | 11 ++---- .../modules/handhistory/model/ActionList.kt | 37 +++++++++++++++---- .../handhistory/model/ComputedAction.kt | 22 +++-------- .../handhistory/model/HandHistoryViewModel.kt | 2 + 4 files changed, 40 insertions(+), 32 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 7199b3ac..d34607a5 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 @@ -53,6 +53,9 @@ open class Action : RealmObject() { } } + /*** + * Returns if the action is passive + */ val isPassive: Boolean get() { return when (this) { @@ -77,14 +80,6 @@ open class Action : RealmObject() { } } -// val requiresOpponentDecision: Boolean -// get() { -// return when(this) { -// CALL, CALL_ALLIN, FOLD -> false -// else -> true -// } -// } - override val viewType: Int = RowViewType.TITLE_GRID.ordinal companion object { 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 cac4ac68..3adebbb1 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 @@ -16,6 +16,7 @@ interface ActionManager { fun dropNextActions(index: Int) fun allinAmountSet(positionIndex: Int) fun blindsUpdated(type: Action.Type, amount: Double) + fun minimumBetAmount(index: Int): Double } interface ActionListListener : PlayerSetupCreationListener { @@ -127,6 +128,26 @@ class ActionList(var listener: ActionListListener) : ArrayList() computedAction.setAmount(amount) } + /*** + * Returns the minimum bet amount for an action at the given [index] + */ + override fun minimumBetAmount(index: Int): Double { + + val street = this[index].street + + // Verify that the amount is correct, at least the amount of the previous raise difference + getStreetLastSignificantAction(street, index - 1)?.action?.let { lastSignificantAction -> + val lastSignificantAmount = lastSignificantAction.amount + if (lastSignificantAmount != null) { + val previousSignificantAmount = getStreetLastSignificantAction(street, lastSignificantAction.index - 1)?.action?.amount ?: 0.0 + val differenceWithPreviousSignificantAmount = lastSignificantAmount - previousSignificantAmount + return lastSignificantAmount + differenceWithPreviousSignificantAmount + } + } + + return 0.0 + } + /*** * Fires the listener if the list count has changed */ @@ -566,14 +587,14 @@ class ActionList(var listener: ActionListListener) : ArrayList() /*** * Updates the small blind amount */ - fun updateBlinds() { - this.handHistory.smallBlind?.let { sb -> - this.firstOrNull { it.action.type == Action.Type.POST_SB }?.setAmount(sb) - } - this.handHistory.bigBlind?.let { bb -> - this.firstOrNull { it.action.type == Action.Type.POST_BB }?.setAmount(bb) - } - } +// fun updateBlinds() { +// this.handHistory.smallBlind?.let { sb -> +// this.firstOrNull { it.action.type == Action.Type.POST_SB }?.setAmount(sb) +// } +// this.handHistory.bigBlind?.let { bb -> +// this.firstOrNull { it.action.type == Action.Type.POST_BB }?.setAmount(bb) +// } +// } /*** * Updates the remaining stacks for each action of the big blind 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 8aa486ca..7382fe83 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 @@ -39,6 +39,9 @@ class ComputedAction(var manager: ActionManager, } } + /*** + * Sets the type of the action: bet, call, fold... + */ fun setType(type: Action.Type) { val typeChange = (this.action.type != null) @@ -76,18 +79,8 @@ class ComputedAction(var manager: ActionManager, */ fun setAmount(amount: Double) { - var correctedAmount = amount - - // Verify that the amount is correct, at least the amount of the previous raise difference - getStreetLastSignificantAction()?.action?.let { lastSignificantAction -> - val lastSignificantAmount = lastSignificantAction.amount - if (lastSignificantAmount != null) { - val previousSignificantAmount = getStreetSignificantActionBefore(lastSignificantAction.index)?.action?.amount ?: 0.0 - val differenceWithPreviousSignificantAmount = lastSignificantAmount - previousSignificantAmount - val minAmount = lastSignificantAmount + differenceWithPreviousSignificantAmount - correctedAmount = max(minAmount, correctedAmount) - } - } + val minimumAmount = this.manager.minimumBetAmount(this.action.index) + val correctedAmount = max(minimumAmount, amount) val committedAmount = this.getPreviouslyCommittedAmount() this.action.effectiveAmount = correctedAmount - committedAmount @@ -190,10 +183,7 @@ class ComputedAction(var manager: ActionManager, // } // } - override fun isFieldNeedsInput( - tag: Int, - handHistory: HandHistory - ): Boolean { + override fun isFieldNeedsInput(tag: Int, handHistory: HandHistory): Boolean { return when (tag) { Tag.ACTION.ordinal -> this.action.type == null Tag.AMOUNT.ordinal -> this.requiresAmount 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 58907ba7..8dac8d56 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 @@ -431,6 +431,8 @@ class HandHistoryViewModel : ViewModel(), RowRepresentableDataSource, CardCentra is ComputedAction -> { amount?.let { this.sortedActions.setAmount(this.actionIndexForSelection, amount) + } ?: run { + this.sortedActions.setAmount(this.actionIndexForSelection, this.handHistory.bigBlind ?: 0.0) } } is PlayerSetupRow -> {