该CPU和用户越来越重复的卡片。 我用的随机播放功能,以及流行。 有没有一种方法,以防止useer和CPU从得到反复卡。
下面是编译的程序的一个例子
这里是您的卡:1)10俱乐部2)钻石3)钻石4)俱乐部5)俱乐部的10的7打牌的6所述的图4,简单地在一个时间输入他们的电话号码之一。 完成后,输入空白2 1 3 4
你玩过:钻石的4俱乐部的10颗钻石俱乐部的7的6
CPU发挥:黑桃的黑桃的杰克杰克
正如你所看到的,用户被提示重复的“随机”卡和CPU玩重复的“随机”卡。
import random
import math
print("Gui-less poker sucks, but it sure is addicting probably")
if 1:
hcardss = [""]
hcardsc = [""]
hcardsh = [""]
ccardss = [""]
ccardsc = [""]
ccardsh = [""]
ingame = "true"
while (ingame == "true"):
undone = 5
while (undone > 0):
card = random.randint(1,52)
# print(card)
temp = card / 13
temp2 = card / 4
temp = math.floor(temp)
temp2 = math.floor(temp2)
temp = temp + 1
# temp2 = temp2 + 1
#print(temp)
#print(temp2)
# undone -= 1
hcardss.append(temp)
hcardsc.append(temp2)
if (temp == 1):
temp3 = " of Spades"
elif (temp == 2):
temp3 = " of Diamonds"
elif (temp == 3):
temp3 = " of Clubs"
else:
temp3 = " of Hearts"
if (temp2 == 10):
temp4 = "Jack"
elif (temp2 == 11):
temp4 = "Queen"
elif (temp2 == 12):
temp4 = "King"
elif (temp2 == 13):
temp4 = "Ace"
else:
temp4 = str(temp2 + 1)
# print("Your card was the " + temp4 + temp3)
hcardsh.append("The " + temp4 + temp3)
undone -= 1
undone = 5
while (undone > 0):
# THIS ONE IS THE COMPUTER
card = random.randint(1,52)
# print(card)
temp = card / 13
temp2 = card / 4
temp = math.floor(temp)
temp2 = math.floor(temp2)
temp = temp + 1
# temp2 = temp2 + 1
#print(temp)
#print(temp2)
# undone -= 1
ccardss.append(temp)
ccardsc.append(temp2)
if (temp == 1):
temp3 = " of Spades"
elif (temp == 2):
temp3 = " of Diamonds"
elif (temp == 3):
temp3 = " of Clubs"
else:
temp3 = " of Hearts"
if (temp2 == 10):
temp4 = "Jack"
elif (temp2 == 11):
temp4 = "Queen"
elif (temp2 == 12):
temp4 = "King"
elif (temp2 == 13):
temp4 = "Ace"
temp4 = str(temp2 + 1)
# print("Your card was the " + temp4 + temp3)
ccardsh.append("The " + temp4 + temp3)
undone -= 1
print()
print()
print()
print("Here are your cards:")
print("1) " + hcardsh[1])
print("2) " + hcardsh[2])
print("3) " + hcardsh[3])
print("4) " + hcardsh[4])
print("5) " + hcardsh[5])
print("To play cards, simply type their number one at a time. When done, input blank")
doneinput = "false"
hplay = [""]
while (doneinput == "false"):
latestinput = input("> ")
if (latestinput == ""):
doneinput = "true"
else:
if (int(latestinput) in hplay):
print("You already picked that one!")
else:
hplay.append(int(latestinput))
# print("The cards you played are " + str(hplay))
doneinput = "false"
cplay = [""]
while (doneinput == "false"):
latestinput = random.randint(1,5)
if (latestinput == ""):
doneinput = "true"
else:
if (int(latestinput) in cplay):
doneinput = "true"
else:
cplay.append(int(latestinput))
#print("So you played " + str(hplay))
#print("And the cpu played " + str(cplay))
#print("So you played the " + hcardsh[hplay[1]] + hcardsh[hplay[2]]
times = len(hplay)
# times = times - 1
hplayh = [""]
cplayh = [""]
sub = 1
print()
print()
print("You played:")
while (sub < times):
hplayh.append(hcardsh[hplay[sub]])
print(hcardsh[hplay[sub]])
sub += 1
sub = 1
times = len(cplay)
print()
print()
print("CPU played:")
while (sub < times):
cplayh.append(ccardsh[cplay[sub]])
print(ccardsh[cplay[sub]])
sub += 1
#print(str(hplayh))
#print(str(cplayh))
ingame = "false"