斗地主2

#coding=utf8import random,sys,time# def randDZ():#     DZ=random.randint(1,3)#     if DZ==1:#         print "玩家1是地主"#         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#     elif DZ==2:#         print "玩家2是地主"#         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#     else:#         print "玩家3是地主"#         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

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 JDZ():#         DZ = input("你是否要叫地主?y/n")#         if DZ == ‘y‘:#             DZcards = player1 + sancards#             print "你现在是地主了,玩家2和3是农民"#             print "三张底牌是:%s"%sancards#             print "你的牌是:%s" % DZcards#             print "玩家2的牌是:%s"%player2#             print "玩家3的牌是:%s" %player3#         else:#             a = random.randint(0, 1)#             if a == 0:#                 DZcards = player2 + sancards#                 print "三张底牌是:%s" % sancards#                 print "你的牌是:%s" % player1#                 print "玩家2叫地主,你和玩家3是农民"#                 print "玩家3的牌是:%s" % player3#                 print "地主家的牌是:%s"%DZcards#             else:#                 DZcards = player3 + sancards#                 print "玩家3叫地主,你和玩家2是农民"#                 print "三张底牌是:%s" % sancards#                 print "你的牌是:%s" % player1#                 print "玩家2的牌是:%s" % player2#                 print "地主家的牌是:%s" % DZcards

def deal():    print "                            开始洗牌!"    myshuffle()    print "loading..............."    time.sleep(3)    print "                            洗牌完毕"    print    print "                            开始发牌!"    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 "loading................"    time.sleep(5)    print "                      发牌完毕,开始随机地主。"

#开始随机地主,

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    print "开始打牌,打牌顺序为玩家1>玩家2>玩家3轮流"    while len(player1) > 0 and len(player2) > 0 and len(player3) > 0:        if len(player1) > 0:            print "玩家1开始打牌"            print "玩家1的牌是:%s" % player1            delcards = raw_input("请选择玩家1要出的牌:").split(" ")            # 每次出的牌从原先的牌删除            for i in range(len(delcards)):                player1.remove(delcards[i])                del delcards[:]                if (len(player1) == 0):                    print "玩家1为赢家,游戏结束"                    break            print "玩家2开始出牌"            print "玩家2的牌是:%s" % player2            delcards = raw_input("请选择玩家2要出的牌:").split(" ")            for i in range(len(delcards)):                player2.remove(delcards[i])                del delcards[:]                if (len(player1) == 0):                    print "玩家2为赢家,游戏结束"                    break            print "玩家3开始出牌"            print "玩家3的牌是:%s" % player2            delcards = raw_input("请选择玩家3要出的牌:").split(" ")            for i in range(len(delcards)):                player3.remove(delcards[i])                del delcards[:]                if (len(player1) == 0):                    print "玩家3为赢家,游戏结束"                    continue    else:        print "game over"

deal()
时间: 2024-10-10 17:21:56

斗地主2的相关文章

斗地主 (NOIP2015 Day1 T3)

斗地主 思路 :读入时注意将A作为第14张牌,因为它可以连在K后, 总体思路为 先出炸弹和四带二 再出三带一 再把对牌和单牌出完 记录并更新Answer,后枚举顺子,并继续向下搜索. 注意:弄明白题意,题目描述不太清楚....另外,我觉的牌的花色只是能用来区分大小王.另外在整顺子之前也可以用贪心来搞其他类似四带二,三带一等的牌 #include <iostream> #include <cstdio> #include <cstring> using namespace

结对项目之小游戏编程(斗地主)

一.题目简介    本次的项目是编写一个斗地主的小游戏,实现语言:java:主要完成了GUI设计.计时线程.算法.本次项目的主要目的是对算法的学习.算法分析在心得里面. 技术难点:1.图片的移动    2.计时线程的设定   3.对牌的分割,必须考虑到优先拆分方案,将权值低的拆分方案舍去. 4.在删除的时候遇到问题了,删除不了. 二.结对分工及过程 本次结对项目的成员有两个,张国伟:负责对GUI界面的设计,完成功能:洗牌功能,发牌功能,打牌功能的图片的位移处理,基本打牌的桌面等等. 我主要负责对

Libgdx: android单机斗地主支持局域网wifi联网的网络模块核心代码

