|
|
|
@ -1,5 +1,7 @@ |
|
|
|
package net.pokeranalytics.android.model.handhistory |
|
|
|
package net.pokeranalytics.android.model.handhistory |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import net.pokeranalytics.android.exceptions.PAIllegalStateException |
|
|
|
|
|
|
|
import net.pokeranalytics.android.model.realm.handhistory.Action |
|
|
|
import net.pokeranalytics.android.model.realm.handhistory.HandHistory |
|
|
|
import net.pokeranalytics.android.model.realm.handhistory.HandHistory |
|
|
|
|
|
|
|
|
|
|
|
class Builder { |
|
|
|
class Builder { |
|
|
|
@ -13,7 +15,11 @@ class Builder { |
|
|
|
load() |
|
|
|
load() |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
val actionsPerStreet = hashMapOf<Street, List<ComputedAction>>() |
|
|
|
private val actionsPerStreet = hashMapOf<Street, List<ComputedAction>>() |
|
|
|
|
|
|
|
private val sortedActions: List<ComputedAction> |
|
|
|
|
|
|
|
get() { |
|
|
|
|
|
|
|
return actionsPerStreet.flatMap { it.value } |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
constructor(handSetup: HandSetup) { |
|
|
|
constructor(handSetup: HandSetup) { |
|
|
|
val handHistory = HandHistory() |
|
|
|
val handHistory = HandHistory() |
|
|
|
@ -42,12 +48,59 @@ class Builder { |
|
|
|
val filteredActions = sortedActions.filter { it.street == street.ordinal } |
|
|
|
val filteredActions = sortedActions.filter { it.street == street.ordinal } |
|
|
|
val computedActions = filteredActions.map { action -> |
|
|
|
val computedActions = filteredActions.map { action -> |
|
|
|
totalPotSize += action.effectiveAmount |
|
|
|
totalPotSize += action.effectiveAmount |
|
|
|
ComputedAction(action, potSize, action.positionRemainingStack) |
|
|
|
ComputedAction(action, potSize, totalPotSize, action.positionRemainingStack) |
|
|
|
} |
|
|
|
} |
|
|
|
this.actionsPerStreet[street] = computedActions |
|
|
|
this.actionsPerStreet[street] = computedActions |
|
|
|
potSize = totalPotSize |
|
|
|
potSize = totalPotSize |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private fun availableActions(index: Int) : Set<Action.Type> { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
val lastSignificantAction: ComputedAction? = getLastSignificantAction(index) |
|
|
|
|
|
|
|
val lastUserAction: ComputedAction? = getLastUserAction(index) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return if (lastSignificantAction != null) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
when (lastSignificantAction.action.type) { |
|
|
|
|
|
|
|
Action.Type.POST_BB, Action.Type.STRADDLE -> setOf(Action.Type.STRADDLE, Action.Type.FOLD, Action.Type.CALL, Action.Type.BET, Action.Type.BET_ALLIN) |
|
|
|
|
|
|
|
Action.Type.BET, Action.Type.RAISE, Action.Type.RAISE_ALLIN, Action.Type.BET_ALLIN -> { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
val remainingStack = lastUserAction?.playerRemainingStack |
|
|
|
|
|
|
|
val actionAmount = lastSignificantAction.action.amount |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (remainingStack != null && actionAmount != null && remainingStack <= actionAmount) { |
|
|
|
|
|
|
|
setOf(Action.Type.FOLD, Action.Type.CALL_ALLIN) |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
setOf(Action.Type.FOLD, Action.Type.CALL, Action.Type.RAISE, Action.Type.RAISE_ALLIN) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else -> { |
|
|
|
|
|
|
|
throw PAIllegalStateException("We should not handle this action: ${lastSignificantAction.action.type}") |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
setOf(Action.Type.CHECK, Action.Type.BET, Action.Type.BET_ALLIN) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private fun selectAction(index: Int, actionType: Action.Type) { |
|
|
|
|
|
|
|
// remove everything after |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private fun getLastUserAction(index: Int): ComputedAction? { |
|
|
|
|
|
|
|
val computedAction = this.sortedActions.first { it.action.index == index } |
|
|
|
|
|
|
|
val action = computedAction.action |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
val previousActions = this.sortedActions.drop(index) |
|
|
|
|
|
|
|
return previousActions.lastOrNull { it.action.position == action.position } |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private fun getLastSignificantAction(index: Int): ComputedAction? { |
|
|
|
|
|
|
|
val previousActions = this.sortedActions.drop(index) |
|
|
|
|
|
|
|
return previousActions.lastOrNull { it.action.isActionSignificant } |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private fun save() { |
|
|
|
private fun save() { |
|
|
|
|