Puts un-impactful suits to suit wildcards

blinds
Laurent 5 years ago
parent 4fd90a3811
commit dbd0586d44
  1. 58
      app/src/main/java/net/pokeranalytics/android/model/realm/handhistory/Card.kt
  2. 41
      app/src/main/java/net/pokeranalytics/android/model/realm/handhistory/HandHistory.kt
  3. 27
      app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/HandHistoryActivity.kt

@ -14,6 +14,7 @@ import net.pokeranalytics.android.exceptions.PAIllegalStateException
import net.pokeranalytics.android.model.handhistory.Street
import net.pokeranalytics.android.ui.view.RowRepresentable
import net.pokeranalytics.android.ui.view.RowViewType
import timber.log.Timber
interface CardProperty
@ -24,11 +25,10 @@ fun List<Card>.formatted(context: Context) : CharSequence? {
var span: CharSequence? = null
this.forEach {
val formatted = it.formatted(context)
if (span == null) {
span = formatted
}
else {
span = TextUtils.concat(span, formatted)
span = if (span == null) {
formatted
} else {
TextUtils.concat(span, formatted)
}
}
return span
@ -95,6 +95,10 @@ open class Card : RealmObject() {
companion object {
val baseSuits: List<Suit> by lazy {
listOf(SPADES, HEART, DIAMOND, CLOVER)
}
val displaySuits: List<Suit> by lazy {
listOf(SPADES, HEART, DIAMOND, CLOVER, UNDEFINED)
}
@ -240,9 +244,49 @@ open class Card : RealmObject() {
}
}
fun copy(): Card {
val card = Card()
card.value = this.value
card.suit = this.suit
return card
}
val isWildCard: Boolean
get() {
return this.value == null || this.suit == null || this.suit == Suit.UNDEFINED
return this.value == null || this.isSuitWildCard
}
}
val isSuitWildCard: Boolean
get() {
return this.suit == null || this.suit == Suit.UNDEFINED
}
}
fun List<Card>.putSuits(usedCards: MutableList<Card>) : List<Card> {
fun getLeastUsedValidSuit(value: Int, usedCards: MutableList<Card>, addedCards: List<Card>): Card.Suit {
val availableSuits = Card.Suit.baseSuits.toMutableList()
usedCards.filter { it.value == value }.forEach { availableSuits.remove(it.suit) }
val currentCards = this.drop(addedCards.size) + addedCards
val cardsPerSuit = availableSuits.associateWith { suit ->
currentCards.filter { it.suit == suit }
}
return cardsPerSuit.minByOrNull { it.value.count() }!!.key
}
val list = mutableListOf<Card>()
this.forEach { cardToClone ->
val card = cardToClone.copy()
if (card.value != null && card.isSuitWildCard) {
card.suit = getLeastUsedValidSuit(card.value!!, usedCards, list)
usedCards.add(card)
Timber.d("Selected suit for wildcard: ${card.suit?.value}, value = ${card.value}")
}
list.add(card)
}
return list
}

@ -609,15 +609,30 @@ open class HandHistory : RealmObject(), Deletable, RowRepresentable, Filterable,
*/
private fun compareHands(activePositions: List<Int>): List<Int> {
val usedFullCards = this.allFullCards.toMutableList()
val noWildCardBoard = this.board.putSuits(usedFullCards)
val noWildCardHands = activePositions.map {
this.playerSetupForPosition(it)?.cards?.putSuits(usedFullCards)
}
// Evaluate all hands
val results = activePositions.map {
this.playerSetupForPosition(it)?.cards?.let { hand ->
EvaluatorBridge.playerHand(hand, this.board)
val results = noWildCardHands.map { cards ->
cards?.let { hand ->
EvaluatorBridge.playerHand(hand, noWildCardBoard)
} ?: run {
Int.MAX_VALUE
}
}
// 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.minOrNull()?.let { best ->
val winners = mutableListOf<Int>()
@ -662,4 +677,24 @@ open class HandHistory : RealmObject(), Deletable, RowRepresentable, Filterable,
return boardHasWildCard || playerCardHasWildCard
}
val allFullCards: List<Card>
get() {
val cards = mutableListOf<Card>()
cards.addAll(this.board)
this.playerSetups.forEach {
cards.addAll(it.cards)
}
return cards.filter { !it.isWildCard }
}
val allSuitWildCards: List<Card>
get() {
val cards = mutableListOf<Card>()
cards.addAll(this.board)
this.playerSetups.forEach {
cards.addAll(it.cards)
}
return cards.filter { it.isSuitWildCard }
}
}

@ -16,7 +16,6 @@ import net.pokeranalytics.android.model.realm.Session
import net.pokeranalytics.android.model.realm.handhistory.HandHistory
import net.pokeranalytics.android.ui.activity.components.BaseActivity
import net.pokeranalytics.android.ui.activity.components.RequestCode
import net.pokeranalytics.android.ui.extensions.areYouSure
import net.pokeranalytics.android.ui.modules.handhistory.editor.EditorFragment
import net.pokeranalytics.android.ui.modules.handhistory.replayer.ReplayExportService
import net.pokeranalytics.android.ui.modules.handhistory.replayer.ReplayerFragment
@ -154,25 +153,14 @@ class HandHistoryActivity : BaseActivity() {
// of the selected item
when (index) {
0 -> this.textExport()
1 -> this.videoExportWildCardsCheck()
2 -> this.gifExportWildCardsCheck()
1 -> this.videoExportAskForPermission()
2 -> this.gifExportAskForPermission()
}
}
builder.create().show()
}
private fun gifExportWildCardsCheck() {
if (this.handHistory.usesWildcards) {
areYouSure(message = R.string.wildcards_warning, positiveTitle = R.string.proceed) {
gifExportAskForPermission()
}
} else {
gifExportAskForPermission()
}
}
private fun gifExportAskForPermission() {
Toast.makeText(this, R.string.video_export_started, Toast.LENGTH_LONG).show()
@ -192,17 +180,6 @@ class HandHistoryActivity : BaseActivity() {
}
private fun videoExportWildCardsCheck() {
if (this.handHistory.usesWildcards) {
areYouSure(message = R.string.wildcards_warning, positiveTitle = R.string.proceed) {
videoExportAskForPermission()
}
} else {
videoExportAskForPermission()
}
}
private fun videoExportAskForPermission() {
Toast.makeText(this, R.string.video_export_started, Toast.LENGTH_LONG).show()

Loading…
Cancel
Save