mjAi/src/engine/dizhu/utils.py

23 lines
688 B
Python
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

def card_to_string(card_index):
"""
将牌的索引转换为具体牌型的字符串表示
:param card_index: 牌的索引0-53
:return: 具体牌型字符串
"""
suits = ['♠️', '♥️', '♦️', '♣️'] # 花色
values = ['3', '4', '5', '6', '7', '8', '9', '10', 'J', 'Q', 'K', 'A', '2']
if card_index < 52:
# 普通牌:计算花色和牌面值
value = values[card_index // 4]
suit = suits[card_index % 4]
return f"{suit}{value}"
elif card_index == 52:
return "小王"
elif card_index == 53:
return "大王"
else:
raise ValueError(f"无效的牌索引: {card_index}")