三国杀模拟抽盒子

苟卡概率太低辣,为了戒氪自己手写了一个简单抽盒子的程序,包括抽50次、10000次以及抽出66宝珠需要的次数。

import org.junit.Test;
import java.util.HashMap;
import java.util.Map;
public class test {
    class goods{
        private String str;
        private int value;
        public goods(String str,int value){
            this.str=str;
            this.value=value;
        }
    }
    public HashMap<Integer,goods> hashMap;
    public HashMap<String,Integer>bag;
    public int[] odds;
    public test() {
        hashMap = new HashMap<Integer, goods>();
        hashMap.put(1,new goods("史诗体验卡",1));
        hashMap.put(2,new goods("欢乐豆",50));
        hashMap.put(3,new goods("菜篮子",2));
        hashMap.put(4,new goods("换将卡",2));
        hashMap.put(5,new goods("手气卡",2));
        hashMap.put(6,new goods("点将卡",2));
        hashMap.put(7,new goods("进阶丹",2));
        hashMap.put(8,new goods("招募令",1));
        hashMap.put(9,new goods("雁翎甲",1));
        hashMap.put(10,new goods("史诗宝珠碎片",1));
        hashMap.put(11,new goods("菜篮子",99));
        hashMap.put(12,new goods("界朱治",1));
        hashMap.put(13,new goods("史诗宝珠",1));
        hashMap.put(14,new goods("将魂",1000));
        hashMap.put(15,new goods("兔年清明*周瑜动态包",1));
        hashMap.put(16,new goods("花鬘",1));
        hashMap.put(17,new goods("谋曹仁",1));
        hashMap.put(18,new goods("史诗宝珠",66));
        hashMap.put(19,new goods("界沮授",1));
        odds=new int[20000];
        for (int i=0;i<odds.length;i++){
            if (i<1000){
                odds[i]=1;
            }else if (i<2000){
                odds[i]=2;
            }else if (i<3355){
                odds[i]=3;
            }else if (i<8355){
                odds[i]=4;
            }else if (i<13355){
                odds[i]=5;
            }else if (i<16355) {
                odds[i] = 6;
            }else if (i<17355) {
                odds[i] = 7;
            }else if (i<18355) {
                odds[i] = 8;
            }else if (i<19355) {
                odds[i] = 9;
            }else if (i<19555) {
                odds[i] = 10;
            }else if (i<19755) {
                odds[i] = 11;
            }else if (i<19855) {
                odds[i] = 12;
            }else if (i<19955) {
                odds[i] = 13;
            }else if (i<19970) {
                odds[i] = 14;
            }else if (i<19985) {
                odds[i] = 15;
            }else if (i<19995) {
                odds[i] = 16;
            }else if (i<19998) {
                odds[i] = 17;
            }else if (i<19999) {
                odds[i] = 18;
            }else {
                odds[i]=19;
            }
    }
    }
    public goods first(){
        return hashMap.get(odds[(int)(Math.random()*20000)]);
    }
    public void one(){
        goods result=hashMap.get(odds[(int)(Math.random()*19999)+1]);
        System.out.println(result.str+"*"+result.value+" 将魂*2 "+"雁翎*20");
    }
    public void fifty(){
        System.out.println("50次的结果:");
        bag = new HashMap<String, Integer>();
        bag.put("将魂",100);
        bag.put("雁翎",1000);
        //循环抽五十次
        for(int i=0;i<50;i++){
            goods x=first();
            if (bag.containsKey(x.str)){
                bag.put(x.str, bag.get(x.str)+x.value);
            }else{
                bag.put(x.str, x.value);
            }
        }
        for (Map.Entry<String,Integer> entry:bag.entrySet()){
            System.out.print(entry.getKey()+"*"+entry.getValue()+" ");
        }
    }
    public void million(){
        System.out.println("一万次的结果:");
        bag = new HashMap<String, Integer>();
        bag.put("将魂",20000);
        bag.put("雁翎",200000);
        //循环抽五十次
        for(int i=0;i<10000;i++){
            goods x=first();
            if (bag.containsKey(x.str)){
                bag.put(x.str, bag.get(x.str)+x.value);
            }else{
                bag.put(x.str, x.value);
            }
        }
        for (Map.Entry<String,Integer> entry:bag.entrySet()){
            System.out.print(entry.getKey()+"*"+entry.getValue()+" ");
        }
    }
    public int get(){
        int i=1;
        while (!first().str.equals("界沮授")){
            i++;
        };
        return i;
    }

@Test
    public void t(){
        test test=new test();
        test.fifty();
        test.million();
         System.out.println("恭喜你抽了"+test.get()+"次,得到了66宝珠");

}
}

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值