Loading

Python斗地主

from random import shuffle

# 买牌环节
tf = ["\u2665", "\u2660", "\u2666", "\u2663"]
num = [3, 4, 5, 6, 7, 8, 9, 10, "J", "Q", "K", "A", 2]
poke_dict_a = {}
poke_dict_b = {}
poke_list = []
player_dict = {}
qdz_dict = {}
l = []
a = []
b = []


def maipai():
    global poke_list, poke_dict_a, poke_dict_b
    for j in num:
        for k in tf:
            poke_list.append(str(j) + k)
    poke_list.append("XXW")
    poke_list.append("DDW")
    print(len(poke_list), poke_list)
    for i in range(0, 54):
        poke_dict_a[poke_list[i]] = i + 1
        poke_dict_b[i + 1] = poke_list[i]
    print(poke_dict_a)  # 买牌结束


# 洗牌
# shuffle(poke_list)
# print(poke_list)


# 发牌
def fapai():
    global player_dict
    player_dict = {
        "player1": [poke_list[0:17], []],
        "player2": [poke_list[17:34], []],
        "player3": [poke_list[34:51], []],
        "dp": [poke_list[-3:], []]
    }
    print(player_dict)


# 码牌
def mapai():
    global player_dict, poke_dict_b, poke_dict_a
    for k, v in player_dict.items():
        l = []
        for i in v[0]:
            v[1].append(poke_dict_a[i])
            v[1] = sorted(v[1])
        for j in v[1]:
            l.append(poke_dict_b[j])
        player_dict[k] = l
    print(player_dict)


# 抢地主
def qdz():
    global qdz_dict, l, player_dict
    qdz_dict = {
        input("玩家1请下注:"): player_dict["player1"],
        input("玩家2请下注:"): player_dict["player2"],
        input("玩家3请下注:"): player_dict["player3"]
    }

    for i in qdz_dict:
        l.append(int(i))
    l = sorted(l)
    qdz_dict[str(l[-1])] += player_dict['dp']
    print(qdz_dict)


# 地主牌排序
def zpx():
    global a, b, poke_dict_a, poke_dict_b, qdz_dict
    for i in qdz_dict[str(l[-1])]:
        a.append(poke_dict_a[i])
    for i in sorted(a):
        b.append(poke_dict_b[i])
    qdz_dict[str(l[-1])] = b
    print(qdz_dict)

# 出牌

maipai()
shuffle(poke_list)
fapai()
mapai()
qdz()
zpx()
posted @ 2019-07-14 16:46  听雨危楼  阅读(872)  评论(0编辑  收藏  举报