|
|
|
@ -15,12 +15,23 @@ class Builder { |
|
|
|
load() |
|
|
|
load() |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*** |
|
|
|
|
|
|
|
* 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 val sortedActions: List<ComputedAction> |
|
|
|
private val sortedActions: List<ComputedAction> |
|
|
|
get() { |
|
|
|
get() { |
|
|
|
return actionsPerStreet.flatMap { it.value } |
|
|
|
return actionsPerStreet.flatMap { it.value } |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*** |
|
|
|
|
|
|
|
* Creates a builder using a [handSetup] |
|
|
|
|
|
|
|
* Creates a new Hand History and configures it according to the [handSetup] |
|
|
|
|
|
|
|
*/ |
|
|
|
constructor(handSetup: HandSetup) { |
|
|
|
constructor(handSetup: HandSetup) { |
|
|
|
val handHistory = HandHistory() |
|
|
|
val handHistory = HandHistory() |
|
|
|
handHistory.configure(handSetup) |
|
|
|
handHistory.configure(handSetup) |
|
|
|
@ -28,10 +39,17 @@ class Builder { |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*** |
|
|
|
|
|
|
|
* Creates a builder using the parameter [handHistory] |
|
|
|
|
|
|
|
*/ |
|
|
|
constructor(handHistory: HandHistory) { |
|
|
|
constructor(handHistory: HandHistory) { |
|
|
|
this.handHistory = handHistory |
|
|
|
this.handHistory = handHistory |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*** |
|
|
|
|
|
|
|
* Fills the [actionsPerStreet] variable with the proper actions |
|
|
|
|
|
|
|
* Pre-computes the potsizes for the video export |
|
|
|
|
|
|
|
*/ |
|
|
|
private fun load() { |
|
|
|
private fun load() { |
|
|
|
|
|
|
|
|
|
|
|
var potSize = 0.0 |
|
|
|
var potSize = 0.0 |
|
|
|
@ -55,6 +73,9 @@ class Builder { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*** |
|
|
|
|
|
|
|
* Returns the list of available user actions at [index] |
|
|
|
|
|
|
|
*/ |
|
|
|
private fun availableActions(index: Int) : Set<Action.Type> { |
|
|
|
private fun availableActions(index: Int) : Set<Action.Type> { |
|
|
|
|
|
|
|
|
|
|
|
val lastSignificantAction: ComputedAction? = getLastSignificantAction(index) |
|
|
|
val lastSignificantAction: ComputedAction? = getLastSignificantAction(index) |
|
|
|
@ -79,7 +100,7 @@ class Builder { |
|
|
|
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 (this.remainingPlayerCount == 2 && remainingStack != null && actionAmount != null && remainingStack > actionAmount) { |
|
|
|
} else if (this.remainingPlayerCount(index) == 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.RAISE_ALLIN) |
|
|
|
setOf(Action.Type.FOLD, Action.Type.CALL, Action.Type.RAISE, Action.Type.RAISE_ALLIN) |
|
|
|
@ -96,19 +117,32 @@ class Builder { |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private val remainingPlayerCount: Int |
|
|
|
/*** |
|
|
|
get() { |
|
|
|
* Returns the remaining player count at the provided [index] |
|
|
|
return 0 // TODO |
|
|
|
*/ |
|
|
|
} |
|
|
|
private fun remainingPlayerCount(index: Int): Int { |
|
|
|
|
|
|
|
return 0 |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*** |
|
|
|
|
|
|
|
* 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 |
|
|
|
|
|
|
|
*/ |
|
|
|
private fun selectAction(index: Int, actionType: Action.Type) { |
|
|
|
private fun selectAction(index: Int, actionType: Action.Type) { |
|
|
|
// remove everything after |
|
|
|
// if the selected action is different from current, remove any action after the index |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*** |
|
|
|
|
|
|
|
* Sets the amount for the action at the provided [index] |
|
|
|
|
|
|
|
*/ |
|
|
|
private fun setAmount(index: Int, amount: Double) { |
|
|
|
private fun setAmount(index: Int, amount: Double) { |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*** |
|
|
|
|
|
|
|
* Returns the last user action, if any, for the action at the provided [index] |
|
|
|
|
|
|
|
*/ |
|
|
|
private fun getLastUserAction(index: Int): ComputedAction? { |
|
|
|
private fun getLastUserAction(index: Int): ComputedAction? { |
|
|
|
val computedAction = this.sortedActions.first { it.action.index == index } |
|
|
|
val computedAction = this.sortedActions.first { it.action.index == index } |
|
|
|
val action = computedAction.action |
|
|
|
val action = computedAction.action |
|
|
|
@ -117,11 +151,17 @@ class Builder { |
|
|
|
return previousActions.lastOrNull { it.action.position == action.position } |
|
|
|
return previousActions.lastOrNull { it.action.position == action.position } |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*** |
|
|
|
|
|
|
|
* Returns the last significant player action, if any, for the action at the provided [index] |
|
|
|
|
|
|
|
*/ |
|
|
|
private fun getLastSignificantAction(index: Int): ComputedAction? { |
|
|
|
private fun getLastSignificantAction(index: Int): ComputedAction? { |
|
|
|
val previousActions = this.sortedActions.drop(index) |
|
|
|
val previousActions = this.sortedActions.drop(index) |
|
|
|
return previousActions.lastOrNull { it.action.isActionSignificant } |
|
|
|
return previousActions.lastOrNull { it.action.isActionSignificant } |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*** |
|
|
|
|
|
|
|
* Saves the current hand state, represented by [actionsPerStreet], in the database |
|
|
|
|
|
|
|
*/ |
|
|
|
private fun save() { |
|
|
|
private fun save() { |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|