Update remaining stacks when updating antes

hh
Laurent 6 years ago
parent 2396150123
commit 3865346b2b
  1. 27
      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<Int>) {
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
}
}
}
}
}
}
Loading…
Cancel
Save