commonMain.eu.codlab.lorcana.math.Deck.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of lorcana-math Show documentation
Show all versions of lorcana-math Show documentation
Lorcana set descriptions and data
package eu.codlab.lorcana.math
data class Deck(
val size: Long,
val hand: Long
) {
private var mutableCards = mutableListOf()
var others = ExpectedCard(
"others",
originalAmount = size,
originalMin = 0,
originalMax = hand
)
private set
val cards: List
get() = mutableCards
fun calculate() = eu.codlab.lorcana.math.calculate(
size,
hand,
others.amount,
cards
)
fun add(name: String): ExpectedCard {
remove(name)
return ExpectedCard(name, 0, 0, 0).also {
mutableCards.add(it)
updateRemainingCards()
}
}
fun remove(name: String) {
val index = mutableCards.indexOfFirst { it.name == name }
if (index < 0) return
mutableCards.removeAt(index)
}
fun update(name: String, amount: Long, min: Long, max: Long): Boolean {
val holder = mutableCards.firstOrNull { it.name == name } ?: return false
holder.update(amount, min, max)
updateRemainingCards()
println("amount -> $amount / $size")
println("min -> $min / $hand")
println("max -> $max / $size")
println("update done \n\n")
return amount <= size && min <= hand && max <= size
}
private fun updateRemainingCards() {
val cardsAddedAmount = mutableCards.map { it.amount }.reduce { acc, l -> acc + l }
val cardsMinAmount = mutableCards.map { it.min }.reduce { acc, l -> acc + l }
println("cards added amount $cardsAddedAmount")
println("cards min amount $cardsMinAmount")
others.update(
amount = size - cardsAddedAmount,
min = 0,
max = hand - cardsMinAmount
)
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy