|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
- 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 = [x + y for x in list_two for y in list_one]
- 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([player_one,player_two,player_three])
-
- 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 = [x[-1] if len(x) != 3 else x[1:] 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([play_list == list_one[i:i+lenp] for i in range(0,leno-lenp)]):
- print("符合规则:单顺")
- continue
- elif all([play_list.count(x) == 2 for x in play_list]) and any([[play_list[j] for j in range(0,lenp,2)] == list_one[i:i+int(lenp/2)] for i in range(0,leno-int(lenp/2))]):
- print("符合规则:双顺")
- continue
- elif lenp >= 8:
- n_p = 2
- while play_list[3*n_p] == play_list[3*n_p+2]:
- n_p += 1
- if play_list[3*n_p-1] == "2":
- print("2不符合规则!")
- continue
- elif any([[play_list[j] for j in range(0,(3*n_p),3)] == list_one[i:i+n_p] 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[3*n_p:])) == n_p:
- print("符合规则:飞机带翅膀")
- continue
- elif lenp-3*n_p == n_p and len(set(play_list[3*n_p:])) == 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[0]) == 3:
- print("符合规则:三带一")
- continue
- elif lenp == 5 and play_list.count(play_list[0]) == 3:
- print("符合规则:三带二")
- continue
- elif lenp == 6 and play_list.count(play_list[0]) == 4:
- print("符合规则:四带二")
- continue
- else:
- print("5不符合规则!")
- continue
-
- else:
- print("6不符合规则!")
- continue
复制代码 |
|