这个作品是我最近写的,结合我的毕业设计的通信模块和之前的单机版斗地主.我已经上架到豌豆荚了,贴了点广告,看看能不能赚点茶钱.可是一点也不乐观.因此我想分享给大家源码.只要不用于商业. 下面先贴网络模块的核心代码,第一次写这种逻辑用的udp, 经验不够,没有写的那么好看. 这里是我上架的apk,大家下载来试试也无妨: 地址 http://www.wandoujia.com/apps/com.hj.joker package com.hj.net; import java.io.ByteArrayI

Android斗地主棋牌游戏牌桌实现源码下载

本次给大家分享下Android斗地主棋牌游戏牌桌实现源码下载如下:为了节约内存资源,每张扑克牌都是剪切形成的,当然这也是当前编程的主流方法. 1.主Activity    package com.bison;            import android.app.Activity;      import android.content.pm.ActivityInfo;      import android.os.Bundle;      import android.view.Wind

洛谷 P2668 斗地主

P2668 斗地主 统计单牌和对牌的数量 然后 凑顺子,能凑就凑 还有四带balabala和三带balabala 1 #include<bits/stdc++.h> 2 using namespace std; 3 int n,t,s[15],ans,a,b; 4 5 inline void read(int &now) 6 { 7 char ch=getchar(); now=0; 8 while(ch>'9'||ch<'0') ch=getchar(); 9 while

洛谷—— P2668 斗地主

https://www.luogu.org/problem/show?pid=2668 题目描述 牛牛最近迷上了一种叫斗地主的扑克游戏.斗地主是一种使用黑桃.红心.梅花.方片的A到K加上大小王的共54张牌来进行的扑克牌游戏.在斗地主中,牌的大小关系根据牌的数码表示如下:3<4<5<6<7<8<9<10<J<Q<K<A<2<小王<大王,而花色并不对牌的大小产生影响.每一局游戏中,一副手牌由n张牌组成.游戏者每次可以根据规定的

自己写的一部分斗地主的程序,没有去写界面,临时是用黑框来显示的

这几天比較空,所以想写一点东西. 斗地主的程序一直以来都想写,但感觉规则推断比較复杂,一直没有较多的时间来写. 这次主要是把跟牌和牌型的推断写出来了.写了一个比較弱智的AI,属于有牌就出的那种.对于AI算法,临时没有什么好的想法,所以打算临时放一放. 后期补上界面之后再进行优化. 在这就把基本的函数和算法列出来吧. 首先是主程序,主要控制显示和游戏的流程. #include <iostream> #include "PokerDesk.h" using namespace

妞一个斗地主发牌程序!!!

学习java三个星期,利用所学的知识做了一个三人斗地主发牌程序,闲话少叙,上代码 1 import java.util.ArrayList; 2 import java.util.Collections; 3 import java.util.List; 4 5 /** 6 * 三人斗地主程序 功能:将一副牌随机分发给地主(20张牌),农民A(17张牌),农民B (17张牌) 7 * 步骤:1.洗牌阶段:将54张牌储存到ArraryList 容器中(批量储存,for循环) 8 * 2.发牌阶段:

P2668 斗地主

P2668 斗地主 题目描述 牛牛最近迷上了一种叫斗地主的扑克游戏.斗地主是一种使用黑桃.红心.梅花.方片的A到K加上大小王的共54张牌来进行的扑克牌游戏.在斗地主中,牌的大小关系根据牌的数码表示如下:3<4<5<6<7<8<9<10<J<Q<K<A<2<小王<大王,而花色并不对牌的大小产生影响.每一局游戏中,一副手牌由n张牌组成.游戏者每次可以根据规定的牌型进行出牌,首先打光自己的手牌一方取得游戏的胜利. 现在,牛牛只想

基础算法(搜索):NOIP 2015 斗地主

Description 牛牛最近迷上了一种叫斗地主的扑克游戏.斗地主是一种使用黑桃.红心.梅花.方片的A到K加上大小王的共54张牌来进行的扑克牌游戏.在斗地主中,牌的大小关系根据牌的数码表示如下:3<4<5<6<7<8<9<10<J<Q<K<A<2<小王<大王,而花色并不对牌的大小产生影响.每一局游戏中,一副手牌由n张牌组成.游戏者每次可以根据规定的牌型进行出牌,首先打光自己的手牌一方取得游戏的胜利.现在,牛牛只想知道,对