写段python代码 判断十三道的五对三条(带王牌,王可以变成然后牌)
时间: 2023-11-22 09:56:03 浏览: 38
以下是一个简单的 Python 代码示例,用于判断十三道中的五对三条(带王牌):
```python
# 定义牌组,其中用数字代表不同的牌,如 14 表示大王,13 表示小王
cards = [3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 14, 13, 9]
# 统计牌数
card_counts = {}
for card in cards:
if card in card_counts:
card_counts[card] += 1
else:
card_counts[card] = 1
# 判断是否符合五对三条的条件
pairs = 0
triplets = 0
kings = 0
for count in card_counts.values():
if count == 2:
pairs += 1
elif count == 3:
triplets += 1
elif count == 4:
pairs += 2
elif count == 5:
pairs += 2
triplets += 1
elif count == 6:
pairs += 4
elif count == 7:
pairs += 4
triplets += 1
elif count == 8:
pairs += 6
elif count == 9:
pairs += 6
triplets += 1
elif count == 10:
pairs += 8
elif count == 11:
pairs += 8
triplets += 1
elif count == 12:
pairs += 10
elif count == 13:
pairs += 10
triplets += 1
elif count == 14:
kings += 1
if (pairs == 5 and triplets == 3 and kings <= 2) or (pairs == 6 and triplets == 2 and kings == 2):
print("符合五对三条的条件")
else:
print("不符合五对三条的条件")
```
在上面的代码中,我们首先定义了一副牌,然后统计了每种牌出现的次数,接着根据牌数计算了对子、三张和王的数量,最后根据五对三条的规则判断是否符合条件。