|
|
|
|
@ -19,15 +19,12 @@ class Builder { |
|
|
|
|
/*** |
|
|
|
|
* The map containing all actions present in a street |
|
|
|
|
*/ |
|
|
|
|
private val actionsPerStreet = hashMapOf<Street, List<ComputedAction>>() |
|
|
|
|
// private val actionsPerStreet = hashMapOf<Street, List<ComputedAction>>() |
|
|
|
|
|
|
|
|
|
/*** |
|
|
|
|
* All actions sorted by index |
|
|
|
|
*/ |
|
|
|
|
private var sortedActions: List<ComputedAction> = listOf() |
|
|
|
|
// get() { |
|
|
|
|
// return actionsPerStreet.flatMap { it.value } |
|
|
|
|
// } |
|
|
|
|
private var sortedActions: List<ComputedAction> = mutableListOf() |
|
|
|
|
|
|
|
|
|
/*** |
|
|
|
|
* Creates a builder using a [handSetup] |
|
|
|
|
@ -137,9 +134,10 @@ class Builder { |
|
|
|
|
* Selects an action type for the action at the provided [index] |
|
|
|
|
* If the user changes the current action, |
|
|
|
|
* for convenience we remove all the following actions to avoid managing complex cases |
|
|
|
|
* Also calculates the player effective amounts in proper cases |
|
|
|
|
*/ |
|
|
|
|
private fun selectAction(index: Int, actionType: Action.Type) : Boolean { |
|
|
|
|
// if the selected action is different from current, remove any action after the index |
|
|
|
|
|
|
|
|
|
val computedAction = this.sortedActions.first { it.action.index == index } |
|
|
|
|
computedAction.action.type = actionType |
|
|
|
|
|
|
|
|
|
@ -157,11 +155,16 @@ class Builder { |
|
|
|
|
Action.Type.STRADDLE -> { |
|
|
|
|
// TODO |
|
|
|
|
} |
|
|
|
|
else -> {} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return computedAction.requireAmount |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/*** |
|
|
|
|
* Removes the actions, if necessary, following a action change |
|
|
|
|
* We only want to keep the first set of actions whatever happens |
|
|
|
|
*/ |
|
|
|
|
private fun dropNextActionsIfNecessary(index: Int) { |
|
|
|
|
if (index > this.handHistory.numberOfPlayers) { |
|
|
|
|
this.sortedActions.drop(index + 1) |
|
|
|
|
@ -170,12 +173,13 @@ class Builder { |
|
|
|
|
|
|
|
|
|
/*** |
|
|
|
|
* Sets the amount for the action at the provided [index] |
|
|
|
|
* In the case of an UNDEFINED_ALLIN, define if it's a RAISE_ALLIN or a CALL_ALLIN |
|
|
|
|
*/ |
|
|
|
|
private fun setAmount(index: Int, amount: Double) { |
|
|
|
|
val computedAction = this.sortedActions.first { it.action.index == index } |
|
|
|
|
|
|
|
|
|
val adjustedAmount = computedAction.playerRemainingStack?.let { min(it, amount) } ?: amount |
|
|
|
|
computedAction.action.amount = adjustedAmount |
|
|
|
|
val revisedAmount = computedAction.playerRemainingStack?.let { min(it, amount) } ?: amount |
|
|
|
|
computedAction.action.amount = revisedAmount |
|
|
|
|
|
|
|
|
|
when (computedAction.action.type) { |
|
|
|
|
Action.Type.UNDEFINED_ALLIN -> { |
|
|
|
|
@ -205,18 +209,24 @@ class Builder { |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/*** |
|
|
|
|
* Returns the committed amount by the player for the street at the current [index] |
|
|
|
|
*/ |
|
|
|
|
private fun getPreviousCommittedAmount(index: Int) : Double? { |
|
|
|
|
val computedAction = this.sortedActions.first { it.action.index == index } |
|
|
|
|
val position = computedAction.action.position |
|
|
|
|
val action = this.sortedActions.first { it.action.index == index }.action |
|
|
|
|
val position = action.position |
|
|
|
|
val street = action.street |
|
|
|
|
|
|
|
|
|
val previousActions = this.sortedActions.drop(index) |
|
|
|
|
val previousComputedAction = previousActions.lastOrNull { it.action.position == position } |
|
|
|
|
val previousComputedAction = previousActions.lastOrNull { |
|
|
|
|
it.action.position == position && it.action.street == street |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
previousComputedAction?.action?.let { action -> |
|
|
|
|
previousComputedAction?.action?.let { previousAction -> |
|
|
|
|
|
|
|
|
|
return when (action.type) { |
|
|
|
|
Action.Type.POST_BB, Action.Type.POST_SB, Action.Type.STRADDLE, Action.Type.BET, Action.Type.RAISE -> action.amount |
|
|
|
|
Action.Type.CALL -> getLastSignificantAction(action.index)?.action?.amount |
|
|
|
|
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.CALL -> getLastSignificantAction(previousAction.index)?.action?.amount |
|
|
|
|
else -> null |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|