跳到正文

剪贴板

剪贴板 ix8k2chz

原文
剪贴板信息

剪贴板信息

收录
更新
Python
import random
import time
#from Players import *       # 玩家类
class Player(object):
    def __init__(self, name):
        self.name = name
        self.cards = []
        self.points = 0
        self.TLEd = False
    def SetPlayerTLE(self, flag):
        # flag是布尔变量
        self.TLEd = flag
    def GetPlayerTLE(self):
        return self.TLEd
    def AddPoint(self, point = 1):
        self.points += point
    def GetPoint(self):
        return self.points
    def AddCard(self, cd):
        # cd是字符串
        self.cards.append(cd)
    def Find(self, CardName):
        # 不提供except
        return self.cards.index(CardName)
    def GetCardName(self, index):
        return self.cards[index]
    def UseCard(self, index):
        return self.cards.pop(index)
    def GetCardTotal(self):
        return len(self.cards)
    def GetName(self):
        return self.name
    def GetCard(self):
        result = ""
        for i in self.cards:
            result += i
            result += ", "
        return result[:-2]
    def GetCardList(self):
        return self.cards
    def GetCardNameTotal(self, name):
        return self.cards.count(name)
    def HaveCard(self, name):
        try:
            a = self.cards.index(name)
            return True
        except ValueError:
            return False
    def __str__(self):
        return self.name
    def __lt__(self, other):
        return self.points >= other.points

# 卡牌类型(字典)
CardDic = {'AC':[3, 12], 'WA':[3, 12], 'TLE':[2, 4], 'MLE':[2, 4], 'CE':[2, 4], 'RE':[2, 4], 'UK':[2, 4], 'UKE':[3, 4], 'Empty':[1, 8], 'Coin':[5, 4], 'Judge':[3, 1]}
#CardDic = {'AC':[3, 3], 'WA':[3, 3], 'TLE':[2, 2], 'MLE':[2, 2], 'CE':[2, 2], 'RE':[2, 12], 'UK':[2, 2], 'UKE':[3, 2], 'Empty':[1, 4], 'Coin':[5, 4], 'Judge':[3, 1]}
# 电脑用弃牌顺序
FoldOrder = ['Empty', 'RE', 'CE', 'TLE', 'MLE', 'UK', 'AC', 'WA', 'UKE', 'Coin', 'Judge']

# 输出用
def TabPrint(layer):
    for i in range(layer):
        print("    ", end = '')

