Adds algorithm to determine the user available actions

hh
Laurent 6 years ago
parent fb56773f64
commit b942c12d12
  1. 57
      app/src/main/java/net/pokeranalytics/android/model/handhistory/Builder.kt
  2. 1
      app/src/main/java/net/pokeranalytics/android/model/handhistory/ComputedAction.kt
  3. 24
      app/src/main/java/net/pokeranalytics/android/model/realm/handhistory/Action.kt
  4. 4
      app/src/main/java/net/pokeranalytics/android/model/realm/handhistory/HandHistory.kt

@ -1,5 +1,7 @@
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
class Builder {
@ -13,7 +15,11 @@ class Builder {
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) {
val handHistory = HandHistory()
@ -42,12 +48,59 @@ class Builder {
val filteredActions = sortedActions.filter { it.street == street.ordinal }
val computedActions = filteredActions.map { action ->
totalPotSize += action.effectiveAmount
ComputedAction(action, potSize, action.positionRemainingStack)
ComputedAction(action, potSize, totalPotSize, action.positionRemainingStack)
}
this.actionsPerStreet[street] = computedActions
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() {

@ -4,6 +4,7 @@ import net.pokeranalytics.android.model.realm.handhistory.Action
class ComputedAction(var action: Action,
var potSize: Double = 0.0,
var totalPotSize: Double = 0.0,
var playerRemainingStack: Double? = null) {
/***

@ -7,13 +7,23 @@ open class Action : RealmObject() {
enum class Type {
POST_SB,
POST_BB,
STRADDLE,
FOLD,
CHECK,
CALL,
BET,
RAISE,
CALL_ALLIN,
BET_ALLIN,
RAISE_ALLIN
RAISE_ALLIN;
val isSignificant: Boolean
get() {
return when (this) {
POST_BB, STRADDLE, BET, RAISE, BET_ALLIN, RAISE_ALLIN -> true
else -> false
}
}
}
/***
@ -34,7 +44,12 @@ open class Action : RealmObject() {
/***
* The type of action: check, fold, raise...
*/
var type: Int? = null
var typeIdentifier: Int? = null
val type: Type?
get() {
return typeIdentifier?.let { Type.values()[it] }
}
/***
* The amount linked for a bet, raise...
@ -46,4 +61,9 @@ open class Action : RealmObject() {
var positionRemainingStack: Double? = null
val isActionSignificant: Boolean
get() {
return this.type?.isSignificant ?: false
}
}

@ -85,11 +85,11 @@ open class HandHistory : RealmObject() {
action.position = i
when (i) {
0 -> {
action.type = Action.Type.POST_SB.ordinal
action.typeIdentifier = Action.Type.POST_SB.ordinal
action.amount = this.smallBlind
}
1 -> {
action.type = Action.Type.POST_BB.ordinal
action.typeIdentifier = Action.Type.POST_BB.ordinal
action.amount = this.bigBlind
}
else -> {

Loading…
Cancel
Save