Adds POT action

hh
Laurent 6 years ago
parent 057f15be55
commit 8dabd8931f
  1. 5
      app/src/main/java/net/pokeranalytics/android/model/realm/handhistory/Action.kt
  2. 19
      app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/model/ActionList.kt
  3. 10
      app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/model/ComputedAction.kt
  4. 5
      app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/model/HandHistoryViewModel.kt
  5. 7
      app/src/main/res/values/strings.xml

@ -43,6 +43,7 @@ open class Action : RealmObject() {
CHECK(R.string.check), CHECK(R.string.check),
CALL(R.string.call), CALL(R.string.call),
BET(R.string.bet), BET(R.string.bet),
POT(R.string.pot),
RAISE(R.string.raise), RAISE(R.string.raise),
UNDEFINED_ALLIN(R.string.allin), UNDEFINED_ALLIN(R.string.allin),
CALL_ALLIN(R.string.callin), CALL_ALLIN(R.string.callin),
@ -60,7 +61,7 @@ open class Action : RealmObject() {
val isSignificant: Boolean val isSignificant: Boolean
get() { get() {
return when (this) { return when (this) {
POST_SB, POST_BB, STRADDLE, BET, RAISE, BET_ALLIN, RAISE_ALLIN -> true POST_SB, POST_BB, STRADDLE, BET, POT, RAISE, BET_ALLIN, RAISE_ALLIN -> true
UNDEFINED_ALLIN -> throw PAIllegalStateException("Can't ask for UNDEFINED_ALLIN") UNDEFINED_ALLIN -> throw PAIllegalStateException("Can't ask for UNDEFINED_ALLIN")
else -> false else -> false
} }
@ -109,7 +110,7 @@ open class Action : RealmObject() {
companion object { companion object {
val defaultTypes: List<Type> by lazy { val defaultTypes: List<Type> by lazy {
listOf(FOLD, CHECK, BET, CALL, RAISE, UNDEFINED_ALLIN) listOf(FOLD, CHECK, BET, POT, CALL, RAISE, UNDEFINED_ALLIN)
} }
} }

@ -17,6 +17,7 @@ interface ActionManager {
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 fun minimumBetAmount(index: Int): Double
fun totalPotSize(index: Int): Double
} }
interface ActionListListener : PlayerSetupCreationListener { interface ActionListListener : PlayerSetupCreationListener {
@ -170,7 +171,7 @@ class ActionList(var listener: ActionListListener) : ArrayList<ComputedAction>()
val lastSignificantAction: ComputedAction? = getStreetLastSignificantAction(computedAction.street, index - 1) val lastSignificantAction: ComputedAction? = getStreetLastSignificantAction(computedAction.street, index - 1)
return if (lastSignificantAction == null) { return if (lastSignificantAction == null) {
setOf(Action.Type.FOLD, Action.Type.CHECK, Action.Type.BET, Action.Type.UNDEFINED_ALLIN) setOf(Action.Type.FOLD, Action.Type.CHECK, Action.Type.BET, Action.Type.POT, Action.Type.UNDEFINED_ALLIN)
} else { } else {
val remainingStack = getLastPlayerAction(index)?.playerRemainingStack val remainingStack = getLastPlayerAction(index)?.playerRemainingStack
val actionAmount = lastSignificantAction.action.amount val actionAmount = lastSignificantAction.action.amount
@ -178,16 +179,16 @@ class ActionList(var listener: ActionListListener) : ArrayList<ComputedAction>()
when (lastSignificantAction.action.type) { when (lastSignificantAction.action.type) {
Action.Type.POST_SB, Action.Type.POST_BB, Action.Type.STRADDLE -> { Action.Type.POST_SB, Action.Type.POST_BB, Action.Type.STRADDLE -> {
if (position == lastSignificantAction.position) { if (position == lastSignificantAction.position) {
setOf(Action.Type.FOLD, Action.Type.CHECK, Action.Type.BET, Action.Type.UNDEFINED_ALLIN) setOf(Action.Type.FOLD, Action.Type.CHECK, Action.Type.BET, Action.Type.POT, Action.Type.UNDEFINED_ALLIN)
} else { } else {
setOf(Action.Type.FOLD, Action.Type.CALL, Action.Type.BET, Action.Type.UNDEFINED_ALLIN) setOf(Action.Type.FOLD, Action.Type.CALL, Action.Type.BET, Action.Type.POT, Action.Type.UNDEFINED_ALLIN)
} }
} }
Action.Type.BET, Action.Type.RAISE -> { Action.Type.BET, Action.Type.POT, Action.Type.RAISE -> {
if (remainingStack != null && actionAmount != null && remainingStack <= actionAmount) { if (remainingStack != null && actionAmount != null && remainingStack <= actionAmount) {
setOf(Action.Type.FOLD, Action.Type.CALL_ALLIN) setOf(Action.Type.FOLD, Action.Type.CALL_ALLIN)
} else { } else {
setOf(Action.Type.FOLD, Action.Type.CALL, Action.Type.RAISE, Action.Type.UNDEFINED_ALLIN) setOf(Action.Type.FOLD, Action.Type.CALL, Action.Type.POT, Action.Type.RAISE, Action.Type.UNDEFINED_ALLIN)
} }
} }
Action.Type.RAISE_ALLIN, Action.Type.BET_ALLIN -> { Action.Type.RAISE_ALLIN, Action.Type.BET_ALLIN -> {
@ -196,11 +197,11 @@ class ActionList(var listener: ActionListListener) : ArrayList<ComputedAction>()
} else if (activePositions(index).size == 2 && remainingStack != null && actionAmount != null && remainingStack > actionAmount) { } else if (activePositions(index).size == 2 && remainingStack != null && actionAmount != null && remainingStack > actionAmount) {
setOf(Action.Type.FOLD, Action.Type.CALL) setOf(Action.Type.FOLD, Action.Type.CALL)
} else { } else {
setOf(Action.Type.FOLD, Action.Type.CALL, Action.Type.RAISE, Action.Type.UNDEFINED_ALLIN) setOf(Action.Type.FOLD, Action.Type.CALL, Action.Type.POT, Action.Type.RAISE, Action.Type.UNDEFINED_ALLIN)
} }
} }
else -> { else -> {
throw PAIllegalStateException("We should not handle this action: ${lastSignificantAction.action.type}") throw PAIllegalStateException("We do not handle this action: ${lastSignificantAction.action.type}")
} }
} }
} }
@ -551,6 +552,10 @@ class ActionList(var listener: ActionListListener) : ArrayList<ComputedAction>()
} }
} }
override fun totalPotSize(index: Int): Double {
return this.handHistory.anteSum + this.take(index).sumByDouble { it.action.effectiveAmount }
}
/*** /***
* Returns the next significant player action in the street, if any, for the action at the provided [index] * Returns the next significant player action in the street, if any, for the action at the provided [index]
*/ */

@ -78,8 +78,16 @@ class ComputedAction(var manager: ActionManager,
Action.Type.STRADDLE -> { Action.Type.STRADDLE -> {
// TODO // TODO
} }
Action.Type.POT -> {
val lastSignificantAction = this.getStreetLastSignificantAction()
val lastSignificantAmount = lastSignificantAction?.action?.amount ?: 0.0
val potAmount = lastSignificantAmount * 2 + this.manager.totalPotSize(this.action.index)
this.setAmount(potAmount)
}
Action.Type.BET_ALLIN, Action.Type.RAISE_ALLIN, Action.Type.UNDEFINED_ALLIN -> { Action.Type.BET_ALLIN, Action.Type.RAISE_ALLIN, Action.Type.UNDEFINED_ALLIN -> {
this.action.amount = this.playerRemainingStack this.playerRemainingStack?.let {
this.setAmount(it)
}
} }
else -> {} else -> {}
} }

@ -351,10 +351,13 @@ class HandHistoryViewModel : ViewModel(), RowRepresentableDataSource, CardCentra
} }
/***
* Returns the formatted pot size at the given [street]
*/
private fun formattedPotSizeForStreet(street: Street): String { private fun formattedPotSizeForStreet(street: Street): String {
val firstIndexOfStreet = this.sortedActions.firstOrNull { it.street == street }?.action?.index val firstIndexOfStreet = this.sortedActions.firstOrNull { it.street == street }?.action?.index
?: this.sortedActions.size ?: this.sortedActions.size
val potSize = this.handHistory.anteSum + this.sortedActions.take(firstIndexOfStreet).sumByDouble { it.action.effectiveAmount } val potSize = this.sortedActions.totalPotSize(firstIndexOfStreet)
return if (potSize > 0) potSize.formatted() else "" // "" required otherwise random values come up return if (potSize > 0) potSize.formatted() else "" // "" required otherwise random values come up
} }

@ -785,11 +785,12 @@
<string name="check">check</string> <string name="check">check</string>
<string name="call">call</string> <string name="call">call</string>
<string name="bet">bet</string> <string name="bet">bet</string>
<string name="pot">pot</string>
<string name="raise">raise</string> <string name="raise">raise</string>
<string name="allin">allin</string> <string name="allin">allin</string>
<string name="ballin">b_allin</string> <string name="ballin">allin</string>
<string name="callin">c_allin</string> <string name="callin">allin</string>
<string name="rallin">r_allin</string> <string name="rallin">allin</string>
<string name="backspace"></string> <string name="backspace"></string>
<string name="mississipi">mississipi</string> <string name="mississipi">mississipi</string>
<string name="set_hero_position">Hero position</string> <string name="set_hero_position">Hero position</string>

Loading…
Cancel
Save