首页
/
每日頭條
/
遊戲
/
python制作沙盒遊戲所有代碼
python制作沙盒遊戲所有代碼
更新时间:2025-02-11 02:09:20

python制作沙盒遊戲所有代碼?# -*- coding: UTF-8 -*- from itertools import combinations from itertools import permutations str1 = "1 2 J A" card = str1.split(" ") re_ref = ['J', 'Q', 'K', 'A'] i_ref = [11, 12, 13, 1] # 運算符 def getYS(): result = [] list1 = [' ', '-', '*', '/'] * 3 for p in combinations(list1, 3): result.append(p) return list(set(result)) # print(len(getYS())) # 獲取牌順序 def getCard(card): result = [] for p in permutations(card, 4): list1 = [] list1.append(p[0]) list1.append(p[1]) list1.append(p[2]) list1.append(p[3]) result.append(list1) return result # print(len(getCard(card))) # 獲取表達式 def getExpress1(card): result = [] for i in getYS(): tmp = card[:] tmp.insert(1, i[0]) tmp.insert(3, i[1]) tmp.insert(5, i[2]) result.append(tmp) return result # print(getExpress(card)) #添加括号 def getExpress2(list1): #隻有一個*或者/ if list1.count("*") list1.count("/") == 1: if list1[3] == "*" or list1[3] == "/": list1.insert(0, "(") list1.insert(4, ")") elif list1[5] == "*" or list1[5] == "/": list1.insert(0, "(") list1.insert(6, ")") #有兩個*或者/ elif list1.count("*") list1.count("/") == 2: if (list1[1] == "*" or list1[1] == "/") and (list1[5] == "*" or list1[5] == "/"): list1.insert(0, "(") list1.insert(6, ")") elif (list1[1] == "*" or list1[1] == "/") and (list1[5] == "*" or list1[5] == "/"): list1.insert(0, "(") list1.insert(4, ")") return list1 #生成字符串表達式 def getExpress3(card, res_result): result = getExpress1(card) for i in result: list1 = getExpress2(i) str1 = '' for j in list1: str1 = str1 str(j) if eval(str1) == 24: str2 = str1.replace('.', '').replace('0', '').replace('(', '').replace(')', '') res_result.append(str2.replace('11', 'J').replace('12', 'Q').replace('13', 'K').replace('1', 'A')) res_result = [] if "joker" in card or "JOKER" in card: print('ERROR') else: for i in card: if i in re_ref: card[card.index(i)] = float(i_ref[re_ref.index(i)]) else: card[card.index(i)] = float(i) print(card) for j in getCard(card): getExpress3(j, res_result) if len(res_result) == 0: print('NONE') else: #print(list(set(res_result))) print(list(set(res_result))[0]) ,我來為大家講解一下關于python制作沙盒遊戲所有代碼?跟着小編一起來看一看吧!

python制作沙盒遊戲所有代碼(python實現24點牌遊戲)1

python制作沙盒遊戲所有代碼

