判断八字格局批处理

淺唱寂寞╮ 提交于 2020-11-15 11:40:30
@echo off
setlocal enabledelayedexpansion
echo 格局程序
echo.
echo 作者:phenix
echo.
echo 联系方式:279682817@qq.com
echo.
:encode
rem 输入四柱信息
set /p bazi=请输入生辰八字(格式:庚子 丁亥 乙卯 乙酉):
echo.
call :decode !bazi!

rem 解析四柱部分
:decode
rem 获取年柱,月柱,日柱和时柱
set year=%1
set month=%2
set day=%3
set time=%4
rem 获取年月日时干支
set niangan=!year:~0,1!
set nianzhi=!year:~1!
set yuegan=!month:~0,1!
set yuezhi=!month:~1!
set rigan=!day:~0,1!
set rizhi=!day:~1!
set shigan=!time:~0,1!
set shizhi=!time:~1!
rem 打印年月日时干支
echo 年干=!niangan!  年支=!nianzhi!  月干=!yuegan!  月支=!yuezhi!  日干=!rigan!  日支=!rizhi!  时干=!shigan!  时支=!shizhi!
echo.
rem 日主字典:格式:日主 比肩劫财食神伤官偏财正财七杀正官偏印正印 主气中气余气地支
if not exist %temp%\rizhushishen.txt (
echo 甲 比肩:甲,劫财:乙,食神:丙,伤官:丁,偏财:戊,正财:己,七杀:庚,正官:辛,偏印:壬,正印:癸 主气:寅;无;无,中气:亥;无;无,余气:无;无;无>%temp%\rizhushishen.txt
echo 乙 比肩:乙,劫财:甲,食神:丁,伤官:丙,偏财:己,正财:戊,七杀:辛,正官:庚,偏印:癸,正印:壬 主气:卯;无;无,中气:辰;无;无,余气:未;无;无>>%temp%\rizhushishen.txt
echo 丙 比肩:丙,劫财:丁,食神:戊,伤官:己,偏财:庚,正财:辛,七杀:壬,正官:癸,偏印:甲,正印:乙 主气:巳;无;无,中气:寅;无;无,余气:无;无;无>>%temp%\rizhushishen.txt
echo 丁 比肩:丁,劫财:丙,食神:己,伤官:戊,偏财:辛,正财:庚,七杀:癸,正官:壬,偏印:乙,正印:甲 主气:午;无;无,中气:未;无;无,余气:戌;无;无>>%temp%\rizhushishen.txt
echo 戊 比肩:戊,劫财:己,食神:庚,伤官:辛,偏财:壬,正财:癸,七杀:甲,正官:乙,偏印:丙,正印:丁 主气:辰;戌;无,中气:无;无;无,余气:寅;巳;申>>%temp%\rizhushishen.txt
echo 己 比肩:己,劫财:戊,食神:辛,伤官:庚,偏财:癸,正财:壬,七杀:乙,正官:甲,偏印:丁,正印:丙 主气:丑;未;无,中气:午;无;无,余气:无;无;无>>%temp%\rizhushishen.txt
echo 庚 比肩:庚,劫财:辛,食神:壬,伤官:癸,偏财:甲,正财:乙,七杀:丙,正官:丁,偏印:戊,正印:己 主气:申;无;无,中气:巳;无;无,余气:无;无;无>>%temp%\rizhushishen.txt
echo 辛 比肩:辛,劫财:庚,食神:癸,伤官:壬,偏财:乙,正财:甲,七杀:丁,正官:丙,偏印:己,正印:戊 主气:酉;无;无,中气:戌;无;无,余气:丑;无;无>>%temp%\rizhushishen.txt
echo 壬 比肩:壬,劫财:癸,食神:甲,伤官:乙,偏财:丙,正财:丁,七杀:戊,正官:己,偏印:庚,正印:辛 主气:亥;无;无,中气:申;无;无,余气:无;无;无>>%temp%\rizhushishen.txt
echo 癸 比肩:癸,劫财:壬,食神:乙,伤官:甲,偏财:丁,正财:丙,七杀:己,正官:戊,偏印:辛,正印:庚 主气:子;无;无,中气:丑;无;无,余气:辰;无;无>>%temp%\rizhushishen.txt
)
rem 年月时干十神、月令透干、本中余气透干、本中余气十神、月令本气、月令本气十神、格局十神、天干阴阳、月令气
set nianganshishen=
set yueganshishen=
set shiganshishen=
set yuelingtougan=
set benqitougan=
set zhongqitougan=
set yuqitougan=
set benqishishen=
set zhongqishishen=
set yuqishishen=
set yuelingbenqi=
set yuelingbenqishishen=
set gejushishen=
set yinyang=
set yuelingqi=
set row=1
rem 解析日主字典
for /f "tokens=1,2,3*" %%a in (%temp%\rizhushishen.txt) do (
rem 日主、十神、日主在月令主中余气
set rizhu=%%a
set shishen=%%b
set dizhiqi=%%c
rem 获取日主信息
if !rigan! equ !rizhu! (
rem 判断日主阴阳
set /a yinyang=!row!%%2
if !yinyang! equ 0 (
set yinyang=阴
) else (
set yinyang=阳
)
rem 解析十神
for /f "tokens=1,2,3,4,5,6,7,8,9,10* delims=," %%c in ("!shishen!") do (
rem 当前日主十神
echo %%c>%temp%\dangqianrizhushishen.txt
echo %%d>>%temp%\dangqianrizhushishen.txt
echo %%e>>%temp%\dangqianrizhushishen.txt
echo %%f>>%temp%\dangqianrizhushishen.txt
echo %%g>>%temp%\dangqianrizhushishen.txt
echo %%h>>%temp%\dangqianrizhushishen.txt
echo %%i>>%temp%\dangqianrizhushishen.txt
echo %%j>>%temp%\dangqianrizhushishen.txt
echo %%k>>%temp%\dangqianrizhushishen.txt
echo %%l>>%temp%\dangqianrizhushishen.txt
rem 解析当前日主十神字典
for /f "tokens=1,2* delims=:" %%m in (%temp%\dangqianrizhushishen.txt) do (
rem 十神和天干
set shishen=%%m
set tiangan=%%n
rem 判断年月日干十神
if !niangan! equ !tiangan! (
set nianganshishen=!shishen!
)
if !yuegan! equ !tiangan! (
set yueganshishen=!shishen!
)
if !shigan! equ !tiangan! (
set shiganshishen=!shishen!
)
)
)
)
rem 分别判断年月时透不透月令气
if !niangan! equ !rizhu! (
for /f "tokens=1,2,3* delims=," %%o in ("!dizhiqi!") do (
rem 本中余气
set benqi=%%o
set zhongqi=%%p
set yuqi=%%q
echo !benqi:~3!>%temp%\niancanggan.txt
echo !zhongqi:~3!>>%temp%\niancanggan.txt
echo !yuqi:~3!>>%temp%\niancanggan.txt
set index=1
rem 本中余气内部解析
for /f "tokens=1,2,3* delims=;" %%r in (%temp%\niancanggan.txt) do (
echo %%r>%temp%\dangqiancanggan.txt
echo %%s>>%temp%\dangqiancanggan.txt
echo %%t>>%temp%\dangqiancanggan.txt
for /f "tokens=*" %%u in (%temp%\dangqiancanggan.txt) do (
rem 判断月支,并记录透的是本中余气和序号
if "%%u" equ "!yuezhi!" (
if !index! equ 1 (
set benqitougan=本气:!niangan!
set yuelingqi=!yuelingqi!!index!
)
if !index! equ 2 (
set zhongqitougan=中气:!niangan!
set yuelingqi=!yuelingqi!!index!
)
if !index! equ 3 (
set yuqitougan=余气:!niangan!
set yuelingqi=!yuelingqi!!index!
)
)
)
set /a index+=1
)
)
)
if !yuegan! equ !rizhu! (
for /f "tokens=1,2,3* delims=," %%o in ("!dizhiqi!") do (
set benqi=%%o
set zhongqi=%%p
set yuqi=%%q
echo !benqi:~3!>%temp%\yuecanggan.txt
echo !zhongqi:~3!>>%temp%\yuecanggan.txt
echo !yuqi:~3!>>%temp%\yuecanggan.txt
set index=1
for /f "tokens=1,2,3* delims=;" %%r in (%temp%\yuecanggan.txt) do (
echo %%r>%temp%\dangqiancanggan.txt
echo %%s>>%temp%\dangqiancanggan.txt
echo %%t>>%temp%\dangqiancanggan.txt
for /f "tokens=*" %%u in (%temp%\dangqiancanggan.txt) do (
if "%%u" equ "!yuezhi!" (
if !index! equ 1 (
set benqitougan=本气:!yuegan!
set yuelingqi=!yuelingqi!!index!
)
if !index! equ 2 (
set zhongqitougan=中气:!yuegan!
set yuelingqi=!yuelingqi!!index!
)
if !index! equ 3 (
set yuqitougan=余气:!yuegan!
set yuelingqi=!yuelingqi!!index!
)
)
)
set /a index+=1
)
)
)
if !shigan! equ !rizhu! (
for /f "tokens=1,2,3* delims=," %%o in ("!dizhiqi!") do (
set benqi=%%o
set zhongqi=%%p
set yuqi=%%q
echo !benqi:~3!>%temp%\shicanggan.txt
echo !zhongqi:~3!>>%temp%\shicanggan.txt
echo !yuqi:~3!>>%temp%\shicanggan.txt
set index=1
for /f "tokens=1,2,3* delims=;" %%r in (%temp%\shicanggan.txt) do (
echo %%r>%temp%\dangqiancanggan.txt
echo %%s>>%temp%\dangqiancanggan.txt
echo %%t>>%temp%\dangqiancanggan.txt
for /f "tokens=*" %%u in (%temp%\dangqiancanggan.txt) do (
if "%%u" equ "!yuezhi!" (
if !index! equ 1 (
set benqitougan=本气:!shigan!
set yuelingqi=!yuelingqi!!index!
)
if !index! equ 2 (
set zhongqitougan=中气:!shigan!
set yuelingqi=!yuelingqi!!index!
)
if !index! equ 3 (
set yuqitougan=余气:!shigan!
set yuelingqi=!yuelingqi!!index!
)
)
)
set /a index+=1
)
)
)
set /a row+=1
)
rem 获取月令本中余气十神
for /f "tokens=1,2* delims=:" %%a in (%temp%\dangqianrizhushishen.txt) do (
set shishen=%%a
set tiangan=%%b
if not "!benqitougan!" equ "" (
if !benqitougan:~3! equ !tiangan! (
set benqishishen=!shishen!
)
)
if not "!zhongqitougan!" equ "" (
if !zhongqitougan:~3! equ !tiangan! (
set zhongqishishen=!shishen!
)
)
if not "!yuqitougan!" equ "" (
if !yuqitougan:~3! equ !tiangan! (
set yuqishishen=!shishen!
)
)
)
echo 年干透出!nianganshishen! 月干透出!yueganshishen! 时干透出!shiganshishen!
echo.
if not "!yuelingqi!" equ "" (
rem 设置非比劫格局十神
if not "!benqishishen!" equ "" (
if not "!benqishishen!" equ "劫财" (
if not "!benqishishen!" equ "比肩" (
set gejushishen=!benqishishen!
)
)
)
if "!gejushishen!" equ "" (
if not "!zhongqishishen!" equ "" (
if not "!zhongqishishen!" equ "劫财" (
if not "!zhongqishishen!" equ "比肩" (
set gejushishen=!zhongqishishen!
)
)
)
)
if "!gejushishen!" equ "" (
if not "!yuqishishen!" equ "" (
if not "!yuqishishen!" equ "劫财" (
if not "!yuqishishen!" equ "比肩" (
set gejushishen=!yuqishishen!
)
)
)
)
rem 藏干为一个时比肩劫财,获取比肩还是劫财
if "!gejushishen!" equ "" (
set idx=!yuelingqi:~0,1!
if !idx! equ 1 (
set gejushishen=!benqishishen!
)
if !idx! equ 2 (
set gejushishen=!zhongqishishen!
)
if !idx! equ 3 (
set gejushishen=!yuqishishen!
)
)
rem 比劫格局处理
if "!gejushishen!" equ "劫财" (
if "!yinyang!" equ "阳" (
set gejushishen=阳刃
) else (
set gejushishen=月劫
)
)
if "!gejushishen!" equ "比肩" (
set gejushishen=建禄
)
echo 月令透干:!benqitougan!!benqishishen!!zhongqitougan!!zhongqishishen!!yuqitougan!!yuqishishen!
echo.
echo 格局:!gejushishen!格
echo.
) else (
rem 不透月令气,取月令本气
for /f "tokens=*" %%a in ('findstr 主气:.*!yuezhi!.*中气.* %temp%\rizhushishen.txt') do (
set yuelingbenqi=%%a
set yuelingbenqi=!yuelingbenqi:~0,1!
for /f "tokens=1,2* delims=:" %%b in (%temp%\dangqianrizhushishen.txt) do (
set shishen=%%b
set tiangan=%%c
rem 处理比劫
if "!yuelingbenqi!" equ "!tiangan!" (
set yuelingbenqishishen=!shishen!
if "!yuelingbenqishishen!" equ "劫财" (
if "!yinyang!" equ "阳" (
set gejushishen=阳刃
) else (
set gejushishen=月劫
)
) else (
if "!yuelingbenqishishen!" equ "比肩" (
set gejushishen=建禄
) else (
set gejushishen=!yuelingbenqishishen!
)
)
)
)
)
echo 月令不透干
echo.
echo 格局:取月令本气!yuelingbenqi!,!gejushishen!格
echo.
)
goto :encode

使用方法:用文本编辑器如notepad++,选ansi编码,复制进去如果开头和最后有问号,删除问号,保存时文件名xx. bat,保存类型选all  types,双击运行,保留代码完整性就行了,有问题私信叭,beta1.0版。

 

beta1.01版

修正了阳刃判断

 

beta1.02版

修正了不透干格局判断

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!