【发布时间】:2021-03-22 14:36:45
【问题描述】:
如前所述,我正在创建一个扑克游戏,但某些扑克牌“if”语句被多次满足,这不应该发生。
"""
PPPPP OOOOO K K EEEEEEE RRRRRR
P P O O K K E R R
P P O O K K E R R
P P O O KK EEE R R
PPPPP O O K K E RRRRRR
P O O K K E R R
P O O K K E R R
P OOOOO K K EEEEEEE R R
Congratulations! My name is James Chrisaldi, and you found the source code for my new game, Poker! Here, you can view a few of my notes to see how I created this game. You can tinker with it, it won't affect the original version. Have fun!
"""
import random
import time
cards = ["Ace of Hearts", "Ace of Diamonds", "Ace of Clubs", "Ace of Spades", "King of Hearts", "King of Diamonds", "King of Clubs", "King of Spades", "Queen of Spades", "Queen of Hearts", "Queen of Clubs", "Queen of Diamonds", "Jack of Hearts", "Jack of Diamonds", "Jack of Clubs", "Jack of Spades", "Ten of Hearts", "Ten of Diamonds", "Ten of Clubs", "Ten of Spades", "Nine of Hearts", "Nine of Diamonds", "Nine of Clubs", "Nine of Spades", "Eight of Hearts", "Eight of Diamonds", "Eight of Clubs", "Eight of Spades", "Seven of Hearts", "Seven of Diamonds", "Seven of Clubs", "Seven of Spades", "Six of Hearts", "Six of Diamonds", "Six of Clubs", "Six of Spades", "Five of Hearts", "Five of Diamonds", "Five of Clubs", "Five of Spades", "Four of Hearts", "Four of Diamonds", "Four of Clubs", "Four of Spades", "Three of Hearts", "Three of Diamonds", "Three of Clubs", "Three of Spades", "Two of Hearts", "Two of Diamonds", "Two of Clubs", "Two of Spades"]
# Player
print("Your game is loading...")
time.sleep(5)
name = input("What is your username? \n")
p1c = random.choice(cards)
cards.remove(p1c)
p2c = random.choice(cards)
cards.remove(p2c)
player_money = 2000000
bb = ["Check", "Bet", "Bet"]
bot_bet = random.choice(bb)
bc = ["Check", "Check", "Bet"]
bot_check = random.choice(bc)
# John Smith
js1c = random.choice(cards)
cards.remove(js1c)
js2c = random.choice(cards)
cards.remove(js2c)
js_money = 2000000
# Dora the Explorer
de1c = random.choice(cards)
cards.remove(de1c)
de2c = random.choice(cards)
cards.remove(de2c)
de_money = 2000000
# Jeff Besos
jb1c = random.choice(cards)
cards.remove(jb1c)
jb2c = random.choice(cards)
cards.remove(jb2c)
jb_money = 2000000
bet = ["Sure, I'll bet.", "I'll bet.", "Check."]
call = ["Sure, I'll call.", "I'll call.", "Fold."]
ca = random.choice(call)
b = random.choice(bet)
check = ["Sure, I'll bet.", "Check.", "I'll check for now."]
c = random.choice(check)
burn1 = random.choice(cards)
cards.remove(burn1)
card1 = random.choice(cards)
cards.remove(card1)
card2 = random.choice(cards)
cards.remove(card2)
card3 = random.choice(cards)
cards.remove(card3)
burn2 = random.choice(cards)
cards.remove(burn2)
card4 = random.choice(cards)
cards.remove(card4)
burn3 = random.choice(cards)
cards.remove(burn3)
card5 = random.choice(cards)
cards.remove(card5)
high_bet_money = ["50000", "60000", "75000", "85000", "100000"]
med_bet_money = ["30000", "40000", "50000", "60000", "75000"]
low_money = ["10000", "20000", "30000", "40000"]
high_bet = random.choice(high_bet_money)
# Functions
def jeff_besos_bet_call():
if "Ace" in jb1c and "Ace" in jb2c:
print(ca)
if ca == "Sure, I'll call." or b == "I'll call.":
time.sleep(2)
jb_money = jb_money - low_bet
print("Jeff Besos calls the bet of " + low_bet + " .")
player_bet = input(name + ", do you call, raise, or fold?\n")
def dora_explorer_bet_call():
if "Ace" in de1c and "Ace" in de2c:
print(ca)
if ca == "Sure, I'll call." or b == "I'll call.":
time.sleep(2)
de_money = de_money - low_bet
print("Dora the Explorer calls the bet of " + low_bet + " . Jeff Besos, do you call the bet of " + low_bet + " ?")
ca = random.choice(call)
jeff_besos_bet_call()
def john_smith_start():
if "Ace" in js1c and "Ace" in js2c:
print(b)
if b == "Sure, I'll bet." or b == "I'll bet.":
time.sleep(2)
print("How much do you bet?")
time.sleep(1.5)
print(low_bet)
time.sleep(2)
js_money = js_money - low_bet
print("John Smith bets " + low_bet + " .Dora the Explorer, do you call the " + low_bet + " ?")
dora_explorer_bet_call()
if "King" in js1c and "King" in js2c:
print(b)
if b == "Sure, I'll bet." or b == "I'll bet.":
time.sleep(2)
print("How much do you bet?")
time.sleep(1.5)
print(high_bet)
time.sleep(2)
print("John Smith bets " + high_bet + " . Dora the Explorer, do you call the " + high_bet + " ?")
dora_explorer_bet_call()
if "Queen" in js1c and "Queen" in js2c:
print(b)
if b == "Sure, I'll bet." or b == "I'll bet.":
time.sleep(2)
print("How much do you bet?")
time.sleep(1.5)
print(high_bet)
time.sleep(2)
print("John Smith bets " + high_bet + " . Dora the Explorer, do you call the " + high_bet + " ?")
dora_explorer_bet_call()
if "Ten" in js1c and "Ten" in js2c:
print(b)
if b == "Sure, I'll bet." or b == "I'll bet.":
time.sleep(2)
print("How much do you bet?")
time.sleep(1.5)
print(high_bet)
time.sleep(2)
print("John Smith bets " + high_bet + " . Dora the Explorer, do you call the " + high_bet + " ?")
dora_explorer_bet_call()
if "Nine" in js1c and "Nine" in js2c:
print(b)
if b == "Sure, I'll bet." or b == "I'll bet.":
time.sleep(2)
print("How much do you bet?")
time.sleep(1.5)
print(high_bet)
time.sleep(2)
print("John Smith bets " + high_bet + " . Dora the Explorer, do you call the " + high_bet + " ?")
dora_explorer_bet_call()
if "Eight" in js1c and "Eight" in js2c:
print(b)
if b == "Sure, I'll bet." or b == "I'll bet.":
time.sleep(2)
print("How much do you bet?")
time.sleep(1.5)
print(high_bet)
time.sleep(2)
print("John Smith bets " + high_bet + " . Dora the Explorer, do you call the " + high_bet + " ?")
dora_explorer_bet_call()
if "Seven" in js1c and "Seven" in js2c:
print(c)
if b == "Sure, I'll bet.":
time.sleep(2)
print("How much do you bet?")
time.sleep(1.5)
print(high_bet)
time.sleep(2)
print("John Smith bets " + high_bet + " . Dora the Explorer, do you call the " + high_bet + " ?")
dora_explorer_bet_call()
if "Six" in js1c and "Six" in js2c:
print(c)
if b == "Sure, I'll bet.":
time.sleep(2)
print("How much do you bet?")
time.sleep(1.5)
print(high_bet)
time.sleep(2)
print("John Smith bets " + high_bet + " . Dora the Explorer, do you call the " + high_bet + " ?")
dora_explorer_bet_call()
if "Five" in js1c and "Five" in js2c:
print(c)
if b == "Sure, I'll bet.":
time.sleep(2)
print("How much do you bet?")
time.sleep(1.5)
print(high_bet)
time.sleep(2)
print("John Smith bets " + high_bet + " . Dora the Explorer, do you call the " + high_bet + " ?")
dora_explorer_bet_call()
if "Four" in js1c and "Four" in js2c:
print(c)
if b == "Sure, I'll bet.":
time.sleep(2)
print("How much do you bet?")
time.sleep(1.5)
print(high_bet)
time.sleep(2)
print("John Smith bets " + high_bet + " . Dora the Explorer, do you call the " + high_bet + " ?")
dora_explorer_bet_call()
if "Three" in js1c and "Five" in js2c:
print(c)
if b == "Sure, I'll bet.":
time.sleep(2)
print("How much do you bet?")
time.sleep(1.5)
print(high_bet)
time.sleep(2)
print("John Smith bets " + high_bet + " . Dora the Explorer, do you call the " + high_bet + " ?")
dora_explorer_bet_call()
if "Two" in js1c and "Four" in js2c:
print(c)
if b == "Sure, I'll bet.":
time.sleep(2)
print("How much do you bet?")
time.sleep(1.5)
print(high_bet)
time.sleep(2)
print("John Smith bets " + high_bet + " . Dora the Explorer, do you call the " + high_bet + " ?")
dora_explorer_bet_call()
if "Spades" in js1c and "Spades" in js2c:
print(c)
if "Spades" in js1c and "Spades" in card1 and "Spades" not in js2c or "Spades" in js2c and "Spades" in card1 and "Spades" not in js1c:
print(c)
if "Spades" in js1c and "Spades" in card2 and "Spades" not in js2c or "Spades" in js2c and "Spades" in card2 and "Spades" not in js1c:
print(c)
if "Spades" in js1c and "Spades" in card3 and "Spades" not in js2c or "Spades" in js2c and "Spades" in card3 and "Spades" not in js1c:
print(c)
if "Clubs" in js1c and "Clubs" in card1 and "Clubs" not in js2c or "Clubs" in js2c and "Clubs" in card1 and "Clubs" not in js1c:
print(c)
if "Clubs" in js1c and "Clubs" in card2 and "Clubs" not in js2c or "Clubs" in js2c and "Clubs" in card2 and "Clubs" not in js1c:
print(c)
if "Clubs" in js1c and "Clubs" in card3 and "Clubs" not in js2c or "Clubs" in js2c and "Clubs" in card3 and "Clubs" not in js1c:
print(c)
if "Hearts" in js1c and "Hearts" in card1 and "Hearts" not in js2c or "Hearts" in js2c and "Hearts" in card1 and "Hearts" not in js1c:
print(c)
if "Hearts" in js1c and "Hearts" in card2 and "Hearts" not in js2c or "Hearts" in js2c and "Hearts" in card2 and "Hearts" not in js1c:
print(c)
if "Hearts" in js1c and "Hearts" in card3 and "Hearts" not in js2c or "Hearts" in js2c and "Hearts" in card3 and "Hearts" not in js1c:
print(c)
if "Diamonds" in js1c and "Diamonds" in card1 and "Diamonds" not in js2c or "Diamonds" in js2c and "Diamonds" in card1 and "Diamonds" not in js1c:
print(c)
if "Diamonds" in js1c and "Diamonds" in card2 and "Diamonds" not in js2c or "Diamonds" in js2c and "Diamonds" in card2 and "Diamonds" not in js1c:
print(c)
if "Diamonds" in js1c and "Diamonds" in card3 and "Diamonds" not in js2c or "Diamonds" in js2c and "Diamonds" in card3 and "Diamonds" not in js1c:
print(c)
if "Clubs" in js1c and "Clubs" in js2c:
print(c)
if "Hearts" in js1c and "Hearts" in js2c:
print(c)
if "Diamonds" in js1c and "Diamonds" in js2c:
print(c)
else:
print(c)
print("\n")
print("Your cards are " + p1c + " and " + p2c + ".")
time.sleep(3)
print("You currently have",player_money,"dollars")
time.sleep(3)
print("")
print("The cards on the board are: ")
time.sleep(0.3)
print(card1)
time.sleep(0.3)
print(card2)
time.sleep(0.3)
print(card3)
time.sleep(4)
print("John Smith, do you check or bet?")
time.sleep(2)
john_smith_start()
# Save the code for later
"""
"""
有时结果:
Your game is loading...
What is your username?
James
Your cards are Five of Spades and Jack of Spades.
You currently have 2000000 dollars
The cards on the board are:
Four of Clubs
King of Spades
Eight of Diamonds
John Smith, do you check or bet?
I'll check for now.
I'll check for now.
[Program finished]
当您启动程序时,它会打印 print("Your game is loading..."),而实际上不是,但我将它放在那里是为了在我的游戏中添加一些逼真的部分。
然后在假加载五秒钟后,它会要求用户输入用户名。在我的游戏中,没有存储用户的;每次使用后游戏会自动重置。
还有一些关于存储bot卡的变量; “烧掉”,或丢弃的牌,桌上的牌等等。它还会从存储所有张卡片的变量中删除这些使用过的卡片,因此它们不会再次使用。
然后,它为机器人设置投注变量,这很容易。
然后是构成游戏玩法的功能。机器人角色的名字是:约翰·史密斯、探险家朵拉和杰夫·贝索斯。这些是用于机器人的随机名称。
机器人说“我现在检查一下。”两次,因为它有我放置的卡的多种变体。这在最终版本上看起来不太好。我该如何解决这个问题?
【问题讨论】:
-
这个“杰夫·贝索斯”角色是谁?
-
一个机器人。我只是想出了一个用于喜剧目的的随机名称。
-
您应该将您的代码缩减为minimal reproducible example。这里有太多的事情可以期待人们涉水而过。
-
Besos 在西班牙语中的意思是亲吻,所以我会离开 Jeff Besos。更有趣
-
哈!现在我不会改变它!谢谢你。
标签: python if-statement random