# -*- coding: UTF-8 -*- from itertools import combinations from itertools import permutations str1 = "1 2 J A" card = str1.split(" ") re_ref = ['J', 'Q', 'K', 'A'] i_ref = [11, 12, 13, 1] # 運算符 def getYS(): result = [] list1 = [' ', '-', '*', '/'] * 3 for p in combinations(list1, 3): result.append(p) return list(set(result)) # print(len(getYS())) # 獲取牌順序 def getCard(card): result = [] for p in permutations(card, 4): list1 = [] list1.append(p[0]) list1.append(p[1]) list1.append(p[2]) list1.append(p[3]) result.append(list1) return result # print(len(getCard(card))) # 獲取表達式 def getExpress1(card): result = [] for i in getYS(): tmp = card[:] tmp.insert(1, i[0]) tmp.insert(3, i[1]) tmp.insert(5, i[2]) result.append(tmp) return result # print(getExpress(card)) #添加括号 def getExpress2(list1): #隻有一個*或者/ if list1.count("*") list1.count("/") == 1: if list1[3] == "*" or list1[3] == "/": list1.insert(0, "(") list1.insert(4, ")") elif list1[5] == "*" or list1[5] == "/": list1.insert(0, "(") list1.insert(6, ")") #有兩個*或者/ elif list1.count("*") list1.count("/") == 2: if (list1[1] == "*" or list1[1] == "/") and (list1[5] == "*" or list1[5] == "/"): list1.insert(0, "(") list1.insert(6, ")") elif (list1[1] == "*" or list1[1] == "/") and (list1[5] == "*" or list1[5] == "/"): list1.insert(0, "(") list1.insert(4, ")") return list1 #生成字符串表達式 def getExpress3(card, res_result): result = getExpress1(card) for i in result: list1 = getExpress2(i) str1 = '' for j in list1: str1 = str1 str(j) if eval(str1) == 24: str2 = str1.replace('.', '').replace('0', '').replace('(', '').replace(')', '') res_result.append(str2.replace('11', 'J').replace('12', 'Q').replace('13', 'K').replace('1', 'A')) res_result = [] if "joker" in card or "JOKER" in card: print('ERROR') else: for i in card: if i in re_ref: card[card.index(i)] = float(i_ref[re_ref.index(i)]) else: card[card.index(i)] = float(i) print(card) for j in getCard(card): getExpress3(j, res_result) if len(res_result) == 0: print('NONE') else: #print(list(set(res_result))) print(list(set(res_result))[0])

,
Comments
Welcome to tft每日頭條 comments! Please keep conversations courteous and on-topic. To fosterproductive and respectful conversations, you may see comments from our Community Managers.
Sign up to post
Sort by
Show More Comments
推荐阅读
遊戲方舟生存進化最強生物盤點
遊戲方舟生存進化最強生物盤點
遊戲方舟生存進化最強生物盤點?由于時代的進步,遊戲廠商所開發出來的遊戲畫面也越來越真實了,現在甚至出現了一些AR遊戲,能夠将角色以立體的樣子展現給玩家下面我就來為大家推薦Steam遊戲平台上的10款高畫質遊戲,由于畫面質量極高,不少的玩家電...
2025-02-11
lpl女解說rita在哪個直播
lpl女解說rita在哪個直播
英雄聯盟:S10開賽前解說Rita火了,可以吸水的電競椅是個什麼鬼開奔馳喝戰馬,電競椅上要幹啥?這個問題,Rita可以自豪的告訴大家了,電競椅上可以吸水了。英雄聯盟LPL賽區,官方解說團的四朵金花之一的Rita,自從轉戰虎牙被姿态帶着開了一...
2025-02-11
王者榮耀畫師有哪些
王者榮耀畫師有哪些
王者榮耀畫師有哪些?惡夏guang,作品有歸墟夢演系列,花木蘭fmvp,盤古,沈夢溪原畫以及勇者皮膚,宮本武藏和猴子的星傳說等等,現在小編就來說說關于王者榮耀畫師有哪些?下面内容希望能幫助到你,我們來一起看看吧!王者榮耀畫師有哪些惡夏gua...
2025-02-11
為什麼華為mate40pro如此受歡迎
為什麼華為mate40pro如此受歡迎
華為Mate40Pro發布已經有了一段時間,對于華為Mate40Pro的各類測評已經見到了很多。它擁有一顆強大的心髒——麒麟9000,它基于5nm工藝制程的手機Soc,集成多達153億個晶體管,包括一個3.13GHzA77大核心、三個2.5...
2025-02-11
王者榮耀霸氣名字男
王者榮耀霸氣名字男
王者榮耀霸氣名字男?目光還在捉迷藏手心的薔薇,下面我們就來聊聊關于王者榮耀霸氣名字男?接下來我們就一起去了解一下吧!王者榮耀霸氣名字男目光還在捉迷藏手心的薔薇脾氣有點上頭.别跟我玩心跳顔陌.桃花劫不交電費瞎發啥光知世故而不世故嘴角上揚也掩蓋...
2025-02-11
Copyright 2023-2025 - www.tftnews.com All Rights Reserved