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