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. 154
      app/src/main/java/net/pokeranalytics/android/model/realm/handhistory/HandHistory.kt

@ -13,10 +13,13 @@ class Builder {
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) {
@ -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
}
}

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

@ -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() {
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
}

@ -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<Card> = RealmList()
/***
* The players actions
*/
var actions: RealmList<Action> = RealmList()
/***
* A list of players initial data: user, position, hand, stack
*/
var playerSetups: RealmList<PlayerSetup> = 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<Card> = RealmList()
/***
* The players actions
*/
var actions: RealmList<Action> = RealmList()
/***
* A list of players initial data: user, position, hand, stack
*/
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