Manages pot size for street headers

hh
Laurent 6 years ago
parent 0ab62bfedb
commit 9143bf4e10
  1. 54
      app/src/main/java/net/pokeranalytics/android/model/handhistory/ComputedAction.kt
  2. 34
      app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/HHBuilder.kt
  3. 2
      app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/HandHistoryViewModel.kt

@ -33,6 +33,31 @@ class ComputedAction(var action: Action,
}
}
/***
* Sets the action amount
*/
fun setAmount(amount: Double, committedAmount: Double) {
val oldAmount = this.action.amount
val remainingStack = this.playerRemainingStack
this.action.effectiveAmount = amount - committedAmount
if (oldAmount != null && remainingStack != null) {
val oldPlayerRemainingStack = remainingStack + oldAmount
val revisedAmount = min(amount, oldPlayerRemainingStack)
val revisedRemainingStack = remainingStack - revisedAmount + oldAmount
this.playerRemainingStack = revisedRemainingStack
this.action.toggleType(remainingStack)
} else {
this.action.amount = amount
}
}
/***
* Sets the effective amount of the action
* Also calculates the player remaining stack if possible
@ -53,7 +78,12 @@ class ComputedAction(var action: Action,
}
}
override val viewType: Int = HandRowType.ACTION.ordinal
/***
* Updates the total pot size
*/
// private fun updateTotalPotSize(previous: Double, new: Double) {
// this.totalPotSize = this.totalPotSize - previous + new
// }
override fun keyboardForCompletion() : HHKeyboard? {
Timber.d("index = ${action.index} / type = ${this.action.type} / amount = ${this.action.amount}")
@ -68,26 +98,6 @@ class ComputedAction(var action: Action,
}
}
fun setAmount(amount: Double) {
val oldAmount = this.action.amount
val remainingStack = this.playerRemainingStack
if (oldAmount != null && remainingStack != null) {
val oldPlayerRemainingStack = remainingStack + oldAmount
val revisedAmount = min(amount, oldPlayerRemainingStack)
val revisedRemainingStack = remainingStack - revisedAmount + oldAmount
this.playerRemainingStack = revisedRemainingStack
this.action.toggleType(remainingStack)
} else {
this.action.amount = amount
}
}
/***
* Returns whether the action type can be edited
* SB / BB cannot have their action type edited
@ -117,4 +127,6 @@ class ComputedAction(var action: Action,
// return amountCanBeEdited
}
override val viewType: Int = HandRowType.ACTION.ordinal
}

@ -218,7 +218,7 @@ class HHBuilder {
?: throw PAIllegalStateException("There must be a previously set significant action for a call to be set")
val significantAmount = significantAction.action.amount
?: throw PAIllegalStateException("There must be a set amount on the action for the call to be set")
val committedAmount = getPreviousCommittedAmount(index) ?: 0.0
val committedAmount = getPreviouslyCommittedAmount(index) ?: 0.0
computedAction.setEffectiveAmount(significantAmount - committedAmount)
}
Action.Type.CALL_ALLIN -> {
@ -378,7 +378,7 @@ class HHBuilder {
val lastComputedAction = this.sortedActions.last()
val totalPotSize = lastComputedAction.totalPotSize
addStreetHeader(this.rowRepresentables, street, totalPotSize)
addStreetHeader(this.rowRepresentables, street)
val lastActionIndex = lastComputedAction.action.index
val isShowDown = street == Street.SUMMARY
@ -435,12 +435,14 @@ class HHBuilder {
val computedAction = this.actionForIndex(index)
Timber.d(">>> Sets $amount at index: $index, for action ${computedAction.action.type}")
computedAction.setAmount(amount)
val committedAmount = getPreviouslyCommittedAmount(index) ?: 0.0
computedAction.setAmount(amount, committedAmount)
when (computedAction.action.type) {
Action.Type.BET, Action.Type.RAISE, Action.Type.BET_ALLIN, Action.Type.RAISE_ALLIN -> {
getStreetNextCalls(index).forEach {
val playerCommittedAmount = getPreviouslyCommittedAmount(it.action.index) ?: 0.0
it.setEffectiveAmount(amount)
}
@ -448,7 +450,6 @@ class HHBuilder {
if (computedAction.action.type == Action.Type.RAISE_ALLIN) {
getStreetLastSignificantAction(index)?.action?.amount?.let { significantActionAmount ->
val committedAmount = getPreviousCommittedAmount(index) ?: 0.0
val askedAmount = significantActionAmount - committedAmount
computedAction.playerRemainingStack?.let { remainingStack ->
@ -463,20 +464,10 @@ class HHBuilder {
}
}
/***
* Clears the amount at the given [index]
*/
fun clearAmount(index: Int) {
val computedAction = this.actionForIndex(index)
computedAction.action.amount = null
// TODO consequences? follow up CALL for example?
}
/***
* Returns the committed amount by the player for the street at the current [index]
*/
private fun getPreviousCommittedAmount(index: Int) : Double? {
private fun getPreviouslyCommittedAmount(index: Int) : Double? {
val action = this.actionForIndex(index).action
val position = action.position
val street = action.street
@ -751,7 +742,6 @@ class HHBuilder {
rows.add(CustomizableRowRepresentable(customViewType = HandRowType.HEADER, resId = R.string.settings))
var potSize = 0.0
Street.values().forEach { street ->
val actions = this.sortedActions.filter { it.action.street == street }
@ -761,7 +751,7 @@ class HHBuilder {
val lastActionIndex = this.sortedActions.size - 1
if (activePositions(lastActionIndex).size < 2 || isStreetActionClosed(lastActionIndex) == Street.SUMMARY) {
addStreetHeader(rows, street, potSize)
addStreetHeader(rows, street)
activePositions(lastActionIndex).forEach {
val positionIndex = this.positions.indexOf(it)
@ -772,9 +762,8 @@ class HHBuilder {
}
else -> {
if (actions.isNotEmpty()) {
addStreetHeader(rows, street, potSize)
addStreetHeader(rows, street)
rows.addAll(actions)
potSize = actions.last().totalPotSize
}
}
}
@ -839,10 +828,13 @@ class HHBuilder {
}
/***
* Adds a [street] header to a [rowRepresentables] list with a given [potSize]
* Adds a [street] header to a [rowRepresentables]
*/
private fun addStreetHeader(rowRepresentables: MutableList<RowRepresentable>, street: Street, potSize: Double) {
private fun addStreetHeader(rowRepresentables: MutableList<RowRepresentable>, street: Street) {
val potSize = this.sortedActions.sumByDouble { it.action.effectiveAmount }
val potString = if (potSize > 0) potSize.formatted() else null
val headerView = CustomizableRowRepresentable(customViewType = HandRowType.HEADER, resId = street.resId, value = potString)
rowRepresentables.add(headerView)

@ -57,7 +57,7 @@ class HandHistoryViewModel : ViewModel(), RowRepresentableDataSource {
}
fun clearAmount() {
builderLiveData.value?.clearAmount(this.actionIndexForSelection)
// builderLiveData.value?.clearAmount(this.actionIndexForSelection)
this.currentAmount = null
}

Loading…
Cancel
Save