From bbd4d3640a5e41f9110ce2a7f03339d6822754e3 Mon Sep 17 00:00:00 2001 From: Laurent Date: Mon, 23 Mar 2020 12:41:34 +0100 Subject: [PATCH] Fixes issue with remaining stacks --- .../modules/handhistory/model/ActionList.kt | 22 ++++++++++++++++++- .../handhistory/model/ComputedAction.kt | 14 +++++++++++- .../handhistory/model/HandHistoryViewModel.kt | 1 + 3 files changed, 35 insertions(+), 2 deletions(-) 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 8877df97..e1a4fc30 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 @@ -200,7 +200,7 @@ class ActionList(var listener: ActionListListener) : ArrayList() } Action.Type.RAISE_ALLIN, Action.Type.BET_ALLIN -> { if (remainingStack != null && actionAmount != null && remainingStack <= actionAmount) { - setOf(Action.Type.FOLD, Action.Type.CALL_ALLIN) + setOf(Action.Type.FOLD, Action.Type.CALL) } else if (activePositions(index).size == 2 && remainingStack != null && actionAmount != null && remainingStack > actionAmount) { setOf(Action.Type.FOLD, Action.Type.CALL) } else { @@ -632,4 +632,24 @@ class ActionList(var listener: ActionListListener) : ArrayList() } + /*** + * Updates all ComputedAction linked to the position with an updated value of the remaining stack + */ + fun stackUpdatedAtPosition(positionIndex: Int) { + this.handHistory.playerSetupForPosition(positionIndex)?.let { playerSetup -> + + var remainingStack = playerSetup.stack + this.filter { it.action.position == positionIndex }.forEach { ca -> + + remainingStack?.let { rs -> + remainingStack = rs - ca.action.effectiveAmount + ca.playerRemainingStack = remainingStack + } ?: run { + ca.playerRemainingStack = null + } + } + + } ?: throw PAIllegalStateException("Can't happen") + } + } 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 4e6b9605..1e9d9046 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 @@ -236,7 +236,19 @@ class ComputedAction(var manager: ActionManager, val significantAmount = significantAction.action.amount ?: 0.0 val committedAmount = getPreviouslyCommittedAmount() - this.setEffectiveAmount(significantAmount - committedAmount) + var effectiveAmount = significantAmount - committedAmount + + // Fixes effective if the remaining stack is lower + this.playerRemainingStack?.let { stack -> + if (stack < effectiveAmount) { + effectiveAmount = stack + if (this.action.type == Action.Type.CALL) { + this.action.type = Action.Type.CALL_ALLIN + } + } + } + + this.setEffectiveAmount(effectiveAmount) } private fun getStreetLastSignificantAction(): ComputedAction? { 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 6bbbc8ef..43f2a3f3 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 @@ -496,6 +496,7 @@ class HandHistoryViewModel : ViewModel(), RowRepresentableDataSource, CardCentra } is PlayerSetupRow -> { row.setStack(amount) + this.sortedActions.stackUpdatedAtPosition(row.positionIndex) } else -> {} }