# 主函数
if __name__ == '__main__':
    # 游戏设置
    Running = True
    Clockwise = False        # True为顺时针, False为逆时针
    now = -1 if Clockwise else 1
    TotalRound = 0

    # 玩家初始化
    players = [Player('1P(你)'), Player('2P'), Player('3P'), Player('4P')]
    TotalPlayers = len(players)

    # 牌堆初始化
    pile = []
    for item in CardDic:
        for i in range(CardDic[item][1]):
            pile.append(item)
            random.shuffle(pile)
    # print(pile)

    # 玩家执行回合
    def RunPlayer(index):
        global Clockwise
        if index == 0:
            # 玩家
            cdtype = None
            while True:
                TabPrint(2)
                print("你的手牌:" + players[index].GetCard())
                TabPrint(2)
                print("请指定要打出的牌(输入'pass'以跳过)。")
                while True:         # 输入循环
                    TabPrint(2)
                    ope = input(">")
                    if ope == 'pass':
                        break
                    if ope in players[index].GetCardList():
                        if ope == 'Empty' or ope == 'UK' or ope == 'UKE' or ope == 'WA':    # 这些牌不能单打
                            TabPrint(2)
                            print("[错误]这张牌不能打。")
                            continue
                        if ope == 'CE' and players[index].GetCardTotal() == 1:
                            TabPrint(2)
                            print("[错误]你没有多余的手牌了。")
                            continue
                        break
                    else:
                        TabPrint(2)
                        print("[错误]你没有这张牌。")
                        continue
                # 输入初步处理,包括pass、Coin与Judge
                if ope == 'pass':
                    return
                tar = (index + 1)%TotalPlayers if Clockwise else (index - 1 + TotalPlayers)%TotalPlayers        # 根据方向确定下一个玩家
                CEtar = None
                cdindex = players[index].Find(ope)
                players[index].UseCard(cdindex)
                if ope == 'Judge':      # 处理Judge
                    TabPrint(2)
                    print("*你使用了 " + ope + "。")
                    time.sleep(1)
                    TabPrint(2)
                    print("请指定目标卡牌。")
                    while True:
                        TabPrint(2)
                        jo = input(">")
                        if jo in CardDic:
                            ope = jo
                            break
                        else:
                            TabPrint(2)
                            print("[错误]无效的输入。")
                if ope == 'Coin':       # 处理Coin
                    TabPrint(2)
                    print("*你使用了 " + ope + "。")
                    time.sleep(1)
                    players[index].AddPoint(3)
                    TabPrint(2)
                    print("[" + players[index].GetName() + "+3分]")
                    continue
                if ope == 'CE':         # 处理CE
                    TabPrint(2)
                    print("*你使用了 " + ope + "。")
                    time.sleep(1)
                    #print(players[index].GetCard())
                    TabPrint(2)
                    print("请指定目标玩家(输入序号)。")
                    while True:
                        TabPrint(2)
                        jo = input(">")
                        try:
                            jo = int(jo)
                            if players[jo-1].GetCardTotal() == 0:
                                TabPrint(2)
                                print("[错误]TA没有手牌了。")
                            elif 0 < jo - 1 < TotalPlayers:
                                CEtar = jo - 1
                                break
                            else:
                                TabPrint(2)
                                print("[错误]无效的输入。")
                        except (IndexError, TypeError, ValueError):
                            TabPrint(2)
                            print("[错误]无效的输入。")
                # 询问是否使用UK/UKE
                eff = True
                UKEd = False
                cseq = [[":)", index]]
                sp = index
                np = index
                np = (np + 1)%TotalPlayers if Clockwise else (np - 1 + TotalPlayers)%TotalPlayers
                while np != sp:
                    if ope == 'AC':
                        break
                    if np == 0 and (players[np].HaveCard("UK") or players[np].HaveCard("UKE") or players[np].HaveCard("Judge")):    # 玩家
                        TabPrint(3)
                        print("你要使用UK(" + str(players[np].GetCardNameTotal('UK')) + ")/UKE(" + str(players[np].GetCardNameTotal('UKE')) + ")吗?输入你想使用的牌(输入'pass'以跳过)。")
                        joi = ''
                        while True:
                            TabPrint(3)
                            joi = input(">")
                            if joi == 'pass':
                                break
                            elif (joi in ["UKE", "Judge"]) and players[np].HaveCard(joi) or (joi == 'UK' and UKEd == False and players[np].HaveCard(joi)):
                                break
                            else:
                                TabPrint(3)
                                print("[错误]无效的输入。")
                        if joi == 'pass':
                            np = (np + 1)%TotalPlayers if Clockwise else (np - 1 + TotalPlayers)%TotalPlayers       # 根据游戏方向确定下一个玩家
                            continue
                        if joi == 'UK':
                            TabPrint(3)
                            print("*你使用了" + players[np].UseCard(players[np].Find(joi)) + "。")
                            time.sleep(1)
                            eff = False if eff else True
                            sp = np
                            cseq.append(['UK', np])
                        if joi == 'UKE':
                            TabPrint(3)
                            print("*你使用了" + players[np].UseCard(players[np].Find(joi)) + "。")
                            time.sleep(1)
                            eff = False if eff else True
                            UKEd = True
                            sp = np
                            cseq.append(['UKE', np])
                        if joi == 'Judge':
                            TabPrint(3)
                            print("*你将" + players[np].UseCard(players[np].Find(joi)) + "当做UKE使用了。")
                            time.sleep(1)
                            eff = False if eff else True
                            UKEd = True
                            sp = np
                            cseq.append(['UKE', np])
                    else:               # 电脑
                        prob = random.randint(1,6)              # 概率
                        # Debug
                        # print("(debug)UKNow:" + str(np) + ", sp:" + str(sp) + ", probility:" + str(prob))
                        # Debug
                        if players[np].HaveCard("UK") and UKEd == False and \
                           ((prob%3 == 0 and np != tar and np != CEtar and eff == False) or \
                            (ope in ['TLE', 'RE'] and np == tar and eff == True) or \
                            (ope == 'MLE' and prob%3 == 0 and eff == False) or \
                            (ope == 'CE' and np == CEtar and eff == True)):        # 电脑使用UK概率1/3
                            TabPrint(3)
                            print("*" + players[np].GetName() + "使用了" + players[np].UseCard(players[np].Find('UK')) + "。")
                            time.sleep(1)
                            eff = False if eff else True
                            sp = np
                            cseq.append(['UK', np])
                        elif  players[np].HaveCard("UKE") and \
                             ((prob%3 == 0 and np != tar and np != CEtar and eff == False) or \
                            (ope in ['TLE', 'RE'] and np == tar and eff == True) or \
                            (ope == 'MLE' and prob%3 == 0 and eff == False) or \
                            (ope == 'CE' and np == CEtar and eff == True)):                      # 电脑使用UKE概率1/3
                            TabPrint(3)
                            print("*" + players[np].GetName() + "使用了" + players[np].UseCard(players[np].Find('UKE')) + "。")
                            time.sleep(1)
                            eff = False if eff else True
                            UKEd = True
                            sp = np
                            cseq.append(['UKE', np])
                        elif  players[np].HaveCard("Judge") and \
                             ((prob%3 == 0 and np != tar and np != CEtar and eff == False) or \
                            (ope in ['TLE', 'RE'] and np == tar and eff == True) or \
                            (ope == 'MLE' and prob%3 == 0 and eff == False) or \
                            (ope == 'CE' and np == CEtar and eff == True)):
                            TabPrint(3)
                            print("*" + players[np].GetName() + "将" + players[np].UseCard(players[np].Find('Judge')) + "当做UKE使用了。")
                            time.sleep(1)
                            eff = False if eff else True
                            UKEd = True
                            sp = np
                            cseq.append(['UKE', np])
                        else:
                            pass
                    np = (np + 1)%TotalPlayers if Clockwise else (np - 1 + TotalPlayers)%TotalPlayers       # 根据游戏方向确定下一个玩家
                # print(cseq)
                for ns in range(len(cseq)-1, -1, -2):
                    if cseq[ns][0] == 'UKE':
                        players[cseq[ns][1]].AddPoint(2)
                        players[cseq[ns-1][1]].AddPoint(-1)
                        TabPrint(3)
                        print("[" + players[cseq[ns][1]].GetName() + "的UKE生效:" + players[cseq[ns][1]].GetName() + "+2分;" + players[cseq[ns-1][1]].GetName() + "-1分]")
                # 输入进一步处理
                if eff == False:        # 牌没有生效
                    continue
                if ope == 'MLE':        # 处理MLE
                    TabPrint(2)
                    print("*你使用了 " + ope + "。")
                    time.sleep(1)
                    TabPrint(2)
                    if len(pile) == 1:
                        players[index].AddCard(pile.pop(len(pile)-1))
                        print("[" + players[index].GetName() + "+1张牌(牌堆剩余:" + str(len(pile)) + "张牌)]")
                    elif len(pile) == 0:
                        print("*你什么也没摸到。")
                    else:
                        players[index].AddCard(pile.pop(len(pile)-1))
                        players[index].AddCard(pile.pop(len(pile)-1))
                        print("[" + players[index].GetName() + "+2张牌(牌堆剩余:" + str(len(pile)) + "张牌)]")
                    continue
                if ope == 'RE':         # 处理RE
                    TabPrint(2)
                    print("*你使用了 " + ope + "。")
                    time.sleep(1)
                    Clockwise = not Clockwise
                    nowOrder = "顺时针(正序)" if Clockwise else "逆时针(逆序)"
                    TabPrint(2)
                    print("[" + players[index].GetName() + "调整游戏方向为 " + nowOrder + "]")
                    continue
                if ope == 'TLE':        # 处理TLE
                    players[tar].SetPlayerTLE(True)
                    TabPrint(2)
                    print("*你对" + players[tar].GetName() + "使用了 " + ope + "。")
                    time.sleep(1)
                    TabPrint(2)
                    print("*" + players[tar].GetName() + "被跳过了。")
                    continue
                if ope == 'CE':         # 处理CE
                    if players[index].GetCardTotal() == 0:
                        TabPrint(2)
                        print("*你没有手牌了。")
                        players[index].AddCard("CE")
                        continue
                    TabPrint(2)
                    print("请指定要交换的手牌。")
                    cjo = None
                    while True:
                        TabPrint(2)
                        cjo = input(">")
                        if players[index].HaveCard(cjo):
                            break
                        TabPrint(2)
                        print("[错误]你没有这张牌。")
                    tempa = players[index].UseCard(players[index].Find(cjo))
                    tempb = players[CEtar].UseCard(random.randint(0, players[CEtar].GetCardTotal()-1))
                    players[CEtar].AddCard(tempa)
                    players[index].AddCard(tempb)
                    time.sleep(1)
                    TabPrint(2)
                    print("[获得" + tempb + "x1]")
                    continue
                if ope == 'AC':         # 处理AC
                    # 询问是否使用WA/UK/UKE
                    eff = index
                    UKed = False
                    UKEd = False
                    cseq = [["WA", index]]
                    sp = index
                    np = index
                    np = (np + 1)%TotalPlayers if Clockwise else (np - 1 + TotalPlayers)%TotalPlayers
                    while np != sp:
                        if np == 0 and (players[np].HaveCard("WA") or players[np].HaveCard("UK") or players[np].HaveCard("UKE") or players[np].HaveCard("Judge")):    # 玩家
                            TabPrint(3)
                            print("你要使用WA(" + str(players[np].GetCardNameTotal('WA')) + ")/UK(" + str(players[np].GetCardNameTotal('UK')) + ")/UKE(" + str(players[np].GetCardNameTotal('UKE')) + ")吗?输入你想使用的牌(输入'pass'以跳过)。")
                            joi = ''
                            while True:
                                TabPrint(3)
                                joi = input(">")
                                if joi == 'pass':
                                    break
                                elif ((joi in ["UKE", "Judge"]) and players[np].HaveCard(joi)) or \
                                     (joi == 'UK' and UKEd == False and players[np].HaveCard(joi)) or \
                                     (joi == 'WA' and UKed == False and players[np].HaveCard(joi)):
                                    break
                                else:
                                    TabPrint(3)
                                    print("[错误]无效的输入。")
                            if joi == 'pass':
                                np = (np + 1)%TotalPlayers if Clockwise else (np - 1 + TotalPlayers)%TotalPlayers       # 根据游戏方向确定下一个玩家
                                continue
                            if joi == 'UK':
                                TabPrint(3)
                                print("*你使用了" + players[np].UseCard(players[np].Find(joi)) + "。")
                                time.sleep(1)
                                UKed = True
                                sp = np
                                cseq.append(['UK', np])
                            if joi == 'UKE':
                                TabPrint(3)
                                print("*你使用了" + players[np].UseCard(players[np].Find(joi)) + "。")
                                time.sleep(1)
                                UKed = True
                                UKEd = True
                                sp = np
                                cseq.append(['UKE', np])
                            if joi == 'Judge':
                                TabPrint(3)
                                print("*你使用了" + players[np].UseCard(players[np].Find(joi)) + "。")
                                time.sleep(1)
                                TabPrint(3)
                                print("请指定目标卡牌(WA/UK/UKE)。")
                                jjo = None
                                while True:
                                    TabPrint(3)
                                    jjo = input(">")
                                    if (jjo == 'WA' and UKed == False) or (jjo == 'UK' and UKEd == False) or jjo == 'UKE':
                                        break
                                    else:
                                        TabPrint(3)
                                        print("[错误]无效的输入。")
                                TabPrint(3)
                                print("*你将Judge当做" + jjo + "使用了。")
                                time.sleep(1)
                                if jjo == 'UK':
                                    UKed = True
                                if jjo == 'UKE':
                                    UKEd = True
                                    UKed = True
                                sp = np
                                cseq.append([jjo, np])
                            if joi == 'WA':
                                TabPrint(3)
                                print("*你使用了" + players[np].UseCard(players[np].Find(joi)) + "。")
                                time.sleep(1)
                                sp = np
                                cseq.append(['WA', np])
                        else:               # 电脑
                            prob = random.randint(1,6)              # 概率
                            # Debug
                            # print("(debug)UKNow:" + str(np) + ", sp:" + str(sp) + ", probility:" + str(prob))
                            # Debug
                            if players[np].HaveCard('WA') and UKed == False and prob%6 != 1:         # WA:5/6
                                TabPrint(3)
                                print("*" + players[np].GetName() + "使用了" + players[np].UseCard(players[np].Find('WA')) + "。")
                                time.sleep(1)
                                eff = np
                                sp = np
                                cseq.append(['WA', np])
                            elif  players[np].HaveCard("UK") and UKEd == False and (prob%3 == 1 or cseq[len(cseq)-1-1][1] == np):                      # 电脑使用UK概率1/3
                                TabPrint(3)
                                print("*" + players[np].GetName() + "使用了" + players[np].UseCard(players[np].Find('UK')) + "。")
                                time.sleep(1)
                                eff = cseq[len(cseq)-1-1][1]
                                UKed = True
                                sp = np
                                cseq.append(['UK', np])
                            elif  players[np].HaveCard("UKE") and UKEd == False and (prob%3 == 1 or cseq[len(cseq)-1-1][1] == np):                      # 电脑使用UKE概率1/3
                                TabPrint(3)
                                print("*" + players[np].GetName() + "使用了" + players[np].UseCard(players[np].Find('UKE')) + "。")
                                time.sleep(1)
                                eff = cseq[len(cseq)-1-1][1]
                                UKed = True
                                UKEd = True
                                sp = np
                                cseq.append(['UKE', np])
                            elif  players[np].HaveCard("Judge") and (prob%3 == 1 or cseq[len(cseq)-1-1][1] == np):        # Judge同UKE
                                TabPrint(3)
                                print("*" + players[np].GetName() + "将" + players[np].UseCard(players[np].Find('Judge')) + "当做UKE使用了。")
                                time.sleep(1)
                                eff = cseq[len(cseq)-1-1][1]
                                UKEd = True
                                UKed = True
                                sp = np
                                cseq.append(['UKE', np])
                            else:
                                pass
                        np = (np + 1)%TotalPlayers if Clockwise else (np - 1 + TotalPlayers)%TotalPlayers       # 根据游戏方向确定下一个玩家
                    # print(cseq)
                    for nsi in range(len(cseq)-1, -1, -2):
                        #print(nsi)
                        if cseq[nsi][0] == 'UKE':
                            players[cseq[nsi][1]].AddPoint(2)
                            players[cseq[nsi-1][1]].AddPoint(-1)
                            TabPrint(3)
                            print("[" + players[cseq[nsi][1]].GetName() + "的UKE生效:" + players[cseq[nsi][1]].GetName() + "+2分;" + players[cseq[nsi-1][1]].GetName() + "-1分]")
                            nsi -= 2
                    eff = index
                    for ns in range(len(cseq)-1, -1, -1):
                        #print(ns)
                        if cseq[ns][0] == 'UK' or cseq[ns][0] == 'UKE':
                            ns -= 2
                            if ns == -1:
                                eff = -1
                                break
                            eff = cseq[ns][1]
                        if cseq[ns][0] == 'WA':
                            eff = cseq[ns][1]
                            break
                    # 输入进一步处理
                    if eff == index:        # AC生效
                        players[index].AddPoint(3)
                        TabPrint(2)
                        print("[" + players[index].GetName() + "的AC生效:" + players[index].GetName() + "+3分]")
                    elif eff != -1:
                        players[eff].AddPoint(3)
                        TabPrint(2)
                        print("[" + players[eff].GetName() + "的WA生效:" + players[eff].GetName() + "+3分]")
                    else:
                        pass

        else:
            # 电脑出牌

            # Debug
            # TabPrint(2)
            # print("(debug)" + players[index].GetName() + "的手牌:" + players[index].GetCard())
            # Debug

            RunOut = True             # 没有牌可打了
            RENotUsed = True          # 防止多次使用RE
            TLENotUsed = True         # 防止多次使用TLE
            while RunOut:
                RoundRunOut = True
                i = 0
                HaveBadCards = players[index].HaveCard('Empty') or players[index].HaveCard('RE')
                nflag = False
                for j in range(TotalPlayers):               # CE的前提是有人还有牌
                    if players[j].GetCardTotal() > 0:
                        nflag = True
                        break
                HaveBadCards = HaveBadCards and nflag
                #for i in range(players[index].GetCardTotal()):
                while i < players[index].GetCardTotal():
                    HaveBadCards = players[index].HaveCard('Empty') or players[index].HaveCard('RE')
                    nflag = False
                    for j in range(TotalPlayers):               # CE的前提是有人还有牌
                        if players[j].GetCardTotal() > 0:
                            nflag = True
                            break
                    HaveBadCards = HaveBadCards and nflag
                    #if i >= players[index].GetCardTotal():
                        #break
                    cd = players[index].GetCardName(i)
                    # print(cd)
                    prob = random.randint(1, 6)
                    # print(prob)
                    tar = (index + 1)%TotalPlayers if Clockwise else (index - 1 + TotalPlayers)%TotalPlayers        # 根据方向确定下一个玩家
                    if (cd == 'MLE' and len(pile) != 0) or (cd == 'RE' and prob%3 == 0 and RENotUsed) or \
                       (cd == 'TLE' and prob%3 == 1 and TLENotUsed) or (cd == 'CE' and prob%3 == 1 and HaveBadCards) or \
                       (cd == 'AC' and prob%6 !=1) or (cd == 'Coin'):
                        # 如果要出牌
                        RoundRunOut = False
                        CEtar = random.randint(0, TotalPlayers-1)
                        while CEtar == index or players[CEtar].GetCardTotal() == 0:
                            CEtar = random.randint(0, TotalPlayers-1)           # 随机设置CEtar,这一步是为了防止CE自己或CE到没手牌的玩家
                        if cd in ['MLE', 'RE', 'AC', 'Coin']:     # 这些牌输出格式一样
                            TabPrint(2)
                            print("*" + players[index].GetName() + "使用了 " + players[index].UseCard(i) + "。")
                            time.sleep(1)
                        elif cd in ['TLE', 'CE']:                 # 这些牌输出格式一样
                            TabPrint(2)
                            if cd == 'TLE':
                                print("*" + players[index].GetName() + "对" + players[tar].GetName() + "使用了 " + players[index].UseCard(i) + "。")
                            else:
                                print("*" + players[index].GetName() + "对" + players[CEtar].GetName() + "使用了 " + players[index].UseCard(i) + "。")
                            time.sleep(1)
                        else:
                            pass
                        if cd == 'Coin':                        # 处理Coin
                            players[index].AddPoint(3)
                            TabPrint(2)
                            print("[" + players[index].GetName() + "+3分]")
                        # 询问是否使用UK/UKE
                        if cd == 'AC':
                            # 询问是否使用WA/UK/UKE
                            eff = index
                            UKed = False
                            UKEd = False
                            cseq = [["WA", index]]
                            sp = index
                            np = index
                            np = (np + 1)%TotalPlayers if Clockwise else (np - 1 + TotalPlayers)%TotalPlayers
                            while np != sp:
                                if np == 0 and (players[np].HaveCard("WA") or players[np].HaveCard("UK") or players[np].HaveCard("UKE") or players[np].HaveCard("Judge")):    # 玩家
                                    TabPrint(3)
                                    print("你要使用WA(" + str(players[np].GetCardNameTotal('WA')) + ")/UK(" + str(players[np].GetCardNameTotal('UK')) + ")/UKE(" + str(players[np].GetCardNameTotal('UKE')) + ")吗?输入你想使用的牌(输入'pass'以跳过)。")
                                    joi = ''
                                    while True:
                                        TabPrint(3)
                                        joi = input(">")
                                        if joi == 'pass':
                                            break
                                        elif ((joi in ["UKE", "Judge"]) and players[np].HaveCard(joi)) or \
                                             (joi == 'UK' and UKEd == False and players[np].HaveCard(joi)) or \
                                             (joi == 'WA' and UKed == False and players[np].HaveCard(joi)):
                                            break
                                        else:
                                            TabPrint(3)
                                            print("[错误]无效的输入。")
                                    if joi == 'pass':
                                        np = (np + 1)%TotalPlayers if Clockwise else (np - 1 + TotalPlayers)%TotalPlayers       # 根据游戏方向确定下一个玩家
                                        continue
                                    if joi == 'UK':
                                        TabPrint(3)
                                        print("*你使用了" + players[np].UseCard(players[np].Find(joi)) + "。")
                                        UKed = True
                                        sp = np
                                        cseq.append(['UK', np])
                                    if joi == 'UKE':
                                        TabPrint(3)
                                        print("*你使用了" + players[np].UseCard(players[np].Find(joi)) + "。")
                                        UKed = True
                                        UKEd = True
                                        sp = np
                                        cseq.append(['UKE', np])
                                    if joi == 'Judge':
                                        TabPrint(3)
                                        print("*你使用了" + players[np].UseCard(players[np].Find(joi)) + "。")
                                        TabPrint(3)
                                        print("请指定目标卡牌(WA/UK/UKE)。")
                                        jjo = None
                                        while True:
                                            TabPrint(3)
                                            jjo = input(">")
                                            if (jjo == 'WA' and UKed == False) or (jjo == 'UK' and UKEd == False) or jjo == 'UKE':
                                                break
                                            else:
                                                TabPrint(3)
                                                print("[错误]无效的输入。")
                                        TabPrint(3)
                                        print("*你将Judge当做" + jjo + "使用了。")
                                        if jjo == 'UK':
                                            UKed = True
                                        if jjo == 'UKE':
                                            UKEd = True
                                            UKed = True
                                        sp = np
                                        cseq.append([jjo, np])
                                    if joi == 'WA':
                                        TabPrint(3)
                                        print("*你使用了" + players[np].UseCard(players[np].Find(joi)) + "。")
                                        sp = np
                                        cseq.append(['WA', np])
                                    time.sleep(1)
                                else:               # 电脑
                                    prob = random.randint(1,6)              # 概率
                                    # Debug
                                    # print("(debug)UKNow:" + str(np) + ", sp:" + str(sp) + ", probility:" + str(prob))
                                    # Debug
                                    if players[np].HaveCard('WA') and UKed == False and (prob%6 != 1 or np == index):         # WA:5/6
                                        TabPrint(3)
                                        print("*" + players[np].GetName() + "使用了" + players[np].UseCard(players[np].Find('WA')) + "。")
                                        eff = np
                                        sp = np
                                        cseq.append(['WA', np])
                                    elif  players[np].HaveCard("UK") and UKEd == False and (prob%3 == 1 or cseq[len(cseq)-1-1][1] == np):                      # 电脑使用UK概率1/3
                                        TabPrint(3)
                                        print("*" + players[np].GetName() + "使用了" + players[np].UseCard(players[np].Find('UK')) + "。")
                                        eff = cseq[len(cseq)-1-1][1]
                                        UKed = True
                                        sp = np
                                        cseq.append(['UK', np])
                                    elif  players[np].HaveCard("UKE") and UKEd == False and (prob%3 == 1 or cseq[len(cseq)-1-1][1] == np):                      # 电脑使用UKE概率1/3
                                        TabPrint(3)
                                        print("*" + players[np].GetName() + "使用了" + players[np].UseCard(players[np].Find('UKE')) + "。")
                                        eff = cseq[len(cseq)-1-1][1]
                                        UKed = True
                                        UKEd = True
                                        sp = np
                                        cseq.append(['UKE', np])
                                    elif  players[np].HaveCard("Judge") and (prob%3 == 1 or cseq[len(cseq)-1-1][1] == np):        # Judge同UKE
                                        TabPrint(3)
                                        print("*" + players[np].GetName() + "将" + players[np].UseCard(players[np].Find('Judge')) + "当做UKE使用了。")
                                        eff = cseq[len(cseq)-1-1][1]
                                        UKEd = True
                                        UKed = True
                                        sp = np
                                        cseq.append(['UKE', np])
                                    else:
                                        pass
                                    time.sleep(1)
                                np = (np + 1)%TotalPlayers if Clockwise else (np - 1 + TotalPlayers)%TotalPlayers       # 根据游戏方向确定下一个玩家
                            # print(cseq)
                            for nsi in range(len(cseq)-1, -1, -2):
                                if cseq[nsi][0] == 'UKE':
                                    players[cseq[nsi][1]].AddPoint(2)
                                    players[cseq[nsi-1][1]].AddPoint(-1)
                                    TabPrint(3)
                                    print("[" + players[cseq[nsi][1]].GetName() + "的UKE生效:" + players[cseq[nsi][1]].GetName() + "+2分;" + players[cseq[nsi-1][1]].GetName() + "-1分]")
                                    nsi -= 2
                            eff = index
                            for ns in range(len(cseq)-1, -1, -1):
                                #print(ns)
                                if cseq[ns][0] == 'UK' or cseq[ns][0] == 'UKE':
                                    ns -= 2
                                    if ns == -1:
                                        eff = -1
                                        break
                                    eff = cseq[ns][1]
                                if cseq[ns][0] == 'WA':
                                    eff = cseq[ns][1]
                                    break
                            # 输入进一步处理
                            if eff == index:        # AC生效
                                players[index].AddPoint(3)
                                TabPrint(2)
                                print("[" + players[index].GetName() + "的AC生效:" + players[index].GetName() + "+3分]")
                            elif eff != -1:
                                players[eff].AddPoint(3)
                                TabPrint(2)
                                print("[" + players[eff].GetName() + "的WA生效:" + players[eff].GetName() + "+3分]")
                            else:
                                pass
                        if cd == 'AC':
                            RunOut = False
                            continue
                        eff = True
                        UKed = False
                        UKEd = False
                        cseq = [[":)", index]]
                        sp = index
                        np = index
                        np = (np + 1)%TotalPlayers if Clockwise else (np - 1 + TotalPlayers)%TotalPlayers
                        while np != sp:
                            if cd == 'Coin':
                                break
                            if np == 0 and (players[np].HaveCard("UK") or players[np].HaveCard("UKE") or players[np].HaveCard("Judge")):    # 玩家
                                TabPrint(3)
                                print("你要使用UK(" + str(players[np].GetCardNameTotal('UK')) + ")/UKE(" + str(players[np].GetCardNameTotal('UKE')) + ")吗?输入你想使用的牌(输入'pass'以跳过)。")
                                joi = ''
                                while True:
                                    TabPrint(3)
                                    joi = input(">")
                                    if joi == 'pass':
                                        break
                                    elif (joi in ["UKE", "Judge"]) and players[np].HaveCard(joi) or (joi == 'UK' and UKEd == False and players[np].HaveCard(joi)):
                                        break
                                    else:
                                        TabPrint(3)
                                        print("[错误]无效的输入。")
                                if joi == 'pass':
                                    np = (np + 1)%TotalPlayers if Clockwise else (np - 1 + TotalPlayers)%TotalPlayers       # 根据游戏方向确定下一个玩家
                                    continue
                                if joi == 'UK':
                                    TabPrint(3)
                                    print("*你使用了" + players[np].UseCard(players[np].Find(joi)) + "。")
                                    eff = False if eff else True
                                    sp = np
                                    cseq.append(['UK', np])
                                if joi == 'UKE':
                                    TabPrint(3)
                                    print("*你使用了" + players[np].UseCard(players[np].Find(joi)) + "。")
                                    eff = False if eff else True
                                    UKEd = True
                                    sp = np
                                    cseq.append(['UKE', np])
                                if joi == 'Judge':
                                    TabPrint(3)
                                    print("*你将" + players[np].UseCard(players[np].Find(joi)) + "当做UKE使用了。")
                                    eff = False if eff else True
                                    UKEd = True
                                    sp = np
                                    cseq.append(['UKE', np])
                                time.sleep(1)
                            else:               # 电脑
                                probu = random.randint(1,6)
                                # Debug
                                # print("(debug)UKNow:" + str(np) + ", sp:" + str(sp) + ", probility:" + str(probu))
                                # Debug
                                if players[np].HaveCard("UK") and UKEd == False and \
                                   (((probu%3 == 0 and np != tar and np != CEtar and \
                                     ((eff == False and cd in ['TLE', 'RE']) or (eff == True and cd in ['CE', 'MLE'])))\
                                    or ((np == tar and eff == True and cd in ['TLE', 'RE']) or \
                                        (np == CEtar and eff == True and cd == 'CE') or \
                                        (np == index and eff == False and cd == 'MLE')))):        # 电脑使用UK概率1/3
                                    TabPrint(3)
                                    print("*" + players[np].GetName() + "使用了" + players[np].UseCard(players[np].Find('UK')) + "。")
                                    eff = False if eff else True
                                    sp = np
                                    cseq.append(['UK', np])
                                elif  players[np].HaveCard("UKE") and \
                                     (((probu%3 == 0 and np != tar and np != CEtar and \
                                     ((eff == False and cd in ['TLE', 'RE']) or (eff == True and cd in ['CE', 'MLE'])))\
                                    or ((np == tar and eff == True and cd in ['TLE', 'RE']) or \
                                        (np == CEtar and eff == True and cd == 'CE') or \
                                        (np == index and eff == False and cd == 'MLE')))):                      # 电脑使用UKE概率1/3
                                    TabPrint(3)
                                    print("*" + players[np].GetName() + "使用了" + players[np].UseCard(players[np].Find('UKE')) + "。")
                                    eff = False if eff else True
                                    UKEd = True
                                    sp = np
                                    cseq.append(['UKE', np])
                                elif  players[np].HaveCard("Judge") and \
                                     (((probu%3 == 0 and np != tar and np != CEtar and \
                                     ((eff == False and cd in ['TLE', 'RE']) or (eff == True and cd in ['CE', 'MLE'])))\
                                    or ((np == tar and eff == True and cd in ['TLE', 'RE']) or \
                                        (np == CEtar and eff == True and cd == 'CE') or \
                                        (np == index and eff == False and cd == 'MLE')))):
                                    TabPrint(3)
                                    print("*" + players[np].GetName() + "将" + players[np].UseCard(players[np].Find('Judge')) + "当做UKE使用了。")
                                    eff = False if eff else True
                                    UKEd = True
                                    sp = np
                                    cseq.append(['UKE', np])
                                else:
                                    pass
                                time.sleep(1)
                            np = (np + 1)%TotalPlayers if Clockwise else (np - 1 + TotalPlayers)%TotalPlayers       # 根据游戏方向确定下一个玩家
                            # print(cseq)
                        for ns in range(len(cseq)-1, -1, -2):
                            if cseq[ns][0] == 'UKE':
                                players[cseq[ns][1]].AddPoint(2)
                                players[cseq[ns-1][1]].AddPoint(-1)
                                TabPrint(3)
                                print("[" + players[cseq[ns][1]].GetName() + "的UKE生效:" + players[cseq[ns][1]].GetName() + "+2分;" + players[cseq[ns-1][1]].GetName() + "-1分]")

                        if eff == False:
                            continue
                    if cd == 'MLE' and len(pile) != 0:      # 处理MLE
                        TabPrint(2)
                        if len(pile) == 1:
                            players[index].AddCard(pile.pop(len(pile)-1))
                            print("[" + players[index].GetName() + "+1张牌(牌堆剩余:" + str(len(pile)) + "张牌)]")
                        else:
                            players[index].AddCard(pile.pop(len(pile)-1))
                            players[index].AddCard(pile.pop(len(pile)-1))
                            print("[" + players[index].GetName() + "+2张牌(牌堆剩余:" + str(len(pile)) + "张牌)]")
                    if cd == 'RE' and prob%3 == 0 and RENotUsed:      # 处理RE(使用概率:1/3)
                        # global Clockwise
                        Clockwise = not Clockwise
                        nowOrder = "顺时针(正序)" if Clockwise else "逆时针(逆序)"
                        RENotUsed = False
                        TabPrint(2)
                        print("[" + players[index].GetName() + "调整游戏方向为 " + nowOrder + "]")
                    if cd == 'TLE' and prob%3 == 1 and TLENotUsed:                        # 处理TLE(使用概率:1/3)
                        TLENotUsed = False
                        players[tar].SetPlayerTLE(True)
                        TabPrint(2)
                        print("*" + players[tar].GetName() + "被跳过了。")
                    if cd == 'CE' and prob%3 == 1 and (players[index].HaveCard('Empty') or players[index].HaveCard('RE')):
                        tempa = None
                        if players[index].HaveCard('Empty'):
                            tempa = players[index].UseCard(players[index].Find('Empty'))
                        else:
                            tempa = players[index].UseCard(players[index].Find('RE'))
                        tempb = players[CEtar].UseCard(random.randint(0, players[CEtar].GetCardTotal()-1))
                        players[CEtar].AddCard(tempa)
                        players[index].AddCard(tempb)
                        time.sleep(1)
                        TabPrint(2)
                        print("[" + players[index].GetName() + "与" + players[CEtar].GetName() + "交换了手牌]")
                    i += 1
                if RoundRunOut:
                    RunOut = False
    # 玩家弃牌
    def PlayerFold(index):
        if index == 0:
            # 玩家
            TabPrint(2)
            print("请指定你要弃置的牌。")
            while players[index].GetCardTotal() > 4:
                TabPrint(2)
                print("你的牌:" + players[index].GetCard())
                TabPrint(2)
                ope = input(">")
                try:
                    cdindex = players[index].Find(ope)
                except ValueError:
                    TabPrint(2)
                    print("[错误]无效的输入。")
                    continue
                TabPrint(2)
                print("*" + players[index].GetName() + "弃置了", players[index].UseCard(cdindex), "。")
        else:
            # 电脑

            # Debug
            # TabPrint(2)
            # print("(debug)" + players[index].GetName() + "的手牌:" + players[index].GetCard())
            # Debug

            while players[index].GetCardTotal() > 4:
                for np in FoldOrder:
                    for i in range(players[index].GetCardTotal()):
                        if players[index].GetCardName(i) == np:
                            TabPrint(2)
                            print("*" + players[index].GetName() + "弃置了", players[index].UseCard(i), "。")
                            break
                        if players[index].GetCardTotal() <= 4:
                            break
                    if players[index].GetCardTotal() <= 4:
                            break

    # 玩家摸牌(4张)
    for i in range(4):
        for np in players:
            np.AddCard(pile.pop(len(pile)-1))

    # 游戏主循环
    print("[Judge牌 游戏开始]")
    time.sleep(1)

    while Running:
        now = (now + 1)%TotalPlayers if Clockwise else (now - 1 + TotalPlayers)%TotalPlayers        # 根据方向确定下一个玩家

        if now == 0:
            TotalRound += 1
            time.sleep(1)
            print("[第 " + str(TotalRound) + " 回合]")
            print("[牌堆剩余:" + str(len(pile)) + "]")
        time.sleep(1)
        TabPrint(1)
        print("[现在轮到:" + players[now].GetName() + "(" + str(players[now].GetPoint()) + "分;" + str(players[now].GetCardTotal()) + "张牌)]")
        if players[now].GetPlayerTLE() == True:        # 判断是否被跳过
            TabPrint(2)
            print("*" + players[now].GetName() + "被跳过了。")
            players[now].SetPlayerTLE(False)
            continue
        time.sleep(1)
        TabPrint(2)
        print("*" + players[now].GetName() + "摸了张牌。")
        # print(now, players[now])
        players[now].AddCard(pile.pop(len(pile)-1))    # 玩家摸牌阶段
        time.sleep(1)
        RunPlayer(now)                                 # 玩家出牌阶段
        time.sleep(1)
        if players[now].GetCardTotal() > 4:
            PlayerFold(now)                            # 玩家弃牌阶段
        if len(pile) == 0:
            Running = False

    time.sleep(2)
    print("[本局游戏结束]")
    print("[玩家分数统计]")
    for np in players:                                 # 回收手牌
        Origin = np.GetPoint()
        Sum = 0
        TabPrint(1)
        print(np.GetName() + ":")
        for j in range(np.GetCardTotal()):
            TabPrint(2)
            print(np.GetCardName(j) + ":+" + str(CardDic[np.GetCardName(j)][0]) + "分")
            np.AddPoint(CardDic[np.GetCardName(j)][0])
            Sum += CardDic[np.GetCardName(j)][0]
        TabPrint(2)
        print("总计:原始" + str(Origin) + "分 + 手牌回收" + str(Sum) + "分 = " + str(np.GetPoint()) + "分")
        time.sleep(0.5)

    players.sort()                                     # 排名
    rank = 1
    time.sleep(1)
    print("[玩家排名]")
    print("第1名:" + players[0].name + "(" + str(players[0].GetPoint()) + ")")
    for i in range(1, TotalPlayers):
        time.sleep(2)
        if players[i].GetPoint() != players[i-1].GetPoint():    # 重分处理
            rank = i + 1
        print("第" + str(rank) + "名:" + players[i].name + "(" + str(players[i].GetPoint()) + ")")