鱼C论坛

 找回密码
 立即注册
查看: 3414|回复: 2

[学习笔记] 斗地主发牌、出牌

[复制链接]
发表于 2022-11-20 23:03:17 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
  1. from random import *
  2. from functools import *

  3. player_one = input("请输入第一位游戏玩家名称:")
  4. player_two = input("请输入第二位游戏玩家名称:")
  5. player_three = input("请输入第三位游戏玩家名称:")

  6. list_one = ["3","4","5","6","7","8","9","10","J","Q","K","1","2"]
  7. list_two = ["♠","♦","♣","♥"]
  8. list_three = ["☽","☀"]
  9. def dealcard(player_one,player_two,player_three):
  10.     list_four = [x + y for x in list_two for y in list_one]
  11.     list_four.extend(list_three)   

  12.     length = len(list_four)   
  13.     for i in range(3):
  14.         a = length + 1
  15.         newlistcard = []               
  16.         for j in range(length):
  17.             b = randrange(1,a)
  18.             s = list_four.pop(b-1)
  19.             newlistcard.append(s)
  20.             a -= 1
  21.         list_four = newlistcard

  22.     cardone = sample(newlistcard , k = 17)
  23.     for each in cardone:
  24.         newlistcard.remove(each)
  25.     cardtwo = sample(newlistcard , k = 17)
  26.     for each in cardtwo:
  27.         newlistcard.remove(each)
  28.     cardthree = sample(newlistcard , k = 17)
  29.     for each in cardthree:
  30.         newlistcard.remove(each)
  31.     landlord = choice([player_one,player_two,player_three])
  32.    
  33.     if landlord == player_one:
  34.         cardone.extend(newlistcard)
  35.     elif landlord == player_two:
  36.         cardtwo.extend(newlistcard)
  37.     else:
  38.         cardthree.extend(newlistcard)
  39.     strone = " ".join(cardone)
  40.     strtwo = " ".join(cardtwo)
  41.     strthree = " " .join(cardthree)
  42.     print(f"地主是;{landlord}")
  43.     print(f"[{player_one}]拿到的牌是:{strone}")
  44.     print(f"[{player_two}]拿到的牌是:{strtwo}")
  45.     print(f"[{player_three}]拿到的牌是:{strthree}")

  46. dealcard(player_one,player_two,player_three)

  47. while True:
  48.     playcard = input("请出牌(空格间隔,退出请输入Q):")
  49.     if playcard == "Q":
  50.         break
  51.     elif playcard == "":
  52.         print("不符合规则!")
  53.         continue
  54.     else:
  55.         play_list = [x[-1] if len(x) != 3 else x[1:] for x in playcard.split(" ")]
  56.         lenp = len(play_list)
  57.         leno = len(list_one)
  58.         if play_list == ["☽","☀"] or play_list == ["☀","☽"]:
  59.             print("符合规则:火箭")
  60.             continue
  61.         elif len(set(play_list)) == 1:
  62.             if lenp == 1:
  63.                 print("符合规则:单牌")
  64.                 continue
  65.             elif lenp == 2:
  66.                 print("符合规则:对牌")
  67.                 continue
  68.             elif lenp == 3:
  69.                 print("符合规则:三张牌相同")
  70.                 continue
  71.             elif lenp == 4:
  72.                 print("符合规则:炸弹")
  73.                 continue
  74.             else:
  75.                 print("1不符合规则!")
  76.                 continue
  77.             
  78.         elif lenp >= 5 and any([play_list == list_one[i:i+lenp] for i in range(0,leno-lenp)]):
  79.             print("符合规则:单顺")
  80.             continue
  81.         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))]):
  82.             print("符合规则:双顺")
  83.             continue
  84.         elif lenp >= 8:
  85.             n_p = 2
  86.             while play_list[3*n_p] == play_list[3*n_p+2]:
  87.                 n_p += 1
  88.             if play_list[3*n_p-1] == "2":
  89.                 print("2不符合规则!")
  90.                 continue
  91.             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)]):
  92.                 if lenp == 3*n_p:
  93.                     print("符合规则:三顺(飞机)")
  94.                     continue
  95.                 elif lenp-3*n_p == 2*n_p and len(set(play_list[3*n_p:])) == n_p:
  96.                     print("符合规则:飞机带翅膀")
  97.                     continue
  98.                 elif lenp-3*n_p == n_p and len(set(play_list[3*n_p:])) == n_p:
  99.                     print("符合规则:飞机带翅膀")
  100.                     continue
  101.                 else:
  102.                     print("3不符合规则!")
  103.                     continue
  104.             else:
  105.                 print("4不符合规则!")
  106.                 continue
  107.         
  108.         elif len(set(play_list)) == 2:
  109.             if lenp == 4 and play_list.count(play_list[0]) == 3:
  110.                 print("符合规则:三带一")
  111.                 continue
  112.             elif lenp == 5 and play_list.count(play_list[0]) == 3:
  113.                 print("符合规则:三带二")
  114.                 continue
  115.             elif lenp == 6 and play_list.count(play_list[0]) == 4:
  116.                 print("符合规则:四带二")
  117.                 continue
  118.             else:
  119.                 print("5不符合规则!")
  120.                 continue
  121.             
  122.         else:
  123.             print("6不符合规则!")
  124.             continue
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2022-11-21 06:46:57 | 显示全部楼层
怎么打开.npy文件呀
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2022-11-21 06:47:36 | 显示全部楼层
怎么打开.npy文件呀
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-4-22 23:55

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表