|
|
|
@ -6,6 +6,7 @@ import net.pokeranalytics.android.model.realm.handhistory.Action |
|
|
|
import net.pokeranalytics.android.model.realm.handhistory.Card |
|
|
|
import net.pokeranalytics.android.model.realm.handhistory.Card |
|
|
|
import net.pokeranalytics.android.model.realm.handhistory.HandHistory |
|
|
|
import net.pokeranalytics.android.model.realm.handhistory.HandHistory |
|
|
|
import net.pokeranalytics.android.ui.modules.handhistory.HandRowType |
|
|
|
import net.pokeranalytics.android.ui.modules.handhistory.HandRowType |
|
|
|
|
|
|
|
import net.pokeranalytics.android.ui.modules.handhistory.views.PlayerCardsRow |
|
|
|
import net.pokeranalytics.android.ui.modules.handhistory.views.StreetCardView |
|
|
|
import net.pokeranalytics.android.ui.modules.handhistory.views.StreetCardView |
|
|
|
import net.pokeranalytics.android.ui.view.RowRepresentable |
|
|
|
import net.pokeranalytics.android.ui.view.RowRepresentable |
|
|
|
import net.pokeranalytics.android.ui.view.rowrepresentable.CustomizableRowRepresentable |
|
|
|
import net.pokeranalytics.android.ui.view.rowrepresentable.CustomizableRowRepresentable |
|
|
|
@ -100,7 +101,7 @@ class HHBuilder : BoardChangedListener { |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
private fun availableActions(index: Int) : Set<Action.Type> { |
|
|
|
private fun availableActions(index: Int) : Set<Action.Type> { |
|
|
|
|
|
|
|
|
|
|
|
val lastSignificantAction: ComputedAction? = getLastSignificantAction(index) |
|
|
|
val lastSignificantAction: ComputedAction? = getStreetLastSignificantAction(index) |
|
|
|
val lastUserAction: ComputedAction? = getLastUserAction(index) |
|
|
|
val lastUserAction: ComputedAction? = getLastUserAction(index) |
|
|
|
|
|
|
|
|
|
|
|
return if (lastSignificantAction != null) { |
|
|
|
return if (lastSignificantAction != null) { |
|
|
|
@ -122,7 +123,7 @@ class HHBuilder : BoardChangedListener { |
|
|
|
Action.Type.RAISE_ALLIN, Action.Type.BET_ALLIN -> { |
|
|
|
Action.Type.RAISE_ALLIN, Action.Type.BET_ALLIN -> { |
|
|
|
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 if (unfoldedPositions(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.RAISE, Action.Type.UNDEFINED_ALLIN) |
|
|
|
@ -160,7 +161,7 @@ class HHBuilder : BoardChangedListener { |
|
|
|
|
|
|
|
|
|
|
|
when (actionType) { |
|
|
|
when (actionType) { |
|
|
|
Action.Type.CALL -> { |
|
|
|
Action.Type.CALL -> { |
|
|
|
val significantAction = getLastSignificantAction(index) |
|
|
|
val significantAction = getStreetLastSignificantAction(index) |
|
|
|
?: throw PAIllegalStateException("There must be a previously set significant action for a call to be set") |
|
|
|
?: throw PAIllegalStateException("There must be a previously set significant action for a call to be set") |
|
|
|
val significantAmount = significantAction.action.amount |
|
|
|
val significantAmount = significantAction.action.amount |
|
|
|
?: throw PAIllegalStateException("There must be a set amount on the action for the call to be set") |
|
|
|
?: throw PAIllegalStateException("There must be a set amount on the action for the call to be set") |
|
|
|
@ -184,7 +185,7 @@ class HHBuilder : BoardChangedListener { |
|
|
|
val modifiedActions = mutableListOf<ComputedAction>() |
|
|
|
val modifiedActions = mutableListOf<ComputedAction>() |
|
|
|
getPreviousEmptyActions(index).forEach { |
|
|
|
getPreviousEmptyActions(index).forEach { |
|
|
|
modifiedActions.add(it) |
|
|
|
modifiedActions.add(it) |
|
|
|
val lastSignificant = getLastSignificantAction(index) |
|
|
|
val lastSignificant = getStreetLastSignificantAction(index) |
|
|
|
if (lastSignificant != null) { |
|
|
|
if (lastSignificant != null) { |
|
|
|
it.action.type = Action.Type.FOLD |
|
|
|
it.action.type = Action.Type.FOLD |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
@ -226,7 +227,7 @@ class HHBuilder : BoardChangedListener { |
|
|
|
val computedAction = this.actionForIndex(index) |
|
|
|
val computedAction = this.actionForIndex(index) |
|
|
|
val indexPosition = computedAction.position |
|
|
|
val indexPosition = computedAction.position |
|
|
|
|
|
|
|
|
|
|
|
val activePositions = unfoldedPositions(index) |
|
|
|
val activePositions = activePositions(index) |
|
|
|
activePositions.remove(indexPosition) |
|
|
|
activePositions.remove(indexPosition) |
|
|
|
|
|
|
|
|
|
|
|
// We want to remove positions that already have an action after [index] |
|
|
|
// We want to remove positions that already have an action after [index] |
|
|
|
@ -267,11 +268,13 @@ class HHBuilder : BoardChangedListener { |
|
|
|
/*** |
|
|
|
/*** |
|
|
|
* Returns the list of position still in play before the given [index] |
|
|
|
* Returns the list of position still in play before the given [index] |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
private fun unfoldedPositions(index: Int) : MutableList<Position> { |
|
|
|
private fun activePositions(index: Int) : MutableList<Position> { |
|
|
|
val folds = this.sortedActions.take(index).filter { it.action.type == Action.Type.FOLD } |
|
|
|
val oustedPositions = this.sortedActions.take(index + 1) |
|
|
|
|
|
|
|
.filter { it.action.type?.isPullOut ?: false } |
|
|
|
.map { it.position } |
|
|
|
.map { it.position } |
|
|
|
|
|
|
|
|
|
|
|
val allPositions = this.positions |
|
|
|
val allPositions = this.positions |
|
|
|
allPositions.removeAll(folds) |
|
|
|
allPositions.removeAll(oustedPositions) |
|
|
|
return allPositions.toMutableList() |
|
|
|
return allPositions.toMutableList() |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -280,37 +283,56 @@ class HHBuilder : BoardChangedListener { |
|
|
|
* Returns true if a street has been created |
|
|
|
* Returns true if a street has been created |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
private fun createNextStreetIfNecessary(index: Int) : Boolean { |
|
|
|
private fun createNextStreetIfNecessary(index: Int) : Boolean { |
|
|
|
val computedAction = this.actionForIndex(index) |
|
|
|
|
|
|
|
val currentStreet = this.actionForIndex(index).action.street // TODO is it useful? |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
getLastSignificantAction(index)?.let { significantAction -> |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
val activePositions = unfoldedPositions(index) |
|
|
|
val nextStreet = isStreetActionClosed(index) |
|
|
|
val activePlayerCount = activePositions.size // don't move this line because of removes |
|
|
|
if (nextStreet != null) { |
|
|
|
|
|
|
|
createStreet(nextStreet) |
|
|
|
activePositions.remove(significantAction.position) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
val significantIndex = significantAction.action.index |
|
|
|
|
|
|
|
for (i in significantIndex + 1 until this.sortedActions.size) { |
|
|
|
|
|
|
|
val ca = this.sortedActions[i] |
|
|
|
|
|
|
|
val type = ca.action.type |
|
|
|
|
|
|
|
if (type != null && !type.isSignificant) { // Calls and folds |
|
|
|
|
|
|
|
activePositions.remove(ca.position) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (activePositions.isEmpty()) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (activePlayerCount >= 2) { |
|
|
|
|
|
|
|
createStreet(currentStreet.next) |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
createStreet(Street.SUMMARY) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return true |
|
|
|
return true |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return false |
|
|
|
return false |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// val computedAction = this.actionForIndex(index) |
|
|
|
|
|
|
|
// val currentStreet = this.actionForIndex(index).action.street |
|
|
|
|
|
|
|
// |
|
|
|
|
|
|
|
// getStreetLastSignificantAction(index)?.let { significantAction -> |
|
|
|
|
|
|
|
// |
|
|
|
|
|
|
|
// val activePositions = activePositions(index) |
|
|
|
|
|
|
|
// val activePlayerCount = activePositions.size // don't move this line because of removes |
|
|
|
|
|
|
|
// |
|
|
|
|
|
|
|
// activePositions.remove(significantAction.position) |
|
|
|
|
|
|
|
// |
|
|
|
|
|
|
|
// val significantIndex = significantAction.action.index |
|
|
|
|
|
|
|
// for (i in significantIndex + 1 until this.sortedActions.size) { |
|
|
|
|
|
|
|
// val ca = this.sortedActions[i] |
|
|
|
|
|
|
|
// val type = ca.action.type |
|
|
|
|
|
|
|
// if (type != null && !type.isSignificant) { // Calls and folds |
|
|
|
|
|
|
|
// activePositions.remove(ca.position) |
|
|
|
|
|
|
|
// } |
|
|
|
|
|
|
|
// } |
|
|
|
|
|
|
|
// |
|
|
|
|
|
|
|
// if (activePositions.isEmpty()) { |
|
|
|
|
|
|
|
// |
|
|
|
|
|
|
|
// if (activePlayerCount >= 2 && currentStreet != Street.RIVER) { |
|
|
|
|
|
|
|
// createStreet(currentStreet.next) |
|
|
|
|
|
|
|
// } else { |
|
|
|
|
|
|
|
// createStreet(Street.SUMMARY) |
|
|
|
|
|
|
|
// } |
|
|
|
|
|
|
|
// return true |
|
|
|
|
|
|
|
// } |
|
|
|
|
|
|
|
// |
|
|
|
|
|
|
|
// } |
|
|
|
|
|
|
|
// |
|
|
|
|
|
|
|
// val allCheck = this.sortedActions.filter { it.action.street == currentStreet }.all { it.action.type == Action.Type.CHECK } |
|
|
|
|
|
|
|
// if (allCheck) { |
|
|
|
|
|
|
|
// if (currentStreet != Street.RIVER) { |
|
|
|
|
|
|
|
// createStreet(currentStreet.next) |
|
|
|
|
|
|
|
// } else { |
|
|
|
|
|
|
|
// createStreet(Street.SUMMARY) |
|
|
|
|
|
|
|
// } |
|
|
|
|
|
|
|
// return true |
|
|
|
|
|
|
|
// } |
|
|
|
|
|
|
|
// |
|
|
|
|
|
|
|
// return false |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/*** |
|
|
|
/*** |
|
|
|
@ -322,17 +344,25 @@ class HHBuilder : BoardChangedListener { |
|
|
|
private fun createStreet(street: Street) { |
|
|
|
private fun createStreet(street: Street) { |
|
|
|
|
|
|
|
|
|
|
|
val lastComputedAction = this.sortedActions.last() |
|
|
|
val lastComputedAction = this.sortedActions.last() |
|
|
|
val lastActionIndex = lastComputedAction.action.index |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
val totalPotSize = lastComputedAction.totalPotSize |
|
|
|
val totalPotSize = lastComputedAction.totalPotSize |
|
|
|
|
|
|
|
|
|
|
|
addStreetHeader(this.rowRepresentables, street, totalPotSize) |
|
|
|
addStreetHeader(this.rowRepresentables, street, totalPotSize) |
|
|
|
|
|
|
|
|
|
|
|
unfoldedPositions(lastActionIndex).sortedBy { it.ordinal }.forEach { |
|
|
|
val lastActionIndex = lastComputedAction.action.index |
|
|
|
|
|
|
|
activePositions(lastActionIndex).sortedBy { it.ordinal }.forEach { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
when (street) { |
|
|
|
|
|
|
|
Street.SUMMARY -> { |
|
|
|
|
|
|
|
this.rowRepresentables.add(PlayerCardsRow(it)) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else -> { |
|
|
|
addNewEmptyAction(it, street, totalPotSize, lastRemainingStack(it, lastActionIndex)) |
|
|
|
addNewEmptyAction(it, street, totalPotSize, lastRemainingStack(it, lastActionIndex)) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/*** |
|
|
|
/*** |
|
|
|
* Returns the list of empty actions before the action at the given [index] |
|
|
|
* Returns the list of empty actions before the action at the given [index] |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
@ -372,7 +402,7 @@ class HHBuilder : BoardChangedListener { |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
Action.Type.UNDEFINED_ALLIN -> { |
|
|
|
Action.Type.UNDEFINED_ALLIN -> { |
|
|
|
getLastSignificantAction(index)?.action?.amount?.let { significantActionAmount -> |
|
|
|
getStreetLastSignificantAction(index)?.action?.amount?.let { significantActionAmount -> |
|
|
|
|
|
|
|
|
|
|
|
val committedAmount = getPreviousCommittedAmount(index) ?: 0.0 |
|
|
|
val committedAmount = getPreviousCommittedAmount(index) ?: 0.0 |
|
|
|
val askedAmount = significantActionAmount - committedAmount |
|
|
|
val askedAmount = significantActionAmount - committedAmount |
|
|
|
@ -425,7 +455,7 @@ class HHBuilder : BoardChangedListener { |
|
|
|
|
|
|
|
|
|
|
|
return when (previousAction.type) { |
|
|
|
return when (previousAction.type) { |
|
|
|
Action.Type.POST_BB, Action.Type.POST_SB, Action.Type.STRADDLE, Action.Type.BET, Action.Type.RAISE -> previousAction.amount |
|
|
|
Action.Type.POST_BB, Action.Type.POST_SB, Action.Type.STRADDLE, Action.Type.BET, Action.Type.RAISE -> previousAction.amount |
|
|
|
Action.Type.CALL -> getLastSignificantAction(previousAction.index)?.action?.amount |
|
|
|
Action.Type.CALL -> getStreetLastSignificantAction(previousAction.index)?.action?.amount |
|
|
|
else -> null |
|
|
|
else -> null |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
@ -466,7 +496,7 @@ class HHBuilder : BoardChangedListener { |
|
|
|
/*** |
|
|
|
/*** |
|
|
|
* Returns the last significant player action, if any, for the action at the provided [index] |
|
|
|
* Returns the last significant player action, if any, for the action at the provided [index] |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
private fun getLastSignificantAction(index: Int): ComputedAction? { |
|
|
|
private fun getStreetLastSignificantAction(index: Int): ComputedAction? { |
|
|
|
val street = this.actionForIndex(index).action.street |
|
|
|
val street = this.actionForIndex(index).action.street |
|
|
|
Timber.d("**** this.sortedActions.size = ${this.sortedActions.size}") |
|
|
|
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).filter { it.action.street == street } |
|
|
|
@ -648,15 +678,29 @@ class HHBuilder : BoardChangedListener { |
|
|
|
|
|
|
|
|
|
|
|
val actions = this.sortedActions.filter { it.action.street == street } |
|
|
|
val actions = this.sortedActions.filter { it.action.street == street } |
|
|
|
|
|
|
|
|
|
|
|
if (actions.isNotEmpty()) { |
|
|
|
when (street) { |
|
|
|
|
|
|
|
Street.SUMMARY -> { |
|
|
|
|
|
|
|
val lastActionIndex = this.sortedActions.size - 1 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (activePositions(lastActionIndex).size < 2 || isStreetActionClosed(lastActionIndex) == Street.SUMMARY) { |
|
|
|
addStreetHeader(rows, street, potSize) |
|
|
|
addStreetHeader(rows, street, potSize) |
|
|
|
|
|
|
|
|
|
|
|
// Actions |
|
|
|
activePositions(lastActionIndex).forEach { |
|
|
|
|
|
|
|
val positionIndex = this.positions.indexOf(it) |
|
|
|
|
|
|
|
val playerCardsRow = PlayerCardsRow(it, this.handHistory.cardsForPosition(positionIndex)) |
|
|
|
|
|
|
|
this.rowRepresentables.add(playerCardsRow) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else -> { |
|
|
|
|
|
|
|
if (actions.isNotEmpty()) { |
|
|
|
|
|
|
|
addStreetHeader(rows, street, potSize) |
|
|
|
rows.addAll(actions) |
|
|
|
rows.addAll(actions) |
|
|
|
|
|
|
|
|
|
|
|
potSize = actions.last().totalPotSize |
|
|
|
potSize = actions.last().totalPotSize |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -664,6 +708,49 @@ class HHBuilder : BoardChangedListener { |
|
|
|
// return rows |
|
|
|
// return rows |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private fun isStreetActionClosed(index: Int) : Street? { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
val currentStreet = this.actionForIndex(index).action.street |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
getStreetLastSignificantAction(index)?.let { significantAction -> |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
val activePositions = activePositions(index) |
|
|
|
|
|
|
|
val activePlayerCount = activePositions.size // don't move this line because of removes |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
activePositions.remove(significantAction.position) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
val significantIndex = significantAction.action.index |
|
|
|
|
|
|
|
for (i in significantIndex + 1 until this.sortedActions.size) { |
|
|
|
|
|
|
|
val ca = this.sortedActions[i] |
|
|
|
|
|
|
|
val type = ca.action.type |
|
|
|
|
|
|
|
if (type != null && !type.isSignificant) { // Calls and folds |
|
|
|
|
|
|
|
activePositions.remove(ca.position) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (activePositions.isEmpty()) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return if (activePlayerCount >= 2 && currentStreet != Street.RIVER) { |
|
|
|
|
|
|
|
currentStreet.next |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
Street.SUMMARY |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
val allCheck = this.sortedActions.filter { it.action.street == currentStreet }.all { it.action.type == Action.Type.CHECK } |
|
|
|
|
|
|
|
if (allCheck) { |
|
|
|
|
|
|
|
return if (currentStreet != Street.RIVER) { |
|
|
|
|
|
|
|
currentStreet.next |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
Street.SUMMARY |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return null |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private fun addStreetHeader(rowRepresentables: MutableList<RowRepresentable>, street: Street, potSize: Double) { |
|
|
|
private fun addStreetHeader(rowRepresentables: MutableList<RowRepresentable>, street: Street, potSize: Double) { |
|
|
|
val headerView = CustomizableRowRepresentable(customViewType = HandRowType.HEADER, resId = street.resId) |
|
|
|
val headerView = CustomizableRowRepresentable(customViewType = HandRowType.HEADER, resId = street.resId) |
|
|
|
rowRepresentables.add(headerView) |
|
|
|
rowRepresentables.add(headerView) |
|
|
|
|