|
找到一个以前突发奇想写的斗地主的程序,就给大伙发来看看,包含发牌:54张牌分别发三份,玩家出牌,以及控制两个电脑进行出牌(电脑跟托管差不多判断有大就出)
以下是运行程序:首先是随机选取地主,并且电脑出牌,显示玩家的牌,并且玩家进行出牌
玩家进行出牌
最后牌出完判断输赢
由于代码时间久远,应该还有一些bug(应该是关于判定出牌的问题)但懒得改了 
整体代码放不下了就简单放一个电脑进行出牌判定的代码吧,大概就是判断出牌是啥,判断手牌有啥,打得过就出,其中判断手牌的函数比如单张,对子四带二飞机等等就不一一列出了
- # 参数:
- # 列表array 玩家的牌
- # 列表last_cart 上次出牌 上次出牌默认符合规则
- # 作用 判断 AI 本次应该出什么类型的牌
- def count(array,last_cart,name):
- # print(last_cart,'666666666666')
- # 顺子和联对 比较特殊 就不按张数算了
- # print(last_cart,'6666')
- temp_list = delete_symbol(last_cart) # 去符号 因为jug_array函数不要符号
-
- # print(temp_list)
- if jug_array(temp_list) == 0:#顺子
- return straight(array,last_cart,name)
- elif Even_for(temp_list) == 0: # 连对
- return paired_count(array,last_cart,name)
- elif judge_airplane(temp_list) == 0:#干捞飞机
- return airplane_0(array,last_cart,name)
- elif judge_airplane(temp_list) == 1:#飞机带单
- return airplane_1(array,last_cart,name)
- elif judge_airplane(temp_list) == 2:#飞机带队
- return airplane_2(array,last_cart,name)
- else:
- if last_cart == []:#全都不要的时候的机器出牌
- return singel_count(array,last_cart,name)
- elif len(last_cart) == 1:# 出单
- return singel_count(array,last_cart,name)
- elif len(last_cart) == 2:# 出对子
- return double_count(array,last_cart,name)
- elif len(last_cart) == 3:# 出三张
- return triple_count(array,last_cart,name)
-
- elif len(last_cart) == 4:
- a = sort_array(last_cart) # 变成数字 按照大小 排列 如:[3,3,3,2]
- if a[0][1:] == a[-1][1:]: # 说明是炸弹
- return has_boom(array,last_cart,name)
- elif a[0][1:] != a[-1][1:]:# 说明是三代一
- return three_with_one(array,last_cart,name)
- elif len(last_cart) == 5:
- # a = sort_array(last_cart) # 变成数字 按照大小 排列 如:[3,3,3,2,2] sort 会吃数组 先不用了
- a = last_cart
- #
- if ((a[2][1:] != a[3][1:]) and (a[0][1:] == a[1][1:])) or ((a[2][1:] != a[3][1:]) and (a[-1][1:] == a[-2][1:])):
- # 说明是 三代二
- return three_with_two(array,last_cart,name)
- else:
- print('你来到了奇怪的地方 ugsiduhoi')
- elif len(last_cart) == 6:
- # a = sort_array(last_cart) # 变成数字 按照大小 排列 如:[3,3,3,2,2]
- a = last_cart
- if (a[2][1:] == a[3][1:]) and ((a[0][1:] != a[1][1:]) or (a[0][1:] != a[-1][1:]) or (a[-1][1:] != a[-2][1:])):
- # 说明是四代二单 [6,7,8,8,8,8] [6,8,8,8,8,9] [8,8,8,8,9,K]
- # print('这里是四代二')
- return four_with_1(array,last_cart,name)
- else:
- print('不要进来!淦')
- pass
- elif len(last_cart) == 8:#四代对
- return four_with_2(array,last_cart,name)
- else:
- return -1
复制代码
购买主题
已有 2 人购买
本主题需向作者支付 10 鱼币 才能浏览
|