模拟开箱代码

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("感谢使用本开箱程序!")

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值