import random
# 武器品质及对应概率
QUALITY = {
"白": 0.4,
"青": 0.28,
"蓝": 0.18,
"墨绿": 0.1,
"棕": 0.02,
"灰": 0.015,
"紫": 0.008,
"金": 0.0065,
"赤金": 0.0026,
"红": 0.0018
}
# 武器品质及对应基础价值
VALUE = {
"白": 2,
"青": 5,
"蓝": 20,
"墨绿": 120,
"棕": 870,
"灰": 1800,
"紫": 4300,
"金": 12000,
"赤金": 32000,
"红": 60000
}
# 箱子价格
BOX_PRICE = {
1: 17,
2: 20,
3: 40,
4: 200,
5: 1000,
6: 6000
}
# 箱子倍率
BOX_beilv = {
1: 1,
2: 1,
3: 2,
4: 5,
5: 10,
6: 20
}
# 统计开出的各种品质颜色的武器数量
def count_color(result):
color_count = {}
for weapon in result:
color = weapon.split("|")[0]
if color in color_count:
color_count[color] += 1
else:
color_count[color] = 1
return color_count
# 随机生成武器品质及名称
def generate_weapon():
rand_num = random.random()
for quality in QUALITY:
if rand_num < QUALITY[quality]:
name = random.choice(["ak47", "m4a4", "deagle", "awp"])
return quality + "|" + name
else:
rand_num -= QUALITY[quality]
# 完成一次开箱
def open_box(box_type):
num = int(input(f"请输入开第{box_type}种箱子的数量: "))
cost = BOX_PRICE[box_type] * num
result = []
for i in range(num):
weapon = generate_weapon()
value = VALUE[weapon.split("|")[0]] * BOX_beilv[box_type]
print(f"第{i+1}个武器:{weapon},价值:{value}")
result.append(weapon)
color_count = count_color(result)
for color in color_count:
print(f"{color}色武器:{color_count[color]}把")
profit = sum([VALUE[weapon.split("|")[0]] * BOX_beilv[box_type] for weapon in result]) - cost
print(f"本次开箱花费:{cost},盈利:{profit}")
return result
# 开始程序
total_cost = 0
total_profit = 0
result_total = []
while True:
box_type = int(input("请输入要开的箱子类型(1~6,对应17块箱子、20块箱子、40块箱子、200块箱子、1000块箱子、6000块箱子):"))
result_total += open_box(box_type)
total_cost = sum([BOX_PRICE[box_type] for weapon in result_total])
total_profit = sum([VALUE[weapon.split("|")[0]]* BOX_beilv[box_type] for weapon in result_total]) - total_cost
print(f"总共花费:{total_cost},总盈利:{total_profit}")
continue_choice = input("是否继续开箱(继续:输入y,结束:输入其他字符):")
if continue_choice != "y":
break
print("感谢使用本开箱程序!")
模拟开箱代码
最新推荐文章于 2025-04-03 16:23:32 发布