私は Python で簡単で汚いポーカー ゲームを作成していますが、どのプレーヤーがハンドに勝つかを判断するのに苦労しています。カードを配り、0 ~ 8 がハイ カード (ストレート フラッシュ) に対応するようにハンドの「価値」を決定し、次に各ハンドをユニークにする重要な要素を決定する関数があります。
私が問題を抱えているのは、同じハンド タイプ (ペア、ツー ペアなど) のプレイヤーが 2 人以上いる場合にどちらが勝つかを判断することです。キッカー。
データを保存し、必要に応じてすべてを比較する良い方法を判断するのに苦労しています。ハンドの値などをチェックする関数をすべて含めたくはありません。長くなりすぎるからです。私は、このデータをどのように保存して比較するかについて人々の考え、特に同様の値を持つ手 (太字のもの) について言及されていることに本当に興味があります。
各プレーヤーの手札は、次の形式のプレーヤー番号でキー付けされた辞書エントリによって表されます。
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]