From 42001c8f0de4e8384949eec974e4c986de59aa2f Mon Sep 17 00:00:00 2001 From: Laurent Date: Mon, 13 Jan 2020 17:39:00 +0100 Subject: [PATCH] Refactoring + todos --- .../android/model/handhistory/HHBuilder.kt | 33 ++++++++++++------- 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/app/src/main/java/net/pokeranalytics/android/model/handhistory/HHBuilder.kt b/app/src/main/java/net/pokeranalytics/android/model/handhistory/HHBuilder.kt index 58495327..c29a249b 100644 --- a/app/src/main/java/net/pokeranalytics/android/model/handhistory/HHBuilder.kt +++ b/app/src/main/java/net/pokeranalytics/android/model/handhistory/HHBuilder.kt @@ -46,6 +46,14 @@ class HHBuilder { this.handHistory = handHistory } + /*** + * Returns the action + */ + private fun actionForIndex(index: Int) : ComputedAction { + return this.sortedActions[index] +// return this.sortedActions.first { it.action.index == index } + } + /*** * Fills the [actionsPerStreet] variable with the proper actions * Pre-computes the potsizes for the video export @@ -129,7 +137,7 @@ class HHBuilder { * Returns the remaining player count at the provided [index] */ private fun remainingPlayerCount(index: Int): Int { - return 0 + return 0 // TODO } /*** @@ -140,11 +148,13 @@ class HHBuilder { */ private fun selectAction(index: Int, actionType: Action.Type) : Boolean { - val computedAction = this.sortedActions.first { it.action.index == index } + val computedAction = this.actionForIndex(index) computedAction.action.type = actionType dropNextActionsIfNecessary(index) + // TODO si on set une action et que les actions precedentes ne sont pas renseignees, on fold PF ou check apres + when (actionType) { Action.Type.CALL -> { val significantAmount = getLastSignificantAction(index)?.action?.amount ?: throw PAIllegalStateException("Cannot happen") @@ -164,13 +174,12 @@ class HHBuilder { } /*** - * Removes the actions, if necessary, following a action change - * We only want to keep the first set of actions whatever happens + * Removes the actions, if necessary, following an action change + * We want drop all non-auto added rows after the index */ private fun dropNextActionsIfNecessary(index: Int) { - if (index > this.handHistory.numberOfPlayers) { - this.sortedActions.drop(index + 1) - } + val dropIndex = index + 1 // TODO determine dropIndex + this.sortedActions.drop(dropIndex) } /*** @@ -178,11 +187,13 @@ class HHBuilder { * 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 computedAction = this.actionForIndex(index) val revisedAmount = computedAction.playerRemainingStack?.let { min(it, amount) } ?: amount computedAction.action.amount = revisedAmount + // TODO si on change un montant de mise, on change les calls suivants + when (computedAction.action.type) { Action.Type.UNDEFINED_ALLIN -> { getLastSignificantAction(index)?.action?.amount?.let { significantActionAmount -> @@ -215,7 +226,7 @@ class HHBuilder { * Returns the committed amount by the player for the street at the current [index] */ private fun getPreviousCommittedAmount(index: Int) : Double? { - val action = this.sortedActions.first { it.action.index == index }.action + val action = this.actionForIndex(index).action val position = action.position val street = action.street @@ -240,9 +251,7 @@ class HHBuilder { * 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 - + val action = this.actionForIndex(index).action val previousActions = this.sortedActions.drop(index) return previousActions.lastOrNull { it.action.position == action.position } }