整理家谱的八字时,浏览储子百家有关八字十神之论命,其精彩处,几令笔者应劫其中,子曰:“生我兮枭印,同我兮比劫,我生兮食伤,我克兮才财,克我兮官杀”。虽说如堕五里雾中,但求答谢度娘渡我一程,随缘推敲解式,算是随缘兮。
下式中rg是日干,gz是其余各柱的干或支。
function ten-gods(rg,gz)
{
var d,ss;
var a=tense(rg);
var b=element(rg,1);
var c=tense(gz);
if("子巳午亥".indexOf(gz)==-1) d=element(gz,1);
else d=math.abs(element(gz,1)-1);
var v=a-c;
if(v<0) v+=5;
var n=math.abs(b-d);
switch(true){
case (v==0&&n==0): ss="比肩"; break; //同我同性 =0,0
case (v==0&&n==1): ss="劫财"; break; //同我异性 =0,1
case (v==1&&n==0): ss="偏印"; break; //生我同性 =1,0
case (v==1&&n==1): ss="正印"; break; //生我异性 =1,1
case (v==2&&n==0): ss="七杀"; break; //克我同性 =2,0
case (v==2&&n==1): ss="正官"; break; //克我异性 =2,1
case (v==3&&n==0): ss="偏财"; break; //我克同性 =3,0
case (v==3&&n==1): ss="正财"; break; //我克异性 =3,1
case (v==4&&n==0): ss="食神"; break; //我生同性 =4,0
case (v==4&&n==1): ss="伤官"; break; //我生异性 =4,1
default: ss="";
}
return ss;
}
function tense(gz)
{
var b=element(gz,0);
var wx="木火土金水";
var a=wx.indexOf(b);
return a;
}
function element(t,s)
{
var a,b;
switch(t){
case "甲": a="木"; b=1; break;
case "乙": a="木"; b=0; break;
case "丙": a="火"; b=1; break;
case "丁": a="火"; b=0; break;
case "戊": a="土"; b=1; break;
case "己": a="土"; b=0; break;
case "庚": a="金"; b=1; break;
case "辛": a="金"; b=0; break;
case "壬": a="水"; b=1; break;
case "癸": a="水"; b=0; break;
case "子": a="水"; b=1; break;
case "丑": a="土"; b=0; break;
case "寅": a="木"; b=1; break;
case "卯": a="木"; b=0; break;
case "辰": a="土"; b=1; break;
case "巳": a="火"; b=0; break;
case "午": a="火"; b=1; break;
case "未": a="土"; b=0; break;
case "申": a="金"; b=1; break;
case "酉": a="金"; b=0; break;
case "戌": a="土"; b=1; break;
case "亥": a="水"; b=0; break;
default: a="";b="";
}
if(s==0) return a;
else return b;
}