parent
349a2ff088
commit
4dbbd583b9
|
|
@ -1,6 +1,6 @@
|
||||||
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, is_dealer: bool) -> dict:
|
||||||
"""
|
"""
|
||||||
根据番数和底分计算总分。
|
根据规则计算得分。
|
||||||
|
|
||||||
参数:
|
参数:
|
||||||
- fan: 总番数。
|
- fan: 总番数。
|
||||||
|
|
@ -9,17 +9,15 @@ def calculate_score(fan: int, base_score: int, is_self_draw: bool, is_dealer: bo
|
||||||
- is_dealer: 是否为庄家。
|
- is_dealer: 是否为庄家。
|
||||||
|
|
||||||
返回:
|
返回:
|
||||||
- scores: 一个字典,包含所有玩家的得分。
|
- scores: 字典,包含赢家得分和输家扣分。
|
||||||
- "winner": 胜利者的得分(正数)。
|
|
||||||
- "loser": 输家们的得分(负数)。
|
|
||||||
"""
|
"""
|
||||||
# 计算总分 = 底分 * (2 ** 番数)
|
# 翻倍计算总分
|
||||||
total_score = base_score * (2 ** fan)
|
total_score = base_score * (2 ** fan)
|
||||||
|
|
||||||
if is_self_draw:
|
if is_self_draw:
|
||||||
# 自摸,其他三家平摊
|
# 自摸,其他三家平摊
|
||||||
if is_dealer:
|
if is_dealer:
|
||||||
# 庄家自摸,三家平摊且输家每人付总分
|
# 庄家自摸:每家付总分
|
||||||
loser_score = -total_score
|
loser_score = -total_score
|
||||||
winner_score = total_score * 3
|
winner_score = total_score * 3
|
||||||
return {
|
return {
|
||||||
|
|
@ -27,7 +25,7 @@ def calculate_score(fan: int, base_score: int, is_self_draw: bool, is_dealer: bo
|
||||||
"loser": [loser_score] * 3
|
"loser": [loser_score] * 3
|
||||||
}
|
}
|
||||||
else:
|
else:
|
||||||
# 闲家自摸,庄家付双倍,其他两家付单倍
|
# 闲家自摸:庄家付双倍,其他两家付单倍
|
||||||
dealer_loss = -total_score * 2
|
dealer_loss = -total_score * 2
|
||||||
other_loss = -total_score
|
other_loss = -total_score
|
||||||
winner_score = total_score * 4
|
winner_score = total_score * 4
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,72 @@
|
||||||
|
from src.engine.scoring import calculate_score
|
||||||
|
|
||||||
|
|
||||||
|
def test_dealer_self_draw():
|
||||||
|
"""
|
||||||
|
测试用例 1: 庄家自摸,总番数 3,底分 10
|
||||||
|
"""
|
||||||
|
fan = 3
|
||||||
|
base_score = 10
|
||||||
|
is_self_draw = True
|
||||||
|
is_dealer = True
|
||||||
|
|
||||||
|
scores = calculate_score(fan, base_score, is_self_draw, is_dealer)
|
||||||
|
expected_scores = {"winner": 240, "loser": [-80, -80, -80]}
|
||||||
|
assert scores == expected_scores, f"庄家自摸测试失败: {scores} != {expected_scores}"
|
||||||
|
|
||||||
|
|
||||||
|
def test_non_dealer_point_win():
|
||||||
|
"""
|
||||||
|
测试用例 2: 闲家点炮,总番数 2,底分 10
|
||||||
|
"""
|
||||||
|
fan = 2
|
||||||
|
base_score = 10
|
||||||
|
is_self_draw = False
|
||||||
|
is_dealer = False
|
||||||
|
|
||||||
|
scores = calculate_score(fan, base_score, is_self_draw, is_dealer)
|
||||||
|
expected_scores = {"winner": 40, "loser": [-40, 0, 0]}
|
||||||
|
assert scores == expected_scores, f"闲家点炮测试失败: {scores} != {expected_scores}"
|
||||||
|
|
||||||
|
|
||||||
|
def test_non_dealer_self_draw():
|
||||||
|
"""
|
||||||
|
测试用例 3: 闲家自摸,总番数 4,底分 10
|
||||||
|
"""
|
||||||
|
fan = 4
|
||||||
|
base_score = 10
|
||||||
|
is_self_draw = True
|
||||||
|
is_dealer = False
|
||||||
|
|
||||||
|
scores = calculate_score(fan, base_score, is_self_draw, is_dealer)
|
||||||
|
expected_scores = {"winner": 160, "loser": [-80, -40, -40]}
|
||||||
|
assert scores == expected_scores, f"闲家自摸测试失败: {scores} != {expected_scores}"
|
||||||
|
|
||||||
|
|
||||||
|
def test_dealer_point_win():
|
||||||
|
"""
|
||||||
|
测试用例 4: 庄家点炮,总番数 1,底分 5
|
||||||
|
"""
|
||||||
|
fan = 1
|
||||||
|
base_score = 5
|
||||||
|
is_self_draw = False
|
||||||
|
is_dealer = True
|
||||||
|
|
||||||
|
scores = calculate_score(fan, base_score, is_self_draw, is_dealer)
|
||||||
|
expected_scores = {"winner": 10, "loser": [-10, 0, 0]}
|
||||||
|
assert scores == expected_scores, f"庄家点炮测试失败: {scores} != {expected_scores}"
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
# 单独执行测试
|
||||||
|
test_dealer_self_draw()
|
||||||
|
print("测试 1: 庄家自摸通过!")
|
||||||
|
|
||||||
|
test_non_dealer_point_win()
|
||||||
|
print("测试 2: 闲家点炮通过!")
|
||||||
|
|
||||||
|
test_non_dealer_self_draw()
|
||||||
|
print("测试 3: 闲家自摸通过!")
|
||||||
|
|
||||||
|
test_dealer_point_win()
|
||||||
|
print("测试 4: 庄家点炮通过!")
|
||||||
Loading…
Reference in New Issue