Automatically defines a minimum amount if the user validates an empty amount

hh
Laurent 6 years ago
parent f48d79e0ad
commit 93f17ef522
  1. 11
      app/src/main/java/net/pokeranalytics/android/model/realm/handhistory/Action.kt
  2. 37
      app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/model/ActionList.kt
  3. 22
      app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/model/ComputedAction.kt
  4. 2
      app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/model/HandHistoryViewModel.kt

@ -53,6 +53,9 @@ open class Action : RealmObject() {
} }
} }
/***
* Returns if the action is passive
*/
val isPassive: Boolean val isPassive: Boolean
get() { get() {
return when (this) { return when (this) {
@ -77,14 +80,6 @@ open class Action : RealmObject() {
} }
} }
// val requiresOpponentDecision: Boolean
// get() {
// return when(this) {
// CALL, CALL_ALLIN, FOLD -> false
// else -> true
// }
// }
override val viewType: Int = RowViewType.TITLE_GRID.ordinal override val viewType: Int = RowViewType.TITLE_GRID.ordinal
companion object { companion object {

@ -16,6 +16,7 @@ interface ActionManager {
fun dropNextActions(index: Int) fun dropNextActions(index: Int)
fun allinAmountSet(positionIndex: Int) fun allinAmountSet(positionIndex: Int)
fun blindsUpdated(type: Action.Type, amount: Double) fun blindsUpdated(type: Action.Type, amount: Double)
fun minimumBetAmount(index: Int): Double
} }
interface ActionListListener : PlayerSetupCreationListener { interface ActionListListener : PlayerSetupCreationListener {
@ -127,6 +128,26 @@ class ActionList(var listener: ActionListListener) : ArrayList<ComputedAction>()
computedAction.setAmount(amount) computedAction.setAmount(amount)
} }
/***
* Returns the minimum bet amount for an action at the given [index]
*/
override fun minimumBetAmount(index: Int): Double {
val street = this[index].street
// Verify that the amount is correct, at least the amount of the previous raise difference
getStreetLastSignificantAction(street, index - 1)?.action?.let { lastSignificantAction ->
val lastSignificantAmount = lastSignificantAction.amount
if (lastSignificantAmount != null) {
val previousSignificantAmount = getStreetLastSignificantAction(street, lastSignificantAction.index - 1)?.action?.amount ?: 0.0
val differenceWithPreviousSignificantAmount = lastSignificantAmount - previousSignificantAmount
return lastSignificantAmount + differenceWithPreviousSignificantAmount
}
}
return 0.0
}
/*** /***
* Fires the listener if the list count has changed * Fires the listener if the list count has changed
*/ */
@ -566,14 +587,14 @@ class ActionList(var listener: ActionListListener) : ArrayList<ComputedAction>()
/*** /***
* Updates the small blind amount * Updates the small blind amount
*/ */
fun updateBlinds() { // fun updateBlinds() {
this.handHistory.smallBlind?.let { sb -> // this.handHistory.smallBlind?.let { sb ->
this.firstOrNull { it.action.type == Action.Type.POST_SB }?.setAmount(sb) // this.firstOrNull { it.action.type == Action.Type.POST_SB }?.setAmount(sb)
} // }
this.handHistory.bigBlind?.let { bb -> // this.handHistory.bigBlind?.let { bb ->
this.firstOrNull { it.action.type == Action.Type.POST_BB }?.setAmount(bb) // this.firstOrNull { it.action.type == Action.Type.POST_BB }?.setAmount(bb)
} // }
} // }
/*** /***
* Updates the remaining stacks for each action of the big blind * Updates the remaining stacks for each action of the big blind

@ -39,6 +39,9 @@ class ComputedAction(var manager: ActionManager,
} }
} }
/***
* Sets the type of the action: bet, call, fold...
*/
fun setType(type: Action.Type) { fun setType(type: Action.Type) {
val typeChange = (this.action.type != null) val typeChange = (this.action.type != null)
@ -76,18 +79,8 @@ class ComputedAction(var manager: ActionManager,
*/ */
fun setAmount(amount: Double) { fun setAmount(amount: Double) {
var correctedAmount = amount val minimumAmount = this.manager.minimumBetAmount(this.action.index)
val correctedAmount = max(minimumAmount, amount)
// Verify that the amount is correct, at least the amount of the previous raise difference
getStreetLastSignificantAction()?.action?.let { lastSignificantAction ->
val lastSignificantAmount = lastSignificantAction.amount
if (lastSignificantAmount != null) {
val previousSignificantAmount = getStreetSignificantActionBefore(lastSignificantAction.index)?.action?.amount ?: 0.0
val differenceWithPreviousSignificantAmount = lastSignificantAmount - previousSignificantAmount
val minAmount = lastSignificantAmount + differenceWithPreviousSignificantAmount
correctedAmount = max(minAmount, correctedAmount)
}
}
val committedAmount = this.getPreviouslyCommittedAmount() val committedAmount = this.getPreviouslyCommittedAmount()
this.action.effectiveAmount = correctedAmount - committedAmount this.action.effectiveAmount = correctedAmount - committedAmount
@ -190,10 +183,7 @@ class ComputedAction(var manager: ActionManager,
// } // }
// } // }
override fun isFieldNeedsInput( override fun isFieldNeedsInput(tag: Int, handHistory: HandHistory): Boolean {
tag: Int,
handHistory: HandHistory
): Boolean {
return when (tag) { return when (tag) {
Tag.ACTION.ordinal -> this.action.type == null Tag.ACTION.ordinal -> this.action.type == null
Tag.AMOUNT.ordinal -> this.requiresAmount Tag.AMOUNT.ordinal -> this.requiresAmount

@ -431,6 +431,8 @@ class HandHistoryViewModel : ViewModel(), RowRepresentableDataSource, CardCentra
is ComputedAction -> { is ComputedAction -> {
amount?.let { amount?.let {
this.sortedActions.setAmount(this.actionIndexForSelection, amount) this.sortedActions.setAmount(this.actionIndexForSelection, amount)
} ?: run {
this.sortedActions.setAmount(this.actionIndexForSelection, this.handHistory.bigBlind ?: 0.0)
} }
} }
is PlayerSetupRow -> { is PlayerSetupRow -> {

Loading…
Cancel
Save