Fixes issue with remaining stacks

hh
Laurent 6 years ago
parent 8cace5259a
commit bbd4d3640a
  1. 22
      app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/model/ActionList.kt
  2. 14
      app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/model/ComputedAction.kt
  3. 1
      app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/model/HandHistoryViewModel.kt

@ -200,7 +200,7 @@ class ActionList(var listener: ActionListListener) : ArrayList<ComputedAction>()
} }
Action.Type.RAISE_ALLIN, Action.Type.BET_ALLIN -> { Action.Type.RAISE_ALLIN, Action.Type.BET_ALLIN -> {
if (remainingStack != null && actionAmount != null && remainingStack <= actionAmount) { 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) { } else if (activePositions(index).size == 2 && remainingStack != null && actionAmount != null && remainingStack > actionAmount) {
setOf(Action.Type.FOLD, Action.Type.CALL) setOf(Action.Type.FOLD, Action.Type.CALL)
} else { } else {
@ -632,4 +632,24 @@ class ActionList(var listener: ActionListListener) : ArrayList<ComputedAction>()
} }
/***
* 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")
}
} }

@ -236,7 +236,19 @@ class ComputedAction(var manager: ActionManager,
val significantAmount = significantAction.action.amount ?: 0.0 val significantAmount = significantAction.action.amount ?: 0.0
val committedAmount = getPreviouslyCommittedAmount() 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? { private fun getStreetLastSignificantAction(): ComputedAction? {

@ -496,6 +496,7 @@ class HandHistoryViewModel : ViewModel(), RowRepresentableDataSource, CardCentra
} }
is PlayerSetupRow -> { is PlayerSetupRow -> {
row.setStack(amount) row.setStack(amount)
this.sortedActions.stackUpdatedAtPosition(row.positionIndex)
} }
else -> {} else -> {}
} }

Loading…
Cancel
Save