斗地主发牌、出牌
from random import *from functools import *
player_one = input("请输入第一位游戏玩家名称:")
player_two = input("请输入第二位游戏玩家名称:")
player_three = input("请输入第三位游戏玩家名称:")
list_one = ["3","4","5","6","7","8","9","10","J","Q","K","1","2"]
list_two = ["♠","♦","♣","♥"]
list_three = ["☽","☀"]
def dealcard(player_one,player_two,player_three):
list_four =
list_four.extend(list_three)
length = len(list_four)
for i in range(3):
a = length + 1
newlistcard = []
for j in range(length):
b = randrange(1,a)
s = list_four.pop(b-1)
newlistcard.append(s)
a -= 1
list_four = newlistcard
cardone = sample(newlistcard , k = 17)
for each in cardone:
newlistcard.remove(each)
cardtwo = sample(newlistcard , k = 17)
for each in cardtwo:
newlistcard.remove(each)
cardthree = sample(newlistcard , k = 17)
for each in cardthree:
newlistcard.remove(each)
landlord = choice()
if landlord == player_one:
cardone.extend(newlistcard)
elif landlord == player_two:
cardtwo.extend(newlistcard)
else:
cardthree.extend(newlistcard)
strone = " ".join(cardone)
strtwo = " ".join(cardtwo)
strthree = " " .join(cardthree)
print(f"地主是;{landlord}")
print(f"[{player_one}]拿到的牌是:{strone}")
print(f"[{player_two}]拿到的牌是:{strtwo}")
print(f"[{player_three}]拿到的牌是:{strthree}")
dealcard(player_one,player_two,player_three)
while True:
playcard = input("请出牌(空格间隔,退出请输入Q):")
if playcard == "Q":
break
elif playcard == "":
print("不符合规则!")
continue
else:
play_list = if len(x) != 3 else x for x in playcard.split(" ")]
lenp = len(play_list)
leno = len(list_one)
if play_list == ["☽","☀"] or play_list == ["☀","☽"]:
print("符合规则:火箭")
continue
elif len(set(play_list)) == 1:
if lenp == 1:
print("符合规则:单牌")
continue
elif lenp == 2:
print("符合规则:对牌")
continue
elif lenp == 3:
print("符合规则:三张牌相同")
continue
elif lenp == 4:
print("符合规则:炸弹")
continue
else:
print("1不符合规则!")
continue
elif lenp >= 5 and any( for i in range(0,leno-lenp)]):
print("符合规则:单顺")
continue
elif all() and any([ for j in range(0,lenp,2)] == list_one for i in range(0,leno-int(lenp/2))]):
print("符合规则:双顺")
continue
elif lenp >= 8:
n_p = 2
while play_list == play_list:
n_p += 1
if play_list == "2":
print("2不符合规则!")
continue
elif any([ for j in range(0,(3*n_p),3)] == list_one for i in range(0,leno-n_p)]):
if lenp == 3*n_p:
print("符合规则:三顺(飞机)")
continue
elif lenp-3*n_p == 2*n_p and len(set(play_list)) == n_p:
print("符合规则:飞机带翅膀")
continue
elif lenp-3*n_p == n_p and len(set(play_list)) == n_p:
print("符合规则:飞机带翅膀")
continue
else:
print("3不符合规则!")
continue
else:
print("4不符合规则!")
continue
elif len(set(play_list)) == 2:
if lenp == 4 and play_list.count(play_list) == 3:
print("符合规则:三带一")
continue
elif lenp == 5 and play_list.count(play_list) == 3:
print("符合规则:三带二")
continue
elif lenp == 6 and play_list.count(play_list) == 4:
print("符合规则:四带二")
continue
else:
print("5不符合规则!")
continue
else:
print("6不符合规则!")
continue 怎么打开.npy文件呀 怎么打开.npy文件呀
页:
[1]