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 11c2521e..e655da13 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 @@ -483,73 +483,6 @@ open class HandHistory : RealmObject(), Deletable, RowRepresentable, Filterable, } data class Pot(var amount: Double, var level: Double, var positions: MutableSet = mutableSetOf()) -// fun pots(): List { -// -// var currentPot = 0.0 -// val positions = this.positionIndexes.toMutableSet() -// val pots = mutableListOf() -// var allinAtStreet: Street? = null -// val allinActions = mutableListOf() -// 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 @@ -577,6 +510,9 @@ open class HandHistory : RealmObject(), Deletable, RowRepresentable, Filterable, this.winnerPots.addAll(wonPots) } + /*** + * Returns a list with all the different pots with the appropriate eligible players + */ fun getPots(eligiblePositions: List): List { var runningPotAmount = 0.0 @@ -591,6 +527,8 @@ open class HandHistory : RealmObject(), Deletable, RowRepresentable, Filterable, runningPotAmount += streetActions.sumByDouble { it.effectiveAmount } } else { val amountsPerPosition = mutableListOf() + + // get all committed amounts for the street by player, by allin this.positionIndexes.map { position -> val playerActions = streetActions.filter { it.position == position } 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 + // for each player val streetPots = mutableListOf() amountsPerPosition.forEach { positionAmount -> val amount = positionAmount.amount @@ -605,6 +544,7 @@ open class HandHistory : RealmObject(), Deletable, RowRepresentable, Filterable, var rest = amount var lastPotLevel = 0.0 + // put invested amount in smaller pots streetPots.forEach { pot -> val added = pot.level - lastPotLevel pot.amount += added @@ -614,43 +554,23 @@ open class HandHistory : RealmObject(), Deletable, RowRepresentable, Filterable, rest -= added lastPotLevel = pot.level } + // Adds remaining chips to the running Pot runningPotAmount += rest + // If the player is allin, create a new pot for the relevant amount val isAllin = allinPositions.contains(position) if (isAllin) { streetPots.add(Pot(runningPotAmount, amount, mutableSetOf(position))) 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) } } + // Create a pot with the remaining chips if (runningPotAmount > 0.0) { pots.add(Pot(runningPotAmount, 0.0, eligiblePositions.toMutableSet())) } @@ -658,62 +578,6 @@ open class HandHistory : RealmObject(), Deletable, RowRepresentable, Filterable, 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): Collection { -// -// // 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() -// 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): Collection { val wonPots = hashMapOf()