From 349a2ff08832a5829f06d77402c6caa9e9f4c854 Mon Sep 17 00:00:00 2001 From: wsy182 <2392948297@qq.com> Date: Sat, 30 Nov 2024 17:01:49 +0800 Subject: [PATCH] 1 1 --- configs/application.yaml | 0 src/engine/scoring.py | 55 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+) create mode 100644 configs/application.yaml create mode 100644 src/engine/scoring.py diff --git a/configs/application.yaml b/configs/application.yaml new file mode 100644 index 0000000..e69de29 diff --git a/src/engine/scoring.py b/src/engine/scoring.py new file mode 100644 index 0000000..1e01d5b --- /dev/null +++ b/src/engine/scoring.py @@ -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] + }