From 3865346b2be9b3120862666c5238de2b49746ec3 Mon Sep 17 00:00:00 2001 From: Laurent Date: Tue, 25 Feb 2020 12:21:30 +0100 Subject: [PATCH] Update remaining stacks when updating antes --- .../handhistory/model/HandHistoryViewModel.kt | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) 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 512abc0f..9eafe3fb 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 @@ -823,10 +823,37 @@ class HandHistoryViewModel : ViewModel(), RowRepresentableDataSource, CardCentra fun setAnte(ante: Double) { this.handHistory.ante = ante + + val positionIndexes = (0..this.handHistory.numberOfPlayers).toList() + updatePlayerRemainingStacks(positionIndexes) } fun setBigBlindAnte(bigBlindAnte: Boolean) { this.handHistory.bigBlindAnte = bigBlindAnte + val bbIndex = this.sortedActions.positions.indexOf(Position.BB) + updatePlayerRemainingStacks(listOf(bbIndex)) + } + + private fun updatePlayerRemainingStacks(positions: List) { + + val ante = if (this.handHistory.bigBlindAnte) this.handHistory.bigBlind ?: 0.0 else this.handHistory.ante + + positions.forEach { position -> + this.handHistory.playerSetupForPosition(position)?.stack?.let { initialStack -> + + var remainingStack = initialStack - ante + val playerActions = this.sortedActions.filter { it.action.position == position } + playerActions.forEach { + remainingStack -= it.action.effectiveAmount + it.playerRemainingStack = remainingStack + if (it.action.type?.isAllin == true) { + it.action.amount = remainingStack + } + } + } + + } + } } \ No newline at end of file