我正在做我的心脏游戏编程,但我对如何计算每张卡片中的所有分数感到困惑 这是有价值的卡片,其他卡片有 0 价值
>>> card_value ={"QS":13,"2H":1,"3H":1,"4H":1,"5H":1,"6H":1,"7H":1,"8H":1,"9H":1,"0H":1,"JH":1,"QH":1,"KH":1,"AH":1,"0D": -10}
但是如果一组列表中的所有子列表都包含一颗心,那么分数将为-26,如果一组列表中的所有子列表都包含一颗心和 10 颗钻石(“0D”),那么分数将为-36
例子
>>> list1 = [['QD', '7D', '5H', '0D'], ['7C', '6D', '2H', 'KS'], ['8S', '3D', '9C', 'KD'], ['4D', '9D', 'KH', '4C'],['7S', 'JH', '4H', 'QC'], ['2S', 'KC', 'AD', 'AC'], ['JD', '8D', 'QS', '6H'], ['AH', '9H', '9S', '6S'],['5S', '0S', 'JC', '2D'],['5D', '8H', '0C', '7H'], ['JS', '6C', '2C', 'AS'], ['3S', '4S', '5C', '0H'], ['3C', 'QH', '3H', '8C']]
输出将是 -36
>>> list2 = ["5C","QS","JH"]
输出将是 14
这是我到目前为止所尝试的:
def score(list,score=0):
for cards in list:
if cards in card_value.keys():
score += card_value[cards]
if cards == "H":
score = -36
if cards == "H" or "0D":
score = -26
return score