我正在用python制作一个快速而肮脏的扑克游戏,并且无法确定哪个玩家赢得了这手牌。我有发牌的功能,以 0-8 对应于高牌的方式确定手的“价值” - 同花顺,然后是使每手独特的关键部分。
我遇到的问题是当有两个或更多玩家的牌型相同(对子、两对等)时,确定谁赢,更糟糕的是,当他们有相同的对子时,我必须下去看看踢球者。
我无法确定一种存储数据的好方法,并根据需要将它们进行比较。我不想包括我所有的功能来检查手值等等,因为它会变得太长。我真的很感兴趣人们对如何存储和比较这些数据的想法,尤其是提到的具有相似值的手(粗体字)
每个玩家的手牌都由一个字典条目表示,由表格中的玩家编号键入
mydict = {(1 :(2,'Spades)), (2 :(3,'Diamonds')), etc}
players = 5
# Creates deck of cards and deals to each player
Cards = Shuffle_Deck(Suits,Values,1)
All_Players, Cards = deal_hand(players,5,Cards)
# scores and orders hands
def order_hands(All_Players):
rank_hands = []
for i in range(1,len(All_Players)+1):
rank_hands.append([i,score_hand(All_Players[i],printhand=False,printvalue=False)])
sorted_hands = rank_hands[:]
sorted_hands.sort(key=lambda x: x[1][0],reverse=True)
return sorted_hands
Sorted_Hands = order_hands(All_Players)
#print Sorted_Hands
def who_Wins(Sorted_Hands):
Tied_Hands = []
winning_index = Sorted_Hands[0][1][0]
for i in range(len(Sorted_Hands)):
if Sorted_Hands[i][1][0] == winning_index:
# print Sorted_Hands[i]
Tied_Hands.append([Sorted_Hands[i][0],Sorted_Hands[i][1][1:]])
return winning_index,Tied_Hands
winning_index,Tied_Hands = who_Wins(Sorted_Hands)
Tied_Hands.sort(key=lambda x: x[1], reverse=True)
print Tied_Hands
for i in range(len(Tied_Hands)):
vals = [val for (val,suit) in All_Players[Tied_Hands[i][0]]]
print 'vals',sorted(vals,reverse=True)
#for hands in Tied_Hands:
# if
print Tied_Hands[0][0]