From ef362bfa283f292cab4392e33b953966eeab5595 Mon Sep 17 00:00:00 2001 From: Laurent Date: Wed, 8 Jan 2020 16:38:59 +0100 Subject: [PATCH] Added creation of new hand, building of actions per street --- .../android/model/handhistory/Builder.kt | 27 ++- .../model/handhistory/ComputedAction.kt | 2 +- .../android/model/handhistory/HandSetup.kt | 15 ++ .../android/model/handhistory/Street.kt | 9 + .../android/model/realm/handhistory/Action.kt | 19 ++- .../model/realm/handhistory/HandHistory.kt | 154 +++++++++++------- 6 files changed, 155 insertions(+), 71 deletions(-) create mode 100644 app/src/main/java/net/pokeranalytics/android/model/handhistory/HandSetup.kt create mode 100644 app/src/main/java/net/pokeranalytics/android/model/handhistory/Street.kt 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 a0e11180..2d5fc8c0 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 @@ -13,10 +13,13 @@ class Builder { load() } - val actions: List = listOf() + val actionsPerStreet = hashMapOf>() + + constructor(handSetup: HandSetup) { + val handHistory = HandHistory() + handHistory.configure(handSetup) + this.handHistory = handHistory - constructor() { - this.handHistory = HandHistory() } constructor(handHistory: HandHistory) { @@ -26,11 +29,23 @@ class Builder { private fun load() { var potSize = 0.0 + var totalPotSize = 0.0 - // sorted actions - this.handHistory.actions.forEach { + // on veut sortir: + // une liste d'action pour générer des images / des animations => ImageRepresentable? + // une liste de lignes à afficher dans un tableau => RowRepresentable + // => ne pas oublier flop / turn / river / résumé - val computedAction = ComputedAction(it, potSize, 0.0) + // sorted actions + val sortedActions = this.handHistory.actions.sortedBy { it.index } + Street.values().forEach { street -> + val filteredActions = sortedActions.filter { it.street == street.ordinal } + val computedActions = filteredActions.map { action -> + totalPotSize += action.effectiveAmount + ComputedAction(action, potSize, action.positionRemainingStack) + } + this.actionsPerStreet[street] = computedActions + potSize = totalPotSize } } diff --git a/app/src/main/java/net/pokeranalytics/android/model/handhistory/ComputedAction.kt b/app/src/main/java/net/pokeranalytics/android/model/handhistory/ComputedAction.kt index b68dfc4e..9c8cdb69 100644 --- a/app/src/main/java/net/pokeranalytics/android/model/handhistory/ComputedAction.kt +++ b/app/src/main/java/net/pokeranalytics/android/model/handhistory/ComputedAction.kt @@ -4,7 +4,7 @@ import net.pokeranalytics.android.model.realm.handhistory.Action class ComputedAction(var action: Action, var potSize: Double = 0.0, - var playerRemainingStack: Double = 0.0) { + var playerRemainingStack: Double? = null) { /*** * The potsize is used: diff --git a/app/src/main/java/net/pokeranalytics/android/model/handhistory/HandSetup.kt b/app/src/main/java/net/pokeranalytics/android/model/handhistory/HandSetup.kt new file mode 100644 index 00000000..a5e09487 --- /dev/null +++ b/app/src/main/java/net/pokeranalytics/android/model/handhistory/HandSetup.kt @@ -0,0 +1,15 @@ +package net.pokeranalytics.android.model.handhistory + +class HandSetup { + + var smallBlind: Double? = null + + var bigBlind: Double? = null + + var ante: Double? = null + + var tableSize: Int? = null + + var bigBlindAnte: Boolean = false + +} \ No newline at end of file diff --git a/app/src/main/java/net/pokeranalytics/android/model/handhistory/Street.kt b/app/src/main/java/net/pokeranalytics/android/model/handhistory/Street.kt new file mode 100644 index 00000000..b4120df6 --- /dev/null +++ b/app/src/main/java/net/pokeranalytics/android/model/handhistory/Street.kt @@ -0,0 +1,9 @@ +package net.pokeranalytics.android.model.handhistory + +enum class Street { + PREFLOP, + FLOP, + TURN, + RIVER +} + diff --git a/app/src/main/java/net/pokeranalytics/android/model/realm/handhistory/Action.kt b/app/src/main/java/net/pokeranalytics/android/model/realm/handhistory/Action.kt index a948a258..9e91cead 100644 --- a/app/src/main/java/net/pokeranalytics/android/model/realm/handhistory/Action.kt +++ b/app/src/main/java/net/pokeranalytics/android/model/realm/handhistory/Action.kt @@ -4,6 +4,18 @@ import io.realm.RealmObject open class Action : RealmObject() { + enum class Type { + POST_SB, + POST_BB, + CHECK, + CALL, + BET, + RAISE, + CALL_ALLIN, + BET_ALLIN, + RAISE_ALLIN + } + /*** * The street of the action */ @@ -22,11 +34,16 @@ open class Action : RealmObject() { /*** * The type of action: check, fold, raise... */ - var type: Int = 0 + var type: Int? = null /*** * The amount linked for a bet, raise... */ var amount: Double? = null + var effectiveAmount: Double = 0.0 + private set + + var positionRemainingStack: Double? = null + } \ No newline at end of file diff --git a/app/src/main/java/net/pokeranalytics/android/model/realm/handhistory/HandHistory.kt b/app/src/main/java/net/pokeranalytics/android/model/realm/handhistory/HandHistory.kt index 608783cc..fe060d2e 100644 --- a/app/src/main/java/net/pokeranalytics/android/model/realm/handhistory/HandHistory.kt +++ b/app/src/main/java/net/pokeranalytics/android/model/realm/handhistory/HandHistory.kt @@ -3,74 +3,102 @@ package net.pokeranalytics.android.model.realm.handhistory import io.realm.RealmList import io.realm.RealmObject import io.realm.annotations.PrimaryKey +import net.pokeranalytics.android.model.handhistory.HandSetup import net.pokeranalytics.android.model.realm.Session import java.util.* open class HandHistory : RealmObject() { - @PrimaryKey - var id = UUID.randomUUID().toString() - - /*** - * The date of the hand history - */ - var date: Date = Date() - - /*** - * The session whose hand was played - */ - var session: Session? = null - - /*** - * The small blind - */ - var smallBlind: Double = 0.0 - - /*** - * The big blind - */ - var bigBlind: Double = 0.0 - - /*** - * The ante - */ - var ante: Double = 0.0 - - /*** - * Big blind ante - */ - var bigBlindAnte: Boolean = false - - /*** - * Number of players in the hand - */ - var numberOfPlayers: Int = 9 - - /*** - * Number of players in the hand - */ - var comment: String? = null - - /*** - * The position index of the hero - */ - var heroIndex: Int? = null - - /*** - * The board - */ - var board: RealmList = RealmList() - - /*** - * The players actions - */ - var actions: RealmList = RealmList() - - /*** - * A list of players initial data: user, position, hand, stack - */ - var playerSetups: RealmList = RealmList() - + @PrimaryKey + var id = UUID.randomUUID().toString() + + /*** + * The date of the hand history + */ + var date: Date = Date() + + /*** + * The session whose hand was played + */ + var session: Session? = null + + /*** + * The small blind + */ + var smallBlind: Double = 0.0 + + /*** + * The big blind + */ + var bigBlind: Double = 0.0 + + /*** + * The ante + */ + var ante: Double = 0.0 + + /*** + * Big blind ante + */ + var bigBlindAnte: Boolean = false + + /*** + * Number of players in the hand + */ + var numberOfPlayers: Int = 9 + + /*** + * Number of players in the hand + */ + var comment: String? = null + + /*** + * The position index of the hero + */ + var heroIndex: Int? = null + + /*** + * The board + */ + var board: RealmList = RealmList() + + /*** + * The players actions + */ + var actions: RealmList = RealmList() + + /*** + * A list of players initial data: user, position, hand, stack + */ + var playerSetups: RealmList = RealmList() + + fun configure(handSetup: HandSetup) { + + handSetup.tableSize?.let { this.numberOfPlayers = it } + handSetup.smallBlind?.let { this.smallBlind = it } + handSetup.bigBlind?.let { this.bigBlind = it } + + for (i in 0..this.numberOfPlayers) { + val action = Action() + action.index = i + action.position = i + when (i) { + 0 -> { + action.type = Action.Type.POST_SB.ordinal + action.amount = this.smallBlind + } + 1 -> { + action.type = Action.Type.POST_BB.ordinal + action.amount = this.bigBlind + } + else -> { + + } + } + this.actions.add(action) + } + + } } \ No newline at end of file