在我的扑克游戏中如何确定获胜者是错误的。
我尝试检查玩家得分值是否已从循环中重置 并且所有其他与逻辑相关的变量也是如此
TableCards = []
for Card in Flop:
TableCards.append(Card)
TableCards.append(Turn)
TableCards.append(River)
for Card in Player.Hand:
TableCards.append(Card)
TableCardValues = []
TableCardSuits = []
for Card in TableCards:
TableCardValues.append(Card.Value)
TableCardSuits.append(Card.Suit)
TableCardValues.sort()
TableCardSuits.sort()
ArrayLengthI = len(TableCardValues)
Straight = False
Flush = False
Pairs = []
ThreeOfAKinds = []
FourOfAKinds = []
StraightCount = 0
PlayerHandValues = []
DealerHandValues = []
for Card in Player.Hand:
PlayerHandValues.append(Card.Value)
for Card in Dealer.Hand:
DealerHandValues.append(Card.Value)
for X in range(ArrayLengthI - 1):
if TableCardValues[X + 1] == TableCardValues[X] + 1:
StraightCount += 1
if StraightCount >= 5:
Straight == True
for Suit in TableCardSuits:
if TableCardSuits.count(Suit) >= 5:
Flush = True
for Value in set(TableCardValues):
if TableCardValues.count(Value) == 2:
Pairs.append(Value)
elif TableCardValues.count(Value) == 3:
ThreeOfAKinds.append(Value)
elif TableCardValues.count(Value) == 4:
FourOfAKinds.append(Value)
if Straight == True or Flush == True:
if Straight == True and Flush == True:
Player.HandScore = PokerHands.StraightFlush * max(PlayerHandValues)
elif Straight == True:
Player.HandScore = PokerHands.Straight * max(PlayerHandValues)
elif Flush == True:
Player.HandScore = PokerHands.Flush * max(PlayerHandValues)
elif FourOfAKinds != []:
Player.HandScore = PokerHands.FourOfAKind * max(PlayerHandValues)
elif ThreeOfAKinds != []:
if len(Pairs) >= 1:
Player.HandScore = PokerHands.FullHouse * max(PlayerHandValues)
else:
Player.HandScore = PokerHands.ThreeOfAKind * max(PlayerHandValues)
elif len(Pairs) == 2:
Player.HandScore = PokerHands.TwoPair * max(PlayerHandValues)
elif len(Pairs) == 1:
Player.HandScore = PokerHands.OnePair * max(PlayerHandValues)
else:
Player.HandScore = PokerHands.HighCard * max(PlayerHandValues)
TableCardsDealer = []
TableCardValuesDealer = []
TableCardSuitsDealer = []
for Card in Flop:
TableCardsDealer.append(Card)
TableCardsDealer.append(Turn)
TableCardsDealer.append(River)
DealerStraight = False
DealerFlush = False
DealerStraightCount = 0
DealerPairs = []
DealerThreeOfAKinds = []
DealerFourOfAKinds = []
for Card in Dealer.Hand:
TableCardsDealer.append(Card)
for Card in TableCards:
TableCardValuesDealer.append(Card.Value)
TableCardSuitsDealer.append(Card.Suit)
TableCardSuitsDealer.sort()
TableCardValuesDealer.sort()
TableCardsDealerLength = len(TableCardSuitsDealer)
for X in range(TableCardsDealerLength - 1):
if TableCardValuesDealer[X + 1] == TableCardValuesDealer[X] + 1:
DealerStraightCount += 1
if DealerStraightCount >= 5:
DealerStraight == True
for Suit in TableCardSuitsDealer:
if TableCardSuitsDealer.count(Suit) >= 5:
DealerFlush == True
for Value in set(TableCardValuesDealer):
if TableCardValuesDealer.count(Value) == 2:
DealerPairs.append(Value)
elif TableCardValuesDealer.count(Value) == 3:
DealerThreeOfAKinds.append(Value)
elif TableCardValuesDealer.count(Value) == 4:
DealerFourOfAKinds.append(Value)
if DealerStraight == True or DealerFlush == True:
if DealerStraight == True and DealerFlush == True:
Dealer.HandScore = PokerHands.StraightFlush * max(DealerHandValues)
elif DealerStraight == True:
Dealer.HandScore = PokerHands.Straight * max(DealerHandValues)
elif DealerFlush == True:
Dealer.HandScore = PokerHands.Flush * max(DealerHandValues)
elif DealerFourOfAKinds != []:
Dealer.HandScore = PokerHands.FourOfAKind * max(DealerHandValues)
elif DealerThreeOfAKinds != []:
if len(DealerPairs) >= 1:
Dealer.HandScore = PokerHands.FullHouse * max(DealerHandValues)
else:
Dealer.HandScore = PokerHands.ThreeOfAKind * max(DealerHandValues)
elif len(DealerPairs) == 2:
Dealer.HandScore = PokerHands.TwoPair * max(DealerHandValues)
elif len(DealerPairs) == 1:
Dealer.HandScore = PokerHands.OnePair * max(DealerHandValues)
else:
Dealer.HandScore = PokerHands.HighCard * max(DealerHandValues)
if Player.HandScore > Dealer.HandScore:
print("Well Done, sir. You've won.")
Player.Money += Pot
Pot = 0
elif Player.HandScore < Dealer.HandScore:
print("I Apologise, but you've lost.")
Dealer.Money += Pot
Pot = 0
elif Player.HandScore == Dealer.HandScore:
print("You've tied")
Pot = 0
Junk = input()
Player.HandScore = 0
Dealer.HandScore = 0
system("cls")
没有错误消息,但似乎可以确定获胜者错了,我无法确切查明原因。