Update scoring.py

pull/1/head
wsy182 2024-11-30 17:35:53 +08:00
parent 6e0c8a80f3
commit c041963b97
1 changed files with 17 additions and 37 deletions

View File

@ -1,52 +1,32 @@
def calculate_score(fan: int, base_score: int, is_self_draw: bool, is_dealer: bool) -> dict: def calculate_score(fan: int, base_score: int, is_self_draw: bool) -> dict:
""" """
根据规则计算得分 根据成都麻将规则计算得分不区分庄家和闲家
参数: 参数:
- fan: 总番数 - fan: 总番数
- base_score: 底分 - base_score: 底分
- is_self_draw: 是否为自摸 - is_self_draw: 是否为自摸
- is_dealer: 是否为庄家
返回: 返回:
- scores: 字典包含赢家得分和输家扣分 - scores: 字典包含赢家得分和输家扣分
""" """
# 翻倍计算基础分 # 计算总分
total_score = base_score * (2 ** fan) multiplier = 2 ** fan # 根据番数计算倍率
total_score = base_score * multiplier
if is_self_draw: if is_self_draw:
# 自摸,其他三家平摊 # 自摸:三家平摊分数
if is_dealer: per_loser_score = -total_score
# 庄家自摸:每家付单倍总分 winner_score = total_score * 3 # 总赢家得分
per_loser_score = -total_score return {
winner_score = total_score * 3 # 三家支付的总和 "winner": winner_score,
return { "loser": [per_loser_score] * 3
"winner": winner_score, }
"loser": [per_loser_score] * 3
}
else:
# 闲家自摸:庄家付双倍,其他两家付单倍
dealer_loss = -total_score * 2
other_loss = -total_score
winner_score = -dealer_loss + 2 * -other_loss # 庄家和两闲家支付总和
return {
"winner": winner_score,
"loser": [dealer_loss, other_loss, other_loss]
}
else: else:
# 点炮点炮者独付 # 点炮:点炮者独付
loser_score = -total_score loser_score = -total_score
winner_score = total_score winner_score = total_score
if is_dealer: return {
# 庄家点炮 "winner": winner_score,
return { "loser": [loser_score, 0, 0]
"winner": winner_score, }
"loser": [loser_score, 0, 0]
}
else:
# 闲家点炮
return {
"winner": winner_score,
"loser": [loser_score, 0, 0]
}