Java实现数字博彩加拿大2.8开奖程序,最优开奖,加智能随机开奖,系统通杀(不得已才出)

Java 数字博彩加拿大2.8开奖程序,最优开奖,加智能随机开奖,系统通杀(不得已才出)
(最优开奖类似于贪心)
开奖总和13|14 系统通吃
开奖有对子,中奖计算 除了对子|极大|极小,其他中奖只返回本金
下一个给大家演示赌博系统里面的水桶算法

忠告大家,赌博赢得永远是庄家

package com.api;

import java.util.*;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicReference;
import java.util.stream.Collectors;

/**
 * 数字博彩加拿大2.8开奖程序,最优开奖,加智能随机开奖,系统通杀(不得已才出)
 * (最优开奖类似于贪心)
 *
 * 开奖总和13|14 系统通吃
 * 开奖有对子,中奖计算 除了对子|极大|极小,其他中奖只返回本金
 *
 * 忠告大家,赌博赢得永远是庄家
 *
 * 下一个给大家演示赌博系统里面的水桶算法
 * @author zhanqi
 * @since 2020-11-23 23:09:09
 */
public class OpenLottery {

    static class Item {
        List<Integer> options;
        public List<Integer> getOptions() {
            return options;
        }
        public void setOptions(List<Integer> item) {
            this.options = item;
        }
    }

    private static final Double money = 2.00;//单注金额

    private static final Map<String, Double> oddsMap = new HashMap<>();//赔率
    static {
        oddsMap.put("大", 2.80);
        oddsMap.put("小", 2.80);
        oddsMap.put("单", 2.00);
        oddsMap.put("双", 2.80);

        oddsMap.put("大单", 4.80);
        oddsMap.put("大双", 4.80);
        oddsMap.put("小单", 4.80);
        oddsMap.put("小双", 4.80);

        oddsMap.put("对子", 14.00);
        oddsMap.put("顺子", 25.00);
        oddsMap.put("豹子", 100.00);
        oddsMap.put("极大", 60.00);
        oddsMap.put("极小", 60.00);
        oddsMap.put("13|14", 0.00);
    }

    //下注统计 注数统计
    private static final Map<String, Double> bottomPourCount = new HashMap<>();

    static {
        bottomPourCount.put("大", 10.00);
        bottomPourCount.put("小", 10.00);
        bottomPourCount.put("单", 10.00);
        bottomPourCount.put("双", 10.00);

        bottomPourCount.put("大单", 10.00);
        bottomPourCount.put("大双", 10.00);
        bottomPourCount.put("小单", 1.00);
        bottomPourCount.put("小双", 1.00);

        bottomPourCount.put("对子", 1.00);
        bottomPourCount.put("顺子", 1.00);
        bottomPourCount.put("豹子", 1.00);
        bottomPourCount.put("极大", 1.00);
        bottomPourCount.put("极小", 1.00);
        bottomPourCount.put("13|14", 0.00);
    }

    public static void main(String[] arg) {
        //先算出奖池里面总共有多少钱
        Double bottomPourSumMoney=0.00;
        for(String key:bottomPourCount.keySet()){
            bottomPourSumMoney += bottomPourCount.get(key)*money;
        }
        System.out.println("奖池里面总共有: "+bottomPourSumMoney);

        Item mem = new Item();
        mem.setOptions(Arrays.asList(0,1,2,3,4,5,6,7,8,9));

        Item mem2 = new Item();
        mem2.setOptions(Arrays.asList(0,1,2,3,4,5,6,7,8,9));

        Item mem3 = new Item();
        mem3.setOptions(Arrays.asList(0,1, 2,3,4,5,6,7,8,9));

        List<Item> itemList = Arrays.asList(mem, mem2, mem3);
        int startIndex = 0;
        LinkedList<List<Integer>> result = exhaustive(itemList.get(startIndex), itemList, startIndex);
        System.out.println("穷举开奖集合: "+result);


        //计算出开那个收益最高
        List<Map<String, Object>> compensateMoneyList = getMaps(bottomPourSumMoney, result);
        System.out.println("初始计算出开那个收益倒序集合: "+compensateMoneyList);
        //过滤13,14
        List<Map<String,Object>> filterListNot13and14 = compensateMoneyList.stream().filter(u -> (Integer)u.get("sum")!=13&&(Integer)u.get("sum")!=14).collect(Collectors.toList());
        System.out.println("过滤13,14倒序集合: "+compensateMoneyList);
        //13,14
        List<Map<String,Object>> filterListIn13and14 = compensateMoneyList.stream().filter(u -> (Integer)u.get("sum")!=13&&(Integer)u.get("sum")!=14).collect(Collectors.toList());
        System.out.println("13,14倒序集合: "+compensateMoneyList);
        //提高开奖体验,随机开最大收益的号码
        if((Integer)filterListNot13and14.get(0).get("sum")<0){
            RandomList(filterListIn13and14);
        }else{
            Double compensateMoney = (Double)filterListNot13and14.get(0).get("compensateMoney");
            List<Map<String,Object>> filterList= compensateMoneyList.stream().filter(u -> (Double)u.get("compensateMoney")-compensateMoney==0).collect(Collectors.toList());
            RandomList(filterList);
        }

    }

    /**
     * 计算出开那个收益最高
     * @param bottomPourSumMoney
     * @param result
     * @return
     */
    private static List<Map<String, Object>> getMaps(Double bottomPourSumMoney, LinkedList<List<Integer>> result) {
        List<Map<String,Object>> compensateMoneyList = new ArrayList<>();
        Double finalBottomPourSumMoney = bottomPourSumMoney;
        AtomicInteger index= new AtomicInteger();
        result.forEach(e ->{
            //System.out.println(lotteryType(e));
            List<String> lotteryTypeList=lotteryType(e);
            Double compensateMoney=0.00;
            for(String key:lotteryTypeList){
                if(lotteryTypeList.contains("对子")){
                    if(key.equals("对子")||key.equals("极大")||key.equals("极小"))
                        compensateMoney += (bottomPourCount.get(key) * oddsMap.get(key));//对子照赔
                    else
                        compensateMoney += (bottomPourCount.get(key) * money);//其他只返还本金

                }else{
                    compensateMoney += (bottomPourCount.get(key) * oddsMap.get(key));//不包含对子照赔所有
                }


            }
            Map<String,Object> map=new HashMap<>();
            map.put("arr",e);
            map.put("sum",NumBySum(e));
            map.put("compensateMoney",finalBottomPourSumMoney-compensateMoney);
            compensateMoneyList.add(map);
            index.incrementAndGet();
        });

        //排序取出最大的值,收益最高
        Collections.sort(compensateMoneyList, (m1, m2) -> {
            double diff = (Double) m2.get("compensateMoney") - (Double) m1.get("compensateMoney");
            if(diff > 0)
                return 1;
            else if(diff == 0)
                return 0;
            else
                return -1;
        });
        return compensateMoneyList;
    }

    /**
     * 顺序两次次打乱
     * @param filterListIn13and14
     */
    private static void RandomList(List<Map<String, Object>> filterListIn13and14) {
        Random ra = new Random();
        Map<String, Object> map = filterListIn13and14.get(ra.nextInt(filterListIn13and14.size()));
        List<Integer> arr = (List<Integer>) map.get("arr");
        Double compensateMoney = (Double) map.get("compensateMoney");
        Collections.shuffle(arr);//顺序再次打乱
        System.out.println("最优开奖结果: "+arr+" 系统盈利: "+compensateMoney);
    }
    /**
     * 穷举开奖结果
     * @param first    第一个item
     * @param itemList 所有item
     * @param index    索引
     * @return
     */
    private static LinkedList<List<Integer>> exhaustive(Item first, List<Item> itemList, int index) {
        List<Integer> firstItem = first.getOptions();
        LinkedList<List<Integer>> ret = new LinkedList<>();
        firstItem.forEach(item ->{
            int nextIndex = index + 1;
            if (nextIndex < itemList.size()) {
                LinkedList<List<Integer>> nextRet = exhaustive(itemList.get(nextIndex), itemList, nextIndex);
                nextRet.forEach(str ->{
                    LinkedList<Integer> sub=new LinkedList<>();
                    sub.add(item);
                    str.forEach(n ->{
                        sub.add(n);
                    });
                    ret.add(sub);
                });
            } else {
                LinkedList<Integer> sub=new LinkedList<>();
                sub.add(item);
                ret.add(sub);
            }
        });
        return ret;
    }
    /**
     * 模拟开奖
     *
     * @return
     */
    private static List<Integer> RandomList() {
        List<Integer> list = new ArrayList<Integer>();
        Random ra = new Random();
        for (int i = 0; i < 3; i++) {
            list.add(ra.nextInt(9));
        }
        return list;
    }

    /**
     * 可能中奖的下注类型,如果总和为13,14系统通吃,返回空list
     *
     * @param list
     * @return
     */
    private static List<String> lotteryType(List<Integer> list) {
        List<String> arr = new ArrayList<String>();
        Integer sum = NumBySum(list);
        if (sum == 13 || sum == 14) {
            arr.add("13|14");
            return arr;
        }

        if (inPairsNum(list)) {
            arr.add("对子");
        }
        if (leopardNum(list)) {
            arr.add("豹子");
        }
        if (straightNum(list)) {
            arr.add("顺子");
        }
        if (sum <= 13) {
            arr.add("小");
            if (sum % 2 != 0) {
                arr.add("小单");
            } else {
                arr.add("小双");
            }
        }
        if (sum > 13) {
            arr.add("大");
            if (sum % 2 != 0) {
                arr.add("大单");
            } else {
                arr.add("大双");
            }
        }
        if (sum >= 23 && sum <= 27) {
            arr.add("极大");

        }
        if (sum > 0 && sum <= 4) {
            arr.add("极小");
        }
        if (sum % 2 != 0) {
            arr.add("单");
        } else {
            arr.add("双");
        }
        return arr;
    }

    /**
     * 豹子号检测
     *
     * @param list
     * @return
     */
    private static boolean leopardNum(List<Integer> list) {
        Set<Integer> result = new HashSet<Integer>(list);
        if (result.size() != 1) {
            return false;
        }
        return true;

    }

    /**
     * 对子检测
     *
     * @param list
     * @return
     */
    private static boolean inPairsNum(List<Integer> list) {
        Set<Integer> result = new HashSet<Integer>(list);
        if (result.size() != 2) {
            return false;
        }
        return true;

    }

    /**
     * 判断是否是顺子
     *
     * @param list
     * @return
     */
    private static Boolean straightNum(List<Integer> list) {
        AtomicReference<Boolean> flag = new AtomicReference<>(true);
        Collections.sort(list, (i1, i2) -> {
            int diff = i1 - i2;
            if (diff != 1) {
                flag.set(false);
                return 1;
            }
            return 0;
        });
        return flag.get();
    }

    /**
     * 求总和
     *
     * @param list
     * @return
     */
    private static Integer NumBySum(List<Integer> list) {
        AtomicReference<Integer> sum = new AtomicReference<>(0);
        list.forEach(e -> {
            sum.updateAndGet(v -> v + e);
        });
        return sum.get();
    }

}

运行结果每次都不一样,但是一定是最优的

已标记关键词 清除标记
©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页