|
|
|
@ -121,7 +121,7 @@ class HHBuilder { |
|
|
|
fun availableActions(index: Int) : Set<Action.Type> { |
|
|
|
fun availableActions(index: Int) : Set<Action.Type> { |
|
|
|
|
|
|
|
|
|
|
|
val position = this.actionForIndex(index).position |
|
|
|
val position = this.actionForIndex(index).position |
|
|
|
val lastSignificantAction: ComputedAction? = getStreetLastSignificantAction(index) |
|
|
|
val lastSignificantAction: ComputedAction? = getStreetLastSignificantAction(index - 1) |
|
|
|
val lastUserAction: ComputedAction? = getLastUserAction(index) |
|
|
|
val lastUserAction: ComputedAction? = getLastUserAction(index) |
|
|
|
|
|
|
|
|
|
|
|
return if (lastSignificantAction != null) { |
|
|
|
return if (lastSignificantAction != null) { |
|
|
|
@ -182,7 +182,7 @@ class HHBuilder { |
|
|
|
|
|
|
|
|
|
|
|
// define allin type |
|
|
|
// define allin type |
|
|
|
if (type == Action.Type.UNDEFINED_ALLIN) { |
|
|
|
if (type == Action.Type.UNDEFINED_ALLIN) { |
|
|
|
val significant = getStreetLastSignificantAction(index) |
|
|
|
val significant = getStreetLastSignificantAction(index - 1) |
|
|
|
if (significant != null) { |
|
|
|
if (significant != null) { |
|
|
|
val betAmount = significant.action.amount |
|
|
|
val betAmount = significant.action.amount |
|
|
|
val remainingStack = computedAction.playerRemainingStack |
|
|
|
val remainingStack = computedAction.playerRemainingStack |
|
|
|
@ -214,7 +214,7 @@ class HHBuilder { |
|
|
|
// define action amounts if possible |
|
|
|
// define action amounts if possible |
|
|
|
when (type) { |
|
|
|
when (type) { |
|
|
|
Action.Type.CALL -> { |
|
|
|
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") |
|
|
|
?: 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") |
|
|
|
@ -237,7 +237,7 @@ class HHBuilder { |
|
|
|
val modifiedActions = mutableListOf<ComputedAction>() |
|
|
|
val modifiedActions = mutableListOf<ComputedAction>() |
|
|
|
getPreviousEmptyActions(index).forEach { |
|
|
|
getPreviousEmptyActions(index).forEach { |
|
|
|
modifiedActions.add(it) |
|
|
|
modifiedActions.add(it) |
|
|
|
val lastSignificant = getStreetLastSignificantAction(index) |
|
|
|
val lastSignificant = getStreetLastSignificantAction(index - 1) |
|
|
|
it.action.type = if (lastSignificant != null) { |
|
|
|
it.action.type = if (lastSignificant != null) { |
|
|
|
Action.Type.FOLD |
|
|
|
Action.Type.FOLD |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
@ -260,9 +260,11 @@ class HHBuilder { |
|
|
|
val computedAction = this.actionForIndex(index) |
|
|
|
val computedAction = this.actionForIndex(index) |
|
|
|
val type = computedAction.action.type |
|
|
|
val type = computedAction.action.type |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
val f = addsFollowupActionsIfNecessary(index) |
|
|
|
return when (type?.isSignificant) { |
|
|
|
return when (type?.isSignificant) { |
|
|
|
true -> { // opens the action and requires action from other |
|
|
|
true -> { // opens the action and requires action from other |
|
|
|
addsFollowupActionsIfNecessary(index) |
|
|
|
// addsFollowupActionsIfNecessary(index) |
|
|
|
|
|
|
|
f |
|
|
|
} |
|
|
|
} |
|
|
|
false -> { // closes the action, pass to next street if necessary |
|
|
|
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 |
|
|
|
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 |
|
|
|
* Returns true if actions have been added |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
private fun addsFollowupActionsIfNecessary(index: Int) : Boolean { |
|
|
|
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) |
|
|
|
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 [refIndex] |
|
|
|
for (i in index + 1 until this.sortedActions.size) { |
|
|
|
for (i in refIndex + 1 until this.sortedActions.size) { |
|
|
|
val ca = this.actionForIndex(i) |
|
|
|
val ca = this.actionForIndex(i) |
|
|
|
activePositions.remove(ca.position) |
|
|
|
activePositions.remove(ca.position) |
|
|
|
} |
|
|
|
} |
|
|
|
@ -304,8 +309,9 @@ class HHBuilder { |
|
|
|
val firstPositionAfterCurrent = max(0, activePositions.indexOfFirst { it.ordinal > indexPosition.ordinal }) |
|
|
|
val firstPositionAfterCurrent = max(0, activePositions.indexOfFirst { it.ordinal > indexPosition.ordinal }) |
|
|
|
for (i in 0 until activePositions.size) { |
|
|
|
for (i in 0 until activePositions.size) { |
|
|
|
val position = activePositions[(firstPositionAfterCurrent + i) % 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() |
|
|
|
return activePositions.isNotEmpty() |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -419,7 +425,9 @@ class HHBuilder { |
|
|
|
else -> activePositions.size |
|
|
|
else -> activePositions.size |
|
|
|
} |
|
|
|
} |
|
|
|
val sizeBefore = this.sortedActions.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() |
|
|
|
this.createRowRepresentation() |
|
|
|
val sizeAfter = this.sortedActions.size |
|
|
|
val sizeAfter = this.sortedActions.size |
|
|
|
|
|
|
|
|
|
|
|
@ -449,7 +457,7 @@ class HHBuilder { |
|
|
|
// verify if the raise is not a call after all |
|
|
|
// verify if the raise is not a call after all |
|
|
|
if (computedAction.action.type == Action.Type.RAISE_ALLIN) { |
|
|
|
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 |
|
|
|
val askedAmount = significantActionAmount - committedAmount |
|
|
|
|
|
|
|
|
|
|
|
computedAction.playerRemainingStack?.let { remainingStack -> |
|
|
|
computedAction.playerRemainingStack?.let { remainingStack -> |
|
|
|
@ -525,7 +533,7 @@ class HHBuilder { |
|
|
|
private fun getStreetLastSignificantAction(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 + 1).filter { it.action.street == street } |
|
|
|
// Timber.d("**** this.sortedActions.size = ${this.sortedActions.size}") |
|
|
|
// Timber.d("**** this.sortedActions.size = ${this.sortedActions.size}") |
|
|
|
return previousActions.lastOrNull { it.action.isActionSignificant } |
|
|
|
return previousActions.lastOrNull { it.action.isActionSignificant } |
|
|
|
} |
|
|
|
} |
|
|
|
|