diff --git a/app/src/main/java/net/pokeranalytics/android/model/handhistory/Builder.kt b/app/src/main/java/net/pokeranalytics/android/model/handhistory/Builder.kt index 24ad6a0f..f3397d02 100644 --- a/app/src/main/java/net/pokeranalytics/android/model/handhistory/Builder.kt +++ b/app/src/main/java/net/pokeranalytics/android/model/handhistory/Builder.kt @@ -15,12 +15,23 @@ class Builder { load() } + /*** + * The map containing all actions present in a street + */ private val actionsPerStreet = hashMapOf>() + + /*** + * All actions sorted by index + */ private val sortedActions: List get() { 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) { val handHistory = HandHistory() handHistory.configure(handSetup) @@ -28,10 +39,17 @@ class Builder { } + /*** + * Creates a builder using the parameter [handHistory] + */ constructor(handHistory: HandHistory) { this.handHistory = handHistory } + /*** + * Fills the [actionsPerStreet] variable with the proper actions + * Pre-computes the potsizes for the video export + */ private fun load() { 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 { val lastSignificantAction: ComputedAction? = getLastSignificantAction(index) @@ -79,7 +100,7 @@ class Builder { Action.Type.RAISE_ALLIN, Action.Type.BET_ALLIN -> { if (remainingStack != null && actionAmount != null && remainingStack <= actionAmount) { 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) } else { 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() { - return 0 // TODO - } + /*** + * Returns the remaining player count at the provided [index] + */ + 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) { - // 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) { } + /*** + * Returns the last user action, if any, for the action at the provided [index] + */ private fun getLastUserAction(index: Int): ComputedAction? { val computedAction = this.sortedActions.first { it.action.index == index } val action = computedAction.action @@ -117,11 +151,17 @@ class Builder { 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? { val previousActions = this.sortedActions.drop(index) return previousActions.lastOrNull { it.action.isActionSignificant } } + /*** + * Saves the current hand state, represented by [actionsPerStreet], in the database + */ private fun save() { }