parent
211189a776
commit
349a2ff088
|
|
@ -0,0 +1,55 @@
|
|||
def calculate_score(fan: int, base_score: int, is_self_draw: bool, is_dealer: bool) -> dict:
|
||||
"""
|
||||
根据番数和底分计算总分。
|
||||
|
||||
参数:
|
||||
- fan: 总番数。
|
||||
- base_score: 底分。
|
||||
- is_self_draw: 是否为自摸。
|
||||
- is_dealer: 是否为庄家。
|
||||
|
||||
返回:
|
||||
- scores: 一个字典,包含所有玩家的得分。
|
||||
- "winner": 胜利者的得分(正数)。
|
||||
- "loser": 输家们的得分(负数)。
|
||||
"""
|
||||
# 计算总分 = 底分 * (2 ** 番数)
|
||||
total_score = base_score * (2 ** fan)
|
||||
|
||||
if is_self_draw:
|
||||
# 自摸,其他三家平摊
|
||||
if is_dealer:
|
||||
# 庄家自摸,三家平摊且输家每人付总分
|
||||
loser_score = -total_score
|
||||
winner_score = total_score * 3
|
||||
return {
|
||||
"winner": winner_score,
|
||||
"loser": [loser_score] * 3
|
||||
}
|
||||
else:
|
||||
# 闲家自摸,庄家付双倍,其他两家付单倍
|
||||
dealer_loss = -total_score * 2
|
||||
other_loss = -total_score
|
||||
winner_score = total_score * 4
|
||||
return {
|
||||
"winner": winner_score,
|
||||
"loser": [dealer_loss, other_loss, other_loss]
|
||||
}
|
||||
else:
|
||||
# 点炮,点炮者独付
|
||||
if is_dealer:
|
||||
# 庄家点炮
|
||||
loser_score = -total_score
|
||||
winner_score = total_score
|
||||
return {
|
||||
"winner": winner_score,
|
||||
"loser": [loser_score, 0, 0]
|
||||
}
|
||||
else:
|
||||
# 闲家点炮
|
||||
loser_score = -total_score
|
||||
winner_score = total_score
|
||||
return {
|
||||
"winner": winner_score,
|
||||
"loser": [loser_score, 0, 0]
|
||||
}
|
||||
Loading…
Reference in New Issue