1)1副牌(52+2=54張)'''2)有大小王,用提供的國王和皇后的符號表示大小王
3)54張牌發給3個玩家,每人17張牌,並有3張底牌。
4)輸出3個玩家的牌,按照由小到大,黑紅梅方的順序。
5)輸出3張底牌
5)輸出每個玩家有幾個炸彈(4張面值一樣的牌,或者大小王在一起,為乙個炸彈。)
注:鬥地主發牌程式
player_num: 代表玩家數目
預設為3 可更改
times: 代表有幾副撲克牌
預設為1 可更改
leftover: 代表給地主留的底牌數目
預設為3 可更改
order 代表牌排列順序
引數值為1(預設值) 按照從小到大順序排列
引數值為0: 按照手機鬥地主排列順序 從大牌到小牌 黑紅梅方順序排列
'''
order = 1 # 牌排列順序 預設為1 即從小到大順序排列 0:從大到小排列
player_num = 3 # 三名玩家
n = 54 # 一副牌有54張(包含大小王)
times = 1 # 一副牌
leftover = 3 # 3張底牌
# -*- coding: utf-8 -*-
"""created on fri oct 12 10:33:57 2018
@author: liu zhendong
"""'''
注:鬥地主發牌程式
player_num: 代表玩家數目
預設為3 可更改
times: 代表有幾副撲克牌
預設為1 可更改
leftover: 代表給地主留的底牌數目
預設為3 可更改
order 代表牌排列順序
引數值為1(預設值) 按照從小到大順序排列
引數值為0: 按照手機鬥地主排列順序 從大牌到小牌 黑紅梅方順序排列
'''order = 1 # 牌排列順序 預設為1 即從小到大順序排列 0:從大到小排列
player_num = 3 # 三名玩家
n = 54 # 一副牌有54張(包含大小王)
times = 1 # 一副牌
leftover = 3 # 3張底牌
import random
card0 = list(range(0, n))
card0 = card0 * times
#print(card0)
schar = '♠♥♣♦♛♚'
card1 =
left = n * times
for i in range (n * times):
rdi = random.randint(0,left-1)
card0.pop(rdi)
left-=1
if left==0:
break
#print(card1)
player =
for i in range (player_num):
for i in range (n * times - leftover):
for i in range (n * times - leftover, n * times):
for i in range(player_num + 1):
# print(player[i])
player[i].sort()
if order == 0:
player[i].reverse()
# print(player[i])
card_output =
for i in range (player_num + 1):
for i in range (player_num + 1):
for j in range(len(player[i])):
if player[i][j] == 53 or player[i][j] == 52:
else:
cardnumber = (player[i][j] // 4 + 2) % 13 + 1
cardflower = 3 - player[i][j] % 4
if cardnumber == 1:
elif cardnumber == 11:
elif cardnumber == 12:
elif cardnumber == 13:
else:
#print(card_output)
for i in range (player_num):
print('玩家的手牌為:'.format(i+1),' '.join(card_output[i]))
print('剩餘的{}張底牌為:'.format(leftover),' '.join(card_output[player_num]))
#for i in range(player_num + 1):
# print(player[i])
# 統計炸彈數目
boom =
for i in range (player_num + 1):
count = 0
last_cardnumber = -1
for i in range (player_num + 1):
if 53 in player[i] and 52 in player[i]:
for data in player[i]:
if data == 53 or data == 52:
continue
else:
cardnumber = (data // 4 + 2) % 13 + 1
if last_cardnumber == cardnumber:
count += 1
else:
if count >= 3:
if last_cardnumber == 1:
last_cardnumber = 'a'.rjust(2)
elif last_cardnumber == 11:
last_cardnumber = 'j'.rjust(2)
elif last_cardnumber == 12:
last_cardnumber = 'q'.rjust(2)
elif last_cardnumber == 13:
last_cardnumber = 'k'.rjust(2)
else:
last_cardnumber = str(last_cardnumber).rjust(2)
count = 0
last_cardnumber = cardnumber
boom_num = 0 #炸彈數目
for i in range (player_num):
if len(boom[i]) != 0:
print('玩家有個炸彈,為:'.format(i+1,len(boom[i])),' '.join(boom[i]))
boom_num += 1
if len(boom[player_num]) != 0:
print('底牌中有個炸彈,為:'.format(len(boom[player_num])),' '.join(boom[player_num]))
boom += 1
if boom_num == 0:
print('本局未產生炸彈')
鬥地主發牌
鬥地主的發牌 a 鬥地主的發牌 實現模擬鬥地主的功能 1.組合牌 2.洗牌 3.發牌 4.看牌 public class doudizhu 定義4個花色陣列 string colors 定義整數變數,作為鍵出現 int index 2 遍歷陣列,花色 點數的組合,儲存到map集合 for strin...
C語言 鬥地主發牌程式
題目 仍然是小學期,就當娛樂 貼 include include include 函式宣告 void sortcards int int void showcards int int void changecard int int getonecard int cards 55 用於記錄每張牌是否被...
Java學習 模擬鬥地主發牌程式
public class pokergame string nums for string num nums 手動新增大小王 pokerbox.add pokerbox.add 洗牌 collections.shuffle pokerbox collections.shuffle pokerbox ...