Remaining stack calculations

hh
Laurent 6 years ago
parent 3865346b2b
commit 2da1f6f410
  1. 44
      app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/model/ActionList.kt
  2. 2
      app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/model/ComputedAction.kt
  3. 36
      app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/model/HandHistoryViewModel.kt

@ -15,7 +15,7 @@ interface ActionManager {
fun getPlayerNextStreetActions(index: Int): List<ComputedAction>
fun dropNextActions(index: Int)
fun allinAmountSet(positionIndex: Int)
fun blindSet(type: Action.Type, amount: Double)
fun blindsUpdated(type: Action.Type, amount: Double)
}
interface ActionListListener : PlayerSetupCreationListener {
@ -460,10 +460,15 @@ class ActionList(var listener: ActionListListener) : ArrayList<ComputedAction>()
/***
* Sets the blinds value in the hand history
*/
override fun blindSet(type: Action.Type, amount: Double) {
override fun blindsUpdated(type: Action.Type, amount: Double) {
when (type) {
Action.Type.POST_SB -> this.handHistory.smallBlind = amount
Action.Type.POST_BB -> this.handHistory.bigBlind = amount
Action.Type.POST_BB -> {
this.handHistory.bigBlind = amount
if (this.handHistory.bigBlindAnte) {
this.updateRemainingStacksForPositions(listOf())
}
}
else -> throw PAIllegalStateException("Should never happen")
}
}
@ -570,4 +575,37 @@ class ActionList(var listener: ActionListListener) : ArrayList<ComputedAction>()
}
}
/***
* Updates the remaining stacks for each action of the big blind
*/
fun updateBigBlindRemainingStack() {
val bbIndex = this.positions.indexOf(Position.BB)
this.updateRemainingStacksForPositions(listOf(bbIndex))
}
/***
* Recomputes all remaining stacks for the given [positions]
*/
fun updateRemainingStacksForPositions(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.filter { it.action.position == position }
playerActions.forEach {
remainingStack -= it.action.effectiveAmount
it.playerRemainingStack = remainingStack
if (it.action.type?.isAllin == true) {
it.action.amount = remainingStack
}
}
}
}
}
}

@ -127,7 +127,7 @@ class ComputedAction(var manager: ActionManager,
this.manager.allinAmountSet(this.action.position)
}
this.action.type?.isBlind == true -> {
this.manager.blindSet(this.action.type!!, amount)
this.manager.blindsUpdated(this.action.type!!, amount)
}
}

@ -75,6 +75,9 @@ class HandHistoryViewModel : ViewModel(), RowRepresentableDataSource, CardCentra
val currentSelection: HHSelection
get() { return selectionLiveData.value ?: throw PAIllegalStateException("No selection") }
/***
* Returns the current selected keyboard
*/
val currentKeyboard: HHKeyboard?
get() {
this.selectionLiveData.value?.let {
@ -821,39 +824,22 @@ class HandHistoryViewModel : ViewModel(), RowRepresentableDataSource, CardCentra
return this.sortedActions.positions.elementAt(positionIndex)
}
/***
* Sets the ante value
*/
fun setAnte(ante: Double) {
this.handHistory.ante = ante
val positionIndexes = (0..this.handHistory.numberOfPlayers).toList()
updatePlayerRemainingStacks(positionIndexes)
this.sortedActions.updateRemainingStacksForPositions(positionIndexes)
}
/***
* Sets whether the hand uses big blind ante or not
*/
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
}
}
}
}
this.sortedActions.updateBigBlindRemainingStack()
}
}
Loading…
Cancel
Save