Android原生奇门遁甲排盘代码

5 篇文章 0 订阅

最近喜欢上中国玄学,奇门遁甲,风水八字等,虽然网上有很多奇门排盘的软件,但是都是非安卓原生代码实现的,所以为了验证自己所学,原生代码写了个自动排盘

如图

时间选择

自动排盘
具体的逻辑主要是公历转为中国传统的农历

/**
     * @param rgz     日干
     * @param curtime 时间
     * @return 
     */
public static List<Object> getPanInfo(long curtime, String rgz) {
        int index = 0;
        String curJieqi = "";
        boolean isYangdun = true;//是否是阳盾
        //夏至和冬至时间 夏至以后为阴盾局 冬至以后为阳盾局
        int curYear = DateUtil.getYearByTimeStamp(curtime);
        int curMonth = DateUtil.getMonthByTimeStamp(curtime);
        Jieqi mj = new Jieqi();
        Map<String, String> map = replaceMapValue(mj.paiYue(curYear), SolarTermsUtil.solarTermToString(curtime), curtime);
        for (Entry<String, String> entry : map.entrySet()) {
            String jq = entry.getKey();
            String date = entry.getValue();
            long dd = DateUtil.getStringToDate(date);
        }
        //冬至后用阳盾2020-12-21 18:02:21,夏至后用阴盾2020-06-21 05:43:37
        String xzDate = map.get("夏至");
        String dzDate = map.get("冬至");
        long xztime = DateUtil.getStringToDate(xzDate);
        long dztime = DateUtil.getStringToDate(dzDate);
        //如果当前月份为夏至后,冬至前则用阴盾
        for (int i = 0; i < sixty_jiazi.length; i++) {
            if (sixty_jiazi[i].equals(rgz)) {
                index = i;
            }
        }
        if (curtime > xztime && curtime < dztime) {
            isYangdun = false;
        }
        int line = index / 5;
        String yuan = yuan_fu[line];
        //首先判断月份是否匹配,每个月两个节气,再根据两个节气的时间做判断,是属于什么节气
        //存储根据正常节气顺序获取的时间戳
        List<Long> datas = new ArrayList<>(24);
        List<String> jq = new ArrayList<>(24);
        List<Integer> indexYue = new ArrayList<>(24);
        for (int i = 0; i < jieqi.length; i++) {
            String time = map.get(jieqi[i]);
            datas.add(i, DateUtil.getStringToDate(time));
            jq.add(i, jieqi[i]);
        }
        for (int i = 0; i < yuefen.length; i++) {
            if (yuefen[i] == curMonth) {
                indexYue.add(i);
            }
        }
        if (curMonth == 2) {
            if (curtime < datas.get(indexYue.get(0))) {
                curJieqi = jieqi[23];
            } else if (curtime >= datas.get(indexYue.get(0)) && curtime < datas.get(indexYue.get(1))) {
                curJieqi = jieqi[indexYue.get(0)];
            } else if (curtime >= datas.get(indexYue.get(1))) {
                curJieqi = jieqi[indexYue.get(1)];
            }
        } else {
            if (curtime < datas.get(indexYue.get(0))) {
                curJieqi = jieqi[indexYue.get(0) - 1];
            } else if (curtime >= datas.get(indexYue.get(0)) && curtime < datas.get(indexYue.get(1))) {
                curJieqi = jieqi[indexYue.get(0)];
            } else if (curtime >= datas.get(indexYue.get(1))) {
                curJieqi = jieqi[indexYue.get(1)];
            }
        }

        Map<String, String> dunMap = new HashMap<>(24);
        dunMap.put("冬至", "174");
        dunMap.put("小寒", "285");
        dunMap.put("大寒", "396");
        dunMap.put("立春", "852");
        dunMap.put("雨水", "963");
        dunMap.put("惊蛰", "174");
        dunMap.put("春分", "396");
        dunMap.put("清明", "417");
        dunMap.put("谷雨", "528");
        dunMap.put("立夏", "417");
        dunMap.put("小满", "528");
        dunMap.put("芒种", "639");
        dunMap.put("夏至", "936");
        dunMap.put("小暑", "825");
        dunMap.put("大暑", "714");
        dunMap.put("立秋", "258");
        dunMap.put("处暑", "147");
        dunMap.put("白露", "936");
        dunMap.put("秋分", "714");
        dunMap.put("寒露", "693");
        dunMap.put("霜降", "582");
        dunMap.put("立冬", "693");
        dunMap.put("小雪", "582");
        dunMap.put("大雪", "471");

        int jushu = 0;
        Log.e(TAG, "isYangdun: " + isYangdun);
        Log.e(TAG, "curJieqi: " + curJieqi);
        if (isYangdun) {
            String s = dunMap.get(curJieqi);
            if (yuan.equals("上元")) {
                jushu = Integer.parseInt(s.substring(0, 1));
            } else if (yuan.equals("中元")) {
                jushu = Integer.parseInt(s.substring(1, 2));
            } else {
                jushu = Integer.parseInt(s.substring(s.length() - 1));
            }
        } else {
            String s = dunMap.get(curJieqi);
            if (yuan.equals("上元")) {
                jushu = Integer.parseInt(s.substring(0, 1));
            } else if (yuan.equals("中元")) {
                jushu = Integer.parseInt(s.substring(1, 2));
            } else {
                jushu = Integer.parseInt(s.substring(s.length() - 1));
            }
        }
        List<Object> list = new ArrayList<>(5);
        list.add(0, isYangdun);
        list.add(1, yuan);
        list.add(2, curJieqi);
        list.add(3, jushu);
        Log.e("DHD", "isYangdun: " + isYangdun);
        Log.e("DHD", "yuan: " + yuan);
        Log.e("DHD", "curMonth: " + curMonth);
        Log.e("DHD", "curJieqi: " + curJieqi);
        Log.e("DHD", "jushu: " + jushu);
        return list;
    }

盘面是用recyclerview实现,其中用到很多算法逻辑

包括干支纪年法计算,十二长生,五行生克,八门九星等,不一一贴图
排盘的activity部分代码截图

有排盘自然要有风水罗盘

罗盘界面
首页

Android端具体逻辑是将时间选择转为农历,再根据干支纪年法,五行生克,十二长生,八门九星等宫位排列规则用recyclerview进行计算排序,

服务端使用go开发
请添加图片描述
请添加图片描述

请添加图片描述
需要代码的可以联系wx:kotm0066

评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值