|
|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
- #导入数据库
- import time
- import random
- import math
- #初始化变量
- run = True
- _count = 0
- show_list = []
- choose = "0"
- #定义函数声明全局变量
- def show(list):
- global show_list
- show_list = []
- for _count in range(0,len(list)):
- if list[_count] < 11:
- show_list.append(str(list[_count]))
- elif list[_count] == 11:
- show_list.append("J")
- elif list[_count] == 12:
- show_list.append("Q")
- elif list[_count] == 13:
- show_list.append("K")
- elif list[_count] == 14:
- show_list.append("A")
- elif list[_count] == 15:
- show_list.append(2)
- elif list[_count] == 16:
- show_list.append("小王")
- else:
- show_list.append("大王")
- def show_cards(landlord):
- if landlord == 1:
- global player_cards
- player_cards.extend(midden_cards)
- player_cards = sorted(player_cards,reverse=True)
- else:
- global robot1_cards
- robot1_cards.extend(midden_cards)
- robot1_cards = sorted(robot1_cards,reverse=True)
- #经典三人斗地主
- print("经典三人斗地主")
- #人机对决
- while run == True:
- #初始化卡牌库
- cards = [3,3,3,3,4,4,4,4,5,5,5,5,6,6,6,6,7,7,7,7,8,8,8,8,9,9,9,9,10,10,10,10,11,11,11,11,12,12,12,12,13,13,13,13,14,14,14,14,15,15,15,15,16,17]
- midden_cards = []
- for _count in range(3):
- idx = random.randint(0,len(cards) - 1)
- card = cards[idx]
- del cards[idx]
- midden_cards.append(card)
- midden_cards = sorted(midden_cards)
- player_cards = []
- for _count in range(17):
- idx = random.randint(0,len(cards) - 1)
- card = cards[idx]
- del cards[idx]
- player_cards.append(card)
- player_cards = sorted(player_cards,reverse=True)
- show(player_cards)
- print("你的初始牌是:"+str(show_list))
- robot1_cards = []
- for _count in range(17):
- idx = random.randint(0,len(cards) - 1)
- card = cards[idx]
- del cards[idx]
- robot1_cards.append(card)
- robot1_cards = sorted(robot1_cards,reverse=True)
- robot2_cards = []
- for _count in range(17):
- idx = random.randint(0,len(cards) - 1)
- card = cards[idx]
- del cards[idx]
- robot2_cards.append(card)
- robot2_cards = sorted(robot2_cards,reverse=True)
-
- #抢地主
- choose = "0"
- turn = random.randint(1,3)
- if turn == 1:
- while choose != "1" and choose != "2":
- choose = str(input("叫不叫地主?(1叫/2不叫)"))
-
- if choose == "1":
- landlord = 1
- else:
- landlord = 2
- print("小明叫地主")
- elif turn == 2:
- while choose != "1" and choose != "2":
- choose = str(input("小明叫地主,小红不抢,你抢不抢?(1抢/2不抢)"))
-
- if choose == "1":
- landlord = 1
- else:
- landlord = 2
- print("小红不抢地主")
- else:
- while choose != "1" and choose != "2":
- choose = str(input("小红不叫地主,你叫不叫?(1叫/2不叫)"))
-
- if choose == "1":
- landlord = 1
- else:
- landlord = 2
- print("小明叫地主")
- if landlord == 1:
- print("你是地主")
- else:
- print("小明是地主")
-
- #揭示底牌
- show_cards(landlord)
- show(midden_cards)
- print("底牌是:"+str(show_list))
- show(player_cards)
- print("你当前的牌是:"+str(show_list))
-
- #揭示人机牌
- show(robot1_cards)
- print("小明的牌是:"+str(show_list))
- show(robot2_cards)
- print("小红的牌是:"+str(show_list))
- input()
-
复制代码 |
|