Added creation of new hand, building of actions per street

hh
Laurent 6 years ago
parent 1c2a4d0a09
commit ef362bfa28
  1. 27
      app/src/main/java/net/pokeranalytics/android/model/handhistory/Builder.kt
  2. 2
      app/src/main/java/net/pokeranalytics/android/model/handhistory/ComputedAction.kt
  3. 15
      app/src/main/java/net/pokeranalytics/android/model/handhistory/HandSetup.kt
  4. 9
      app/src/main/java/net/pokeranalytics/android/model/handhistory/Street.kt
  5. 19
      app/src/main/java/net/pokeranalytics/android/model/realm/handhistory/Action.kt
  6. 28
      app/src/main/java/net/pokeranalytics/android/model/realm/handhistory/HandHistory.kt

@ -13,10 +13,13 @@ class Builder {
load() load()
} }
val actions: List<ComputedAction> = listOf() val actionsPerStreet = hashMapOf<Street, List<ComputedAction>>()
constructor(handSetup: HandSetup) {
val handHistory = HandHistory()
handHistory.configure(handSetup)
this.handHistory = handHistory
constructor() {
this.handHistory = HandHistory()
} }
constructor(handHistory: HandHistory) { constructor(handHistory: HandHistory) {
@ -26,11 +29,23 @@ class Builder {
private fun load() { private fun load() {
var potSize = 0.0 var potSize = 0.0
var totalPotSize = 0.0
// sorted actions // on veut sortir:
this.handHistory.actions.forEach { // 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
} }
} }

@ -4,7 +4,7 @@ import net.pokeranalytics.android.model.realm.handhistory.Action
class ComputedAction(var action: Action, class ComputedAction(var action: Action,
var potSize: Double = 0.0, var potSize: Double = 0.0,
var playerRemainingStack: Double = 0.0) { var playerRemainingStack: Double? = null) {
/*** /***
* The potsize is used: * The potsize is used:

@ -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
}

@ -0,0 +1,9 @@
package net.pokeranalytics.android.model.handhistory
enum class Street {
PREFLOP,
FLOP,
TURN,
RIVER
}

@ -4,6 +4,18 @@ import io.realm.RealmObject
open class Action : 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 * The street of the action
*/ */
@ -22,11 +34,16 @@ open class Action : RealmObject() {
/*** /***
* The type of action: check, fold, raise... * The type of action: check, fold, raise...
*/ */
var type: Int = 0 var type: Int? = null
/*** /***
* The amount linked for a bet, raise... * The amount linked for a bet, raise...
*/ */
var amount: Double? = null var amount: Double? = null
var effectiveAmount: Double = 0.0
private set
var positionRemainingStack: Double? = null
} }

@ -3,6 +3,7 @@ package net.pokeranalytics.android.model.realm.handhistory
import io.realm.RealmList import io.realm.RealmList
import io.realm.RealmObject import io.realm.RealmObject
import io.realm.annotations.PrimaryKey import io.realm.annotations.PrimaryKey
import net.pokeranalytics.android.model.handhistory.HandSetup
import net.pokeranalytics.android.model.realm.Session import net.pokeranalytics.android.model.realm.Session
import java.util.* import java.util.*
@ -72,5 +73,32 @@ open class HandHistory : RealmObject() {
*/ */
var playerSetups: RealmList<PlayerSetup> = RealmList() var playerSetups: RealmList<PlayerSetup> = 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)
}
}
} }
Loading…
Cancel
Save