#coding=utf8import random,timeendcards=[]cardlist1=[ "spade1", "club1", "heart1", "diamond1", "spade2","club2","heart2","diamond2","spade3","club3","h ...
#coding=utf8
import random,time
endcards=[]
cardlist1=[
"spade1", "club1", "heart1", "diamond1", "spade2","club2","heart2","diamond2","spade3","club3","heart3","diamond3",
"spade4", "club4", "heart4", "diamond4", "spade5","club5","heart5","diamond5","spade6","club6","heart6","diamond6",
"spade7", "club7", "heart7", "diamond7", "spade8","club8","heart8","diamond8","spade9","club9","heart9","diamond9",
"spade10","club10","heart10","diamond10","spadeJ","clubJ","heartJ","diamondJ","spadeQ","clubQ","heartQ","diamondQ",
"spadeK", "clubK", "heartK", "diamondK", "queen","king"
]
cardlist2={
"spade3":3, "club3":3, "heart3":3, "diamond3":3, "spade4":4, "club4":4, "heart4":4, "diamond4":4,
"spade5":5, "club5":5, "heart5":5, "diamond5":5, "spade6":6, "club6":6, "heart6":6, "diamond6":6,
"spade7":7, "club7":7, "heart7":7, "diamond7":7, "spade8":8, "club8":8, "heart8":8, "diamond8":8,
"spade9":9, "club9":9, "heart9":9, "diamond9":9, "spade10":10,"club10":10,"heart10":10,"diamond10":10,
"spadeJ":11,"clubJ":11,"heartJ":11,"diamondJ":11,"spadeQ":12, "clubQ":12, "heartQ":12,"diamondQ":12,
"spadeK":13,"clubK":13,"heartK":13,"diamondK":13,"spade1":14, "club1":14, "heart1":14, "diamond1":14,
"spade2":15,"club2":15,"heart2":15,"diamond2":15,"queen":16,"king":17
}
#洗牌
def myshuffle():
random.shuffle(cardlist1)
#隨機地主
def randDZ():
global player1,player2,player3
print "三張底牌是:%s" % sancards
DZ = random.randint(1, 3)
if DZ == 1:
print "玩家1是地主,玩家2是農民,玩家3是農民"
player1 = player1 + sancards
for i in range(0, 20):
for j in range(i + 1, 20):
if cardlist2[player1[i]] < cardlist2[player1[j]]:
player1[i], player1[j] = player1[j], player1[i]
# print "地主的牌是:%s" % player1
# print "玩家2的牌是:%s" % player2
# print "玩家3的牌是:%s" % player3
elif DZ == 2:
print "玩家2是地主,玩家1是農民,玩家3是農民"
player2 = player2 + sancards
for i in range(0, 20):
for j in range(i + 1, 20):
if cardlist2[player2[i]] < cardlist2[player2[j]]:
player2[i], player2[j] = player2[j], player2[i]
# print "地主的牌是:%s" % player2
# print "玩家1的牌是:%s" % player1
# print "玩家3的牌是:%s" % player3
elif DZ == 3:
print "玩家3是地主,玩家1是農民,玩家2是農民"
player3 = player3 + sancards
for i in range(0, 20):
for j in range(i + 1, 20):
if cardlist2[player3[i]] < cardlist2[player3[j]]:
player3[i], player3[j] = player3[j], player3[i]
# print "地主的牌是:%s" % player3
# print "玩家1的牌是:%s" % player1
# print "玩家2的牌是:%s" % player2
#判斷牌型
def cardtype(delplayer):
cardnums=len(delplayer)
while cardnums<=4:
if cardnums == 1:
print "玩家出的單牌是:%s" % delplayer[0]
break
elif cardnums == 2:
if cardlist2[delplayer[0]] == cardlist2[delplayer[1]]:
print "玩家出的對%s" %delplayer[0]
break
elif cardnums == 3:
if cardlist2[delplayer[0]] == cardlist2[delplayer[1]] == cardlist2[delplayer[2]]:
print "玩家出的三張%s" %delplayer[0]
break
elif cardnums == 4:
if cardlist2[delplayer[0]] == cardlist2[delplayer[1]] == cardlist2[delplayer[2]]==cardlist2[delplayer[3]]:
print "玩家出了炸%s" %delplayer[0]
break
else:
raw_input()
#打牌
def dapai():
global endcards
print " 開始打牌,打牌順序為玩家1>玩家2>玩家3輪流"
while len(player1)>0 and len(player2)>0 and len(player3)>0:
if len(endcards) > 0:
print "玩家1開始打牌"
print "玩家1的牌是:%s" % player1
delplayer1 = raw_input("請選擇玩家1要出的牌:").split(" ")
if len(endcards)==1 and len(delplayer1)==len(endcards) and cardlist2[delplayer1[0]]>cardlist2[endcards[0]]:
print "玩家出了單張%s"%delplayer1[0]
for i in range(len(delplayer1)): # 每次出的牌從原先的牌刪除
player1.remove(delplayer1[i])
elif len(endcards)==2 and len(delplayer1)==len(endcards) and cardlist2[delplayer1[0]]>cardlist2[endcards[0]] and cardlist2[delplayer1[0]]==cardlist2[delplayer1[1]]:
print "玩家2出了對%s"%delplayer1[0]
for i in range(len(delplayer1)): # 每次出的牌從原先的牌刪除
player1.remove(delplayer1[i])
elif len(endcards)==3 and len(delplayer1)==len(endcards) and cardlist2[delplayer1[0]]>cardlist2[endcards[0]] and cardlist2[delplayer1[0]] == cardlist2[delplayer1[1]] == cardlist2[delplayer1[2]]:
print "玩家2出了三張%s"%delplayer1[0]
for i in range(len(delplayer1)): # 每次出的牌從原先的牌刪除
player1.remove(delplayer1[i])
elif len(endcards)==4 and len(delplayer1)==len(endcards) and cardlist2[delplayer1[0]]>cardlist2[endcards[0]] and cardlist2[delplayer1[0]] == cardlist2[delplayer1[1]] == cardlist2[delplayer1[2]]==cardlist2[delplayer1[3]]:
print "玩家2出了四張%s"%delplayer1[0]
for i in range(len(delplayer1)): # 每次出的牌從原先的牌刪除
player1.remove(delplayer1[i])
else:
pass
del endcards[:]
if (len(player1) == 0):
print "玩家1為贏家,游戲結束"
break
print "玩家2開始出牌"
print "玩家2的牌是:%s" % player2
delplayer2= raw_input("請選擇玩家2要出的牌:").split(" ")
if len(delplayer1)==1 and len(delplayer1)==len(delplayer2) and cardlist2[delplayer2[0]]>cardlist2[delplayer1[0]]:
print "玩家出了單張%s"%delplayer2[0]
for i in range(len(delplayer2)): # 每次出的牌從原先的牌刪除
player2.remove(delplayer2[i])
elif len(delplayer1)==2 and len(delplayer1)==len(delplayer2) and cardlist2[delplayer2[0]]>cardlist2[delplayer1[0]] and cardlist2[delplayer2[0]]==cardlist2[delplayer2[1]]:
print "玩家2出了對%s"%delplayer2[0]
for i in range(len(delplayer2)): # 每次出的牌從原先的牌刪除
player2.remove(delplayer2[i])
elif len(delplayer1)==3 and len(delplayer1)==len(delplayer2) and cardlist2[delplayer2[0]]>cardlist2[delplayer1[0]] and cardlist2[delplayer2[0]] == cardlist2[delplayer2[1]] == cardlist2[delplayer2[2]]:
print "玩家2出了三張%s"%delplayer2[0]
for i in range(len(delplayer2)): # 每次出的牌從原先的牌刪除
player2.remove(delplayer2[i])
elif len(delplayer1)==4 and len(delplayer1)==len(delplayer2) and cardlist2[delplayer2[0]]>cardlist2[delplayer1[0]] and cardlist2[delplayer2[0]] == cardlist2[delplayer2[1]] == cardlist2[delplayer2[2]]==cardlist2[delplayer2[3]]:
print "玩家2出了四張%s"%delplayer2[0]
for i in range(len(delplayer2)): # 每次出的牌從原先的牌刪除
player2.remove(delplayer2[i])
else:
pass
del delplayer2[:]
if (len(player2) == 0):
print "玩家2為贏家,游戲結束"
break
print "玩家3開始出牌"
print "玩家3的牌是:%s" % player3
delplayer3 = raw_input("請選擇玩家3要出的牌:").split(" ")
if len(delplayer2)==1 and len(delplayer2)==len(delplayer3) and cardlist2[delplayer3[0]]>cardlist2[delplayer2[0]]:
print "玩家出了單張%s"%delplayer3[0]
for i in range(len(delplayer3)): # 每次出的牌從原先的牌刪除
player3.remove(delplayer3[i])
elif len(delplayer2)==2 and len(delplayer2)==len(delplayer3) and cardlist2[delplayer3[0]]>cardlist2[delplayer2[0]] and cardlist2[delplayer3[0]]==cardlist2[delplayer3[1]]:
print "玩家2出了對%s"%delplayer3[0]
for i in range(len(delplayer3)): # 每次出的牌從原先的牌刪除
player3.remove(delplayer3[i])
elif len(delplayer2)==3 and len(delplayer2)==len(delplayer3) and cardlist2[delplayer3[0]]>cardlist2[delplayer2[0]] and cardlist2[delplayer3[0]] == cardlist2[delplayer3[1]] == cardlist2[delplayer3[2]]:
print "玩家2出了三張%s"%delplayer3[0]
for i in range(len(delplayer3)): # 每次出的牌從原先的牌刪除
player3.remove(delplayer3[i])
elif len(delplayer2)==4 and len(delplayer2)==len(delplayer3) and cardlist2[delplayer3[0]]>cardlist2[delplayer2[0]] and cardlist2[delplayer3[0]] == cardlist2[delplayer3[1]] == cardlist2[delplayer3[2]]==cardlist2[delplayer3[3]]:
print "玩家2出了四張%s"%delplayer3[0]
for i in range(len(delplayer3)): # 每次出的牌從原先的牌刪除
player3.remove(delplayer3[i])
else:
pass
endcards=delplayer3
del delplayer3[:]
if (len(player3) == 0):
print "玩家3為贏家,游戲結束"
continue
#發牌,指定玩家1,玩家2,玩家3
def deal():
print " 開始洗牌!"
myshuffle()
print "loading..............."
time.sleep(3)
print " 洗牌完畢"
print " 開始發牌!"
print "loading................"
time.sleep(5)
global sancards
sancards=random.sample(cardlist1,3)
print "三張底牌是:%s"%sancards
cardlist1.remove(sancards[0]),cardlist1.remove(sancards[1]),cardlist1.remove(sancards[2])
global player1
player1=random.sample(cardlist1,17)
#將玩家1的牌重新按降序排列
for i in range(0,17):
for j in range(i+1,17):
if cardlist2[player1[i]]<cardlist2[player1[j]]:
player1[i],player1[j]=player1[j],player1[i]
print "玩家1的牌是:%s"%player1
for i in range(0,17):
cardlist1.remove(player1[i])
global player2
player2=random.sample(cardlist1,17)
# 將玩家2的牌重新按降序排列
for i in range(0,17):
for j in range(i+1,17):
if cardlist2[player2[i]]<cardlist2[player2[j]]:
player2[i],player2[j]=player2[j],player2[i]
print "玩家2的牌是:%s"%player2
for i in range(0,17):
cardlist1.remove(player2[i])
global player3
player3=random.sample(cardlist1,17)
# 將玩家3的牌重新按降序排列
for i in range(0, 17):
for j in range(i + 1, 17):
if cardlist2[player3[i]] < cardlist2[player3[j]]:
player3[i], player3[j] = player3[j], player3[i]
print "玩家3的牌是:%s"%player3
print " 發牌完畢,開始隨機地主。"
randDZ()
dapai()
deal()