diff --git a/app/src/main/java/net/pokeranalytics/android/model/handhistory/ComputedAction.kt b/app/src/main/java/net/pokeranalytics/android/model/handhistory/ComputedAction.kt index 0c505e7f..a308a081 100644 --- a/app/src/main/java/net/pokeranalytics/android/model/handhistory/ComputedAction.kt +++ b/app/src/main/java/net/pokeranalytics/android/model/handhistory/ComputedAction.kt @@ -1,5 +1,6 @@ package net.pokeranalytics.android.model.handhistory +import net.pokeranalytics.android.exceptions.PAIllegalStateException import net.pokeranalytics.android.model.realm.handhistory.Action import net.pokeranalytics.android.ui.modules.handhistory.HHKeyboard import net.pokeranalytics.android.ui.modules.handhistory.HandRowType @@ -63,6 +64,11 @@ class ComputedAction(var action: Action, * Also calculates the player remaining stack if possible */ fun setEffectiveAmount(amount: Double) { + + if (amount <= 0.0) { + throw PAIllegalStateException("Something probably went wrong somewhere, attempting to make a call of $amount") + } + val oldEffective = this.action.effectiveAmount this.action.effectiveAmount = amount @@ -78,13 +84,6 @@ class ComputedAction(var action: Action, } } - /*** - * 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}") return if (this.action.type != null) { @@ -108,8 +107,6 @@ class ComputedAction(var action: Action, Action.Type.POST_SB, Action.Type.POST_BB -> false else -> true } -// Timber.d("Can be edited = $actionCanBeEdited, action = ${this.action.type}, pure index = ${this.action.index}") -// return actionCanBeEdited } /*** diff --git a/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/HHBuilder.kt b/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/HHBuilder.kt index cec3d871..1cfa7dc9 100644 --- a/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/HHBuilder.kt +++ b/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/HHBuilder.kt @@ -121,7 +121,7 @@ class HHBuilder { fun availableActions(index: Int) : Set { val position = this.actionForIndex(index).position - val lastSignificantAction: ComputedAction? = getStreetLastSignificantAction(index) + val lastSignificantAction: ComputedAction? = getStreetLastSignificantAction(index - 1) val lastUserAction: ComputedAction? = getLastUserAction(index) return if (lastSignificantAction != null) { @@ -182,7 +182,7 @@ class HHBuilder { // define allin type if (type == Action.Type.UNDEFINED_ALLIN) { - val significant = getStreetLastSignificantAction(index) + val significant = getStreetLastSignificantAction(index - 1) if (significant != null) { val betAmount = significant.action.amount val remainingStack = computedAction.playerRemainingStack @@ -214,7 +214,7 @@ class HHBuilder { // define action amounts if possible when (type) { Action.Type.CALL -> { - val significantAction = getStreetLastSignificantAction(index) + val significantAction = getStreetLastSignificantAction(index - 1) ?: 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") @@ -237,7 +237,7 @@ class HHBuilder { val modifiedActions = mutableListOf() getPreviousEmptyActions(index).forEach { modifiedActions.add(it) - val lastSignificant = getStreetLastSignificantAction(index) + val lastSignificant = getStreetLastSignificantAction(index - 1) it.action.type = if (lastSignificant != null) { Action.Type.FOLD } else { @@ -260,9 +260,11 @@ class HHBuilder { val computedAction = this.actionForIndex(index) val type = computedAction.action.type + val f = addsFollowupActionsIfNecessary(index) return when (type?.isSignificant) { true -> { // opens the action and requires action from other - addsFollowupActionsIfNecessary(index) +// addsFollowupActionsIfNecessary(index) + f } false -> { // closes the action, pass to next street if necessary if (type == Action.Type.CALL_ALLIN) { // sometimes we can go from RAISE_ALLIN to CALL_IN, changing the actions required @@ -288,14 +290,17 @@ class HHBuilder { * Returns true if actions have been added */ private fun addsFollowupActionsIfNecessary(index: Int) : Boolean { - val computedAction = this.actionForIndex(index) - val indexPosition = computedAction.position - val activePositions = activePositions(index) + val refAction = getStreetLastSignificantAction(index) ?: this.actionForIndex(index) + val refIndex = refAction.action.index + + val indexPosition = refAction.position + + val activePositions = activePositions(refIndex) activePositions.remove(indexPosition) - // We want to remove positions that already have an action after [index] - for (i in index + 1 until this.sortedActions.size) { + // We want to remove positions that already have an action after [refIndex] + for (i in refIndex + 1 until this.sortedActions.size) { val ca = this.actionForIndex(i) activePositions.remove(ca.position) } @@ -304,8 +309,9 @@ class HHBuilder { val firstPositionAfterCurrent = max(0, activePositions.indexOfFirst { it.ordinal > indexPosition.ordinal }) for (i in 0 until activePositions.size) { val position = activePositions[(firstPositionAfterCurrent + i) % activePositions.size] - this.addNewEmptyAction(position, computedAction.action.street, computedAction.totalPotSize, lastRemainingStack(position, index)) + this.addNewEmptyAction(position, refAction.action.street, refAction.totalPotSize, lastRemainingStack(position, index)) } + return activePositions.isNotEmpty() } @@ -419,7 +425,9 @@ class HHBuilder { else -> activePositions.size } val sizeBefore = this.sortedActions.size - this.sortedActions = this.sortedActions.take(index + defaultRowsCount).toMutableList() +// val keptRowsIndex = max(index, firstIndexOfStreet + defaultRowsCount) + this.sortedActions = this.sortedActions.take(index + 1).toMutableList() + this.updateFollowupActions(index) this.createRowRepresentation() val sizeAfter = this.sortedActions.size @@ -449,7 +457,7 @@ class HHBuilder { // verify if the raise is not a call after all if (computedAction.action.type == Action.Type.RAISE_ALLIN) { - getStreetLastSignificantAction(index)?.action?.amount?.let { significantActionAmount -> + getStreetLastSignificantAction(index - 1)?.action?.amount?.let { significantActionAmount -> val askedAmount = significantActionAmount - committedAmount computedAction.playerRemainingStack?.let { remainingStack -> @@ -525,7 +533,7 @@ class HHBuilder { private fun getStreetLastSignificantAction(index: Int): ComputedAction? { val street = this.actionForIndex(index).action.street // Timber.d("**** this.sortedActions.size = ${this.sortedActions.size}") - val previousActions = this.sortedActions.take(index).filter { it.action.street == street } + val previousActions = this.sortedActions.take(index + 1).filter { it.action.street == street } // Timber.d("**** this.sortedActions.size = ${this.sortedActions.size}") return previousActions.lastOrNull { it.action.isActionSignificant } }