使用 Streamlit 展示原神八重神子杀生樱激化概率

优化了上版代码,使用了streamlit展示,效果如图所示

以下为代码

import random

import streamlit as st


class Enemy:
    def __init__(self, name):
        self.hit = 0
        self.hit_all = 0
        self.time = 0.0
        self.flag = True
        self.restart = True
        self.jihua = 1
        self.gap = 0.0
        self.name = name

    def renew(self):
        self.hit = 0
        self.hit_all = 0
        self.time = 0.0
        self.flag = True
        self.restart = True
        self.jihua = 1
        self.gap = 0.0

    def do_restart(self, time):
        self.restart = True
        self.hit = 1
        self.hit_all += 1
        self.jihua += 1
        self.time = time
        # print(f"{self.name}在{time}时被击中了,这次攻击是激化")

    def enemy_time_hit(self, time=0.0):
        if self.flag:
            self.time = time
            self.flag = False
            # print(f"{self.name}在{time}时被击中了,这次攻击是激化")
            self.hit += 1
            self.hit_all += 1
        else:
            self.gap = time - self.time
            if self.hit == 3 or self.gap >= 2.5:
                self.do_restart(time)
            else:
                self.restart = False
                self.hit += 1
                self.hit_all += 1
                # print(f"{self.name}在{time}时被击中了,这次攻击不是激化")

    def jihua_rate(self):
        return self.jihua, self.hit_all


def create_sha_sheng_ying(head):
    return [head, head+3, head+6, head+9, head+12]


def main():
    st.title("八重神子杀生樱激化概率")
    st.header("标准激化概率(2.5s / 3hit)")
    st.image('yea_miko.png')
    gap = float(st.selectbox("杀生樱释放间隔 /s", ['0.25', '0.5', '1']))
    times = int(st.selectbox("循环次数", ['10', '100', '500']))
    enemy_num = int(st.selectbox("敌人数量", ['1', '2', '3', '5', '8']))
    flag = st.button('点击计算')

    s = []
    enemy = []
    for i in range(enemy_num):
        enemy.append(Enemy(i))
    ssy = create_sha_sheng_ying(0) + create_sha_sheng_ying(gap) + create_sha_sheng_ying(2 * gap)
    ssy.sort()

    num = []
    all = []
    for time in range(times):
        for k in range(enemy_num):
            enemy[k].renew()
        for i in range(len(ssy)):
            k = random.randint(0, enemy_num-1)
            enemy[k].enemy_time_hit(ssy[i])
        for j in range(enemy_num):
            temp1, temp2 = enemy[j].jihua_rate()
            num.append(temp1)
            all.append(temp2)
    s.append(sum(num) / sum(all))
    if flag:
        st.header(round(sum(s), 2))


if __name__ == '__main__':
    main()

请使用 streamlit run 来启动

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值