|
|
|
@ -483,73 +483,6 @@ open class HandHistory : RealmObject(), Deletable, RowRepresentable, Filterable, |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
data class Pot(var amount: Double, var level: Double, var positions: MutableSet<Int> = mutableSetOf()) |
|
|
|
data class Pot(var amount: Double, var level: Double, var positions: MutableSet<Int> = mutableSetOf()) |
|
|
|
// fun pots(): List<Pot> { |
|
|
|
|
|
|
|
// |
|
|
|
|
|
|
|
// var currentPot = 0.0 |
|
|
|
|
|
|
|
// val positions = this.positionIndexes.toMutableSet() |
|
|
|
|
|
|
|
// val pots = mutableListOf<Pot>() |
|
|
|
|
|
|
|
// var allinAtStreet: Street? = null |
|
|
|
|
|
|
|
// val allinActions = mutableListOf<Action>() |
|
|
|
|
|
|
|
// this.sortedActions.forEach { |
|
|
|
|
|
|
|
// |
|
|
|
|
|
|
|
// if (allinAtStreet == null) { |
|
|
|
|
|
|
|
// |
|
|
|
|
|
|
|
// when { |
|
|
|
|
|
|
|
// it.type == Action.Type.FOLD -> { |
|
|
|
|
|
|
|
// positions.remove(it.position) |
|
|
|
|
|
|
|
// } |
|
|
|
|
|
|
|
// it.type?.isPullOut == false -> { |
|
|
|
|
|
|
|
// currentPot += it.effectiveAmount |
|
|
|
|
|
|
|
// } |
|
|
|
|
|
|
|
// it.type == Action.Type.CALL_ALLIN -> { |
|
|
|
|
|
|
|
// allinAtStreet = it.street |
|
|
|
|
|
|
|
// // TODO create pot |
|
|
|
|
|
|
|
// } |
|
|
|
|
|
|
|
// it.type?.isAllin == true -> { |
|
|
|
|
|
|
|
// currentPot += it.effectiveAmount |
|
|
|
|
|
|
|
// allinAtStreet = it.street |
|
|
|
|
|
|
|
// allinActions.add(it) |
|
|
|
|
|
|
|
// } |
|
|
|
|
|
|
|
// else -> { |
|
|
|
|
|
|
|
// Timber.d("unmanaged action type: ${it.type}") |
|
|
|
|
|
|
|
//// throw PAIllegalStateException("unmanaged action type: ${it.type}") |
|
|
|
|
|
|
|
// } |
|
|
|
|
|
|
|
// } |
|
|
|
|
|
|
|
// |
|
|
|
|
|
|
|
// } else { // Allin situation |
|
|
|
|
|
|
|
// |
|
|
|
|
|
|
|
// if (it.street != allinAtStreet) { |
|
|
|
|
|
|
|
// allinAtStreet = null |
|
|
|
|
|
|
|
// allinActions.clear() |
|
|
|
|
|
|
|
// } else { |
|
|
|
|
|
|
|
// when { |
|
|
|
|
|
|
|
// it.type == Action.Type.FOLD -> { |
|
|
|
|
|
|
|
// positions.remove(it.position) |
|
|
|
|
|
|
|
// } |
|
|
|
|
|
|
|
// it.type == Action.Type.CALL -> { |
|
|
|
|
|
|
|
// currentPot += it.effectiveAmount |
|
|
|
|
|
|
|
// allinActions.add(it) |
|
|
|
|
|
|
|
// } |
|
|
|
|
|
|
|
// it.type == Action.Type.CALL_ALLIN -> { |
|
|
|
|
|
|
|
// |
|
|
|
|
|
|
|
// } |
|
|
|
|
|
|
|
// |
|
|
|
|
|
|
|
// } |
|
|
|
|
|
|
|
// |
|
|
|
|
|
|
|
// |
|
|
|
|
|
|
|
// |
|
|
|
|
|
|
|
// } |
|
|
|
|
|
|
|
// |
|
|
|
|
|
|
|
// } |
|
|
|
|
|
|
|
// |
|
|
|
|
|
|
|
// } |
|
|
|
|
|
|
|
// |
|
|
|
|
|
|
|
// if (currentPot > 0.0) { |
|
|
|
|
|
|
|
//// pots.add(Pot(currentPot, positions)) |
|
|
|
|
|
|
|
// } |
|
|
|
|
|
|
|
// |
|
|
|
|
|
|
|
// return pots |
|
|
|
|
|
|
|
// } |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*** |
|
|
|
/*** |
|
|
|
* Defines which positions win the hand |
|
|
|
* Defines which positions win the hand |
|
|
|
@ -577,6 +510,9 @@ open class HandHistory : RealmObject(), Deletable, RowRepresentable, Filterable, |
|
|
|
this.winnerPots.addAll(wonPots) |
|
|
|
this.winnerPots.addAll(wonPots) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*** |
|
|
|
|
|
|
|
* Returns a list with all the different pots with the appropriate eligible players |
|
|
|
|
|
|
|
*/ |
|
|
|
fun getPots(eligiblePositions: List<Int>): List<Pot> { |
|
|
|
fun getPots(eligiblePositions: List<Int>): List<Pot> { |
|
|
|
|
|
|
|
|
|
|
|
var runningPotAmount = 0.0 |
|
|
|
var runningPotAmount = 0.0 |
|
|
|
@ -591,6 +527,8 @@ open class HandHistory : RealmObject(), Deletable, RowRepresentable, Filterable, |
|
|
|
runningPotAmount += streetActions.sumByDouble { it.effectiveAmount } |
|
|
|
runningPotAmount += streetActions.sumByDouble { it.effectiveAmount } |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
val amountsPerPosition = mutableListOf<PositionAmount>() |
|
|
|
val amountsPerPosition = mutableListOf<PositionAmount>() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// get all committed amounts for the street by player, by allin |
|
|
|
this.positionIndexes.map { position -> |
|
|
|
this.positionIndexes.map { position -> |
|
|
|
val playerActions = streetActions.filter { it.position == position } |
|
|
|
val playerActions = streetActions.filter { it.position == position } |
|
|
|
val sum = playerActions.sumByDouble { it.effectiveAmount } |
|
|
|
val sum = playerActions.sumByDouble { it.effectiveAmount } |
|
|
|
@ -598,6 +536,7 @@ open class HandHistory : RealmObject(), Deletable, RowRepresentable, Filterable, |
|
|
|
} |
|
|
|
} |
|
|
|
amountsPerPosition.sortWith(this) // sort by value, then allin. Allin must be first of equal values sequence |
|
|
|
amountsPerPosition.sortWith(this) // sort by value, then allin. Allin must be first of equal values sequence |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// for each player |
|
|
|
val streetPots = mutableListOf<Pot>() |
|
|
|
val streetPots = mutableListOf<Pot>() |
|
|
|
amountsPerPosition.forEach { positionAmount -> |
|
|
|
amountsPerPosition.forEach { positionAmount -> |
|
|
|
val amount = positionAmount.amount |
|
|
|
val amount = positionAmount.amount |
|
|
|
@ -605,6 +544,7 @@ open class HandHistory : RealmObject(), Deletable, RowRepresentable, Filterable, |
|
|
|
|
|
|
|
|
|
|
|
var rest = amount |
|
|
|
var rest = amount |
|
|
|
var lastPotLevel = 0.0 |
|
|
|
var lastPotLevel = 0.0 |
|
|
|
|
|
|
|
// put invested amount in smaller pots |
|
|
|
streetPots.forEach { pot -> |
|
|
|
streetPots.forEach { pot -> |
|
|
|
val added = pot.level - lastPotLevel |
|
|
|
val added = pot.level - lastPotLevel |
|
|
|
pot.amount += added |
|
|
|
pot.amount += added |
|
|
|
@ -614,43 +554,23 @@ open class HandHistory : RealmObject(), Deletable, RowRepresentable, Filterable, |
|
|
|
rest -= added |
|
|
|
rest -= added |
|
|
|
lastPotLevel = pot.level |
|
|
|
lastPotLevel = pot.level |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// Adds remaining chips to the running Pot |
|
|
|
runningPotAmount += rest |
|
|
|
runningPotAmount += rest |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// If the player is allin, create a new pot for the relevant amount |
|
|
|
val isAllin = allinPositions.contains(position) |
|
|
|
val isAllin = allinPositions.contains(position) |
|
|
|
if (isAllin) { |
|
|
|
if (isAllin) { |
|
|
|
streetPots.add(Pot(runningPotAmount, amount, mutableSetOf(position))) |
|
|
|
streetPots.add(Pot(runningPotAmount, amount, mutableSetOf(position))) |
|
|
|
runningPotAmount = 0.0 |
|
|
|
runningPotAmount = 0.0 |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// if (!isAllin) { |
|
|
|
|
|
|
|
// |
|
|
|
|
|
|
|
// if (streetPots.isEmpty()) { |
|
|
|
|
|
|
|
// runningPotAmount += amount |
|
|
|
|
|
|
|
// } else { |
|
|
|
|
|
|
|
// var rest = amount |
|
|
|
|
|
|
|
// streetPots.forEach { pot -> |
|
|
|
|
|
|
|
// pot.amount += pot.level |
|
|
|
|
|
|
|
// if (eligiblePositions.contains(position)) { |
|
|
|
|
|
|
|
// pot.positions.add(position) |
|
|
|
|
|
|
|
// } |
|
|
|
|
|
|
|
// rest -= pot.level |
|
|
|
|
|
|
|
// } |
|
|
|
|
|
|
|
// runningPotAmount += rest |
|
|
|
|
|
|
|
// } |
|
|
|
|
|
|
|
// |
|
|
|
|
|
|
|
// } else { |
|
|
|
|
|
|
|
// runningPotAmount += amount |
|
|
|
|
|
|
|
// streetPots.add(Pot(runningPotAmount, amount, mutableSetOf(position))) |
|
|
|
|
|
|
|
// runningPotAmount = 0.0 |
|
|
|
|
|
|
|
// } |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
pots.addAll(streetPots) |
|
|
|
pots.addAll(streetPots) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Create a pot with the remaining chips |
|
|
|
if (runningPotAmount > 0.0) { |
|
|
|
if (runningPotAmount > 0.0) { |
|
|
|
pots.add(Pot(runningPotAmount, 0.0, eligiblePositions.toMutableSet())) |
|
|
|
pots.add(Pot(runningPotAmount, 0.0, eligiblePositions.toMutableSet())) |
|
|
|
} |
|
|
|
} |
|
|
|
@ -658,62 +578,6 @@ open class HandHistory : RealmObject(), Deletable, RowRepresentable, Filterable, |
|
|
|
return pots |
|
|
|
return pots |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/*** |
|
|
|
|
|
|
|
* Compares the hands of the players at the given [positions] |
|
|
|
|
|
|
|
* Returns the list of winning hands by position + chips won |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
// private fun getWinningsByPosition(positions: List<Int>): Collection<WonPot> { |
|
|
|
|
|
|
|
// |
|
|
|
|
|
|
|
// // get the total committed amounts for each position, same order |
|
|
|
|
|
|
|
// val committedAmounts = this.positionIndexes.map { position -> |
|
|
|
|
|
|
|
// this.actions.filter { it.position == position }.sumByDouble { it.effectiveAmount } |
|
|
|
|
|
|
|
// }.toMutableList() |
|
|
|
|
|
|
|
// |
|
|
|
|
|
|
|
// // get the various committed levels, ascendly sorted |
|
|
|
|
|
|
|
// val sortedPotLevels = committedAmounts.toSet().toList().sorted() |
|
|
|
|
|
|
|
// |
|
|
|
|
|
|
|
// var previousPotLevel = 0.0 // previous pot level, to remove from the next level |
|
|
|
|
|
|
|
// |
|
|
|
|
|
|
|
// // Iterate on each pot |
|
|
|
|
|
|
|
// sortedPotLevels.forEach { potLevel -> |
|
|
|
|
|
|
|
// |
|
|
|
|
|
|
|
// val potEligiblePositions = mutableListOf<Int>() |
|
|
|
|
|
|
|
// var pot = 0.0 |
|
|
|
|
|
|
|
// val asked = potLevel - previousPotLevel |
|
|
|
|
|
|
|
// committedAmounts.forEachIndexed { index, playerAmount -> |
|
|
|
|
|
|
|
// |
|
|
|
|
|
|
|
// // if the player has the asked amount, he becomes eligible for the pot |
|
|
|
|
|
|
|
// if (playerAmount >= asked) { |
|
|
|
|
|
|
|
// potEligiblePositions.add(positions[index]) |
|
|
|
|
|
|
|
// committedAmounts[index] = playerAmount - asked |
|
|
|
|
|
|
|
// pot += asked |
|
|
|
|
|
|
|
// } else if (playerAmount != 0.0) { |
|
|
|
|
|
|
|
// throw PAIllegalStateException("Issue in pot calculations") |
|
|
|
|
|
|
|
// } |
|
|
|
|
|
|
|
// } |
|
|
|
|
|
|
|
// previousPotLevel = potLevel |
|
|
|
|
|
|
|
// |
|
|
|
|
|
|
|
// // get the winning positions |
|
|
|
|
|
|
|
// val winningPositions = compareHands(potEligiblePositions) |
|
|
|
|
|
|
|
// |
|
|
|
|
|
|
|
// // Distributes the pot for each winners |
|
|
|
|
|
|
|
// val share = pot / winningPositions.size |
|
|
|
|
|
|
|
// winningPositions.forEach { p -> |
|
|
|
|
|
|
|
// val wp = wonPots[p] |
|
|
|
|
|
|
|
// if (wp == null) { |
|
|
|
|
|
|
|
// val wonPot = WonPot() |
|
|
|
|
|
|
|
// wonPot.position = p |
|
|
|
|
|
|
|
// wonPot.amount = share |
|
|
|
|
|
|
|
// wonPots[p] = wonPot |
|
|
|
|
|
|
|
// } else { |
|
|
|
|
|
|
|
// wp.amount += share |
|
|
|
|
|
|
|
// } |
|
|
|
|
|
|
|
// } |
|
|
|
|
|
|
|
// } |
|
|
|
|
|
|
|
// |
|
|
|
|
|
|
|
// return wonPots.values |
|
|
|
|
|
|
|
// } |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private fun wonPots(pots: List<Pot>): Collection<WonPot> { |
|
|
|
private fun wonPots(pots: List<Pot>): Collection<WonPot> { |
|
|
|
|
|
|
|
|
|
|
|
val wonPots = hashMapOf<Int, WonPot>() |
|
|
|
val wonPots = hashMapOf<Int, WonPot>() |
|
|
|
|