All Downloads are FREE. Search and download functionalities are using the official Maven repository.

commonMain.mahjongutils.hora.helpers.CalcHan.kt Maven / Gradle / Ivy

There is a newer version: 0.7.6
Show newest version
package mahjongutils.hora.helpers

import mahjongutils.hora.HoraHandPattern
import mahjongutils.hora.HoraOptions
import mahjongutils.yaku.Yaku

fun calcHan(
    pattern: HoraHandPattern,
    options: HoraOptions,
    yaku: Set,
    dora: Int
): Int {
    val hasYakuman: Boolean = yaku.any { it.isYakuman }

    var ans = 0

    if (hasYakuman && !options.aotenjou && !options.hasComplexYakuman) {
        ans = if (pattern.menzen) {
            yaku.maxOf { it.han }
        } else {
            yaku.maxOf { it.han - it.furoLoss }
        }
    } else {
        ans = if (pattern.menzen) {
            yaku.sumOf { it.han }
        } else {
            yaku.sumOf { it.han - it.furoLoss }
        }

        if (options.aotenjou || !hasYakuman && ans > 0) {
            ans += dora
        }
    }

    return ans
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy