|
|
|
@ -20,6 +20,7 @@ import net.pokeranalytics.android.model.interfaces.DeleteValidityStatus |
|
|
|
import net.pokeranalytics.android.model.interfaces.Identifiable |
|
|
|
import net.pokeranalytics.android.model.interfaces.Identifiable |
|
|
|
import net.pokeranalytics.android.model.interfaces.TimeFilterable |
|
|
|
import net.pokeranalytics.android.model.interfaces.TimeFilterable |
|
|
|
import net.pokeranalytics.android.model.realm.Session |
|
|
|
import net.pokeranalytics.android.model.realm.Session |
|
|
|
|
|
|
|
import net.pokeranalytics.android.ui.modules.handhistory.evaluator.EvaluatorBridge |
|
|
|
import net.pokeranalytics.android.ui.modules.handhistory.model.ActionReadRow |
|
|
|
import net.pokeranalytics.android.ui.modules.handhistory.model.ActionReadRow |
|
|
|
import net.pokeranalytics.android.ui.modules.handhistory.model.CardHolder |
|
|
|
import net.pokeranalytics.android.ui.modules.handhistory.model.CardHolder |
|
|
|
import net.pokeranalytics.android.ui.view.RowRepresentable |
|
|
|
import net.pokeranalytics.android.ui.view.RowRepresentable |
|
|
|
@ -115,6 +116,11 @@ open class HandHistory : RealmObject(), Deletable, RowRepresentable, Filterable, |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
var heroIndex: Int? = null |
|
|
|
var heroIndex: Int? = null |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*** |
|
|
|
|
|
|
|
* Indicates if the hero wins the hand |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
var winningPositions: RealmList<Int> = RealmList() |
|
|
|
|
|
|
|
|
|
|
|
/*** |
|
|
|
/*** |
|
|
|
* The board |
|
|
|
* The board |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
@ -403,6 +409,30 @@ open class HandHistory : RealmObject(), Deletable, RowRepresentable, Filterable, |
|
|
|
return actionItems.joinToString(" ") |
|
|
|
return actionItems.joinToString(" ") |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*** |
|
|
|
|
|
|
|
* Returns if the hero has won the hand, or part of the pot |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
val heroWins: Boolean? |
|
|
|
|
|
|
|
get() { |
|
|
|
|
|
|
|
return this.heroIndex?.let { |
|
|
|
|
|
|
|
this.winningPositions.contains(it) |
|
|
|
|
|
|
|
} ?: run { |
|
|
|
|
|
|
|
null |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// private fun definesIfHeroWins() { |
|
|
|
|
|
|
|
// this.heroIndex?.let { heroIndex -> |
|
|
|
|
|
|
|
// |
|
|
|
|
|
|
|
// val heroCards = this.playerSetupForPosition(heroIndex)?.cards |
|
|
|
|
|
|
|
// val heroNumberOfCards = heroCards?.size ?: 0 |
|
|
|
|
|
|
|
// if (this.board.size == 5 && heroNumberOfCards > 1) { |
|
|
|
|
|
|
|
// |
|
|
|
|
|
|
|
// } |
|
|
|
|
|
|
|
// |
|
|
|
|
|
|
|
// } |
|
|
|
|
|
|
|
// } |
|
|
|
|
|
|
|
|
|
|
|
/*** |
|
|
|
/*** |
|
|
|
* Creates a list of cards for the hand history to give a representation of the hand |
|
|
|
* Creates a list of cards for the hand history to give a representation of the hand |
|
|
|
* We will try to add a minimum of 5 cards using by priority: |
|
|
|
* We will try to add a minimum of 5 cards using by priority: |
|
|
|
@ -455,4 +485,46 @@ open class HandHistory : RealmObject(), Deletable, RowRepresentable, Filterable, |
|
|
|
return views |
|
|
|
return views |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fun compareHands(activePositions: List<Int>): List<Int> { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Evaluate all hands |
|
|
|
|
|
|
|
val results = activePositions.map { |
|
|
|
|
|
|
|
this.playerSetupForPosition(it)?.cards?.let { hand -> |
|
|
|
|
|
|
|
EvaluatorBridge.playerHand(hand, this.board) |
|
|
|
|
|
|
|
} ?: run { |
|
|
|
|
|
|
|
Int.MAX_VALUE |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Check who has best score (EvaluatorBridge gives a lowest score for a better hand) |
|
|
|
|
|
|
|
return results.min()?.let { best -> |
|
|
|
|
|
|
|
val winners = mutableListOf<Int>() |
|
|
|
|
|
|
|
results.forEachIndexed { index, i -> |
|
|
|
|
|
|
|
if (i == best && i != Int.MAX_VALUE) { |
|
|
|
|
|
|
|
winners.add(activePositions[index]) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
winners |
|
|
|
|
|
|
|
} ?: run { |
|
|
|
|
|
|
|
listOf<Int>() // type needed for build |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fun defineWinnerPositions() { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
val folds = this.sortedActions.filter { it.type == Action.Type.FOLD }.map { it.position } |
|
|
|
|
|
|
|
val activePositions = (0 until this.numberOfPlayers).toMutableList() |
|
|
|
|
|
|
|
activePositions.removeAll(folds) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
val winningPositions = when (activePositions.size) { |
|
|
|
|
|
|
|
0 -> listOf() // no winner, everyone has fold. Should not happen |
|
|
|
|
|
|
|
1 -> activePositions // One player has not fold, typically BET / FOLD |
|
|
|
|
|
|
|
else -> this.compareHands(activePositions) // Several players remains, typically BET/FOLD or CHECKS |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.winningPositions.clear() |
|
|
|
|
|
|
|
this.winningPositions.addAll(winningPositions) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |