-
Notifications
You must be signed in to change notification settings - Fork 0
/
mingpan.go
153 lines (126 loc) · 3.02 KB
/
mingpan.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
package doushu
import (
"bytes"
"fmt"
)
type MingPan struct {
MingZhu *MingZhu
Gongs []*Gong
Minggong *Gong `json:"-"`
Shengong *Gong `json:"-"`
Positions []Element `json:"-"` // 星所在宫的地支代码
Lights []Element `json:"-"` //
}
func (pan *MingPan) String() string {
var buf bytes.Buffer
buf.WriteString(pan.MingZhu.String())
for _, gong := range pan.Gongs {
buf.WriteString("\n")
buf.WriteString(gong.String())
}
return buf.String()
}
func NewMingPan(name string, gender, niangan, nianzhi, yue, ri, shi Element) *MingPan {
mingZhu := &MingZhu{
Name: name,
Gender: gender,
NianGan: niangan,
NianZhi: nianzhi,
Yue: yue,
Ri: ri,
Shi: shi,
}
positions := make([]Element, End)
for i := 0; i < int(End); i++ {
positions[i] = Element(-1)
}
return &MingPan{
MingZhu: mingZhu,
Positions: positions,
}
}
type MingZhu struct {
Name string
Gender Element
NianGan Element
NianZhi Element
Yue Element
Ri Element
Shi Element
Yinyang Element
Wuxingju Element
Mingzhu Element
Shenzhu Element
Zidou Element
}
func (m *MingZhu) YinNanYangNv() bool {
return (m.Yinyang == Yang && m.Gender == Nan) || (m.Yinyang == YinXing && m.Gender == Nv)
}
func (m *MingZhu) String() string {
return fmt.Sprintf("%s %s%s年 %s%s %s时 %s%s %s\n命主:%s 身主:%s 子斗:%s",
m.Name, m.NianGan, m.NianZhi, m.Yue, m.Ri, m.Shi, m.Yinyang, m.Gender, m.Wuxingju,
m.Mingzhu, m.Shenzhu, m.Zidou)
}
type Gong struct {
Tiangan, Dizhi Element
Gong Element
Shen bool
JiaStars, YiStars, BingStars []*Star
HuaStars []Element
Changsheng12Star Element
Boshi12Star Element
Jianqian12Star Element
Suiqian12Star Element
DaxianStart int
Xiaoxian int
}
func (g *Gong) String() string {
buf := bytes.NewBuffer(make([]byte, 0, 1024))
buf.WriteString("\n")
buf.WriteString(g.Tiangan.String())
buf.WriteString(g.Dizhi.String())
buf.WriteString(" ")
buf.WriteString(g.Gong.String())
if g.Shen {
buf.WriteString(" ")
buf.WriteString(Shengong.String())
}
buf.WriteString(":\n ")
appendStars(buf, "甲级星", g.JiaStars)
appendStars(buf, "乙级星", g.YiStars)
appendStars(buf, "丙级星", g.BingStars)
buf.WriteString("\n ")
buf.WriteString(g.Changsheng12Star.String())
buf.WriteString(" ")
buf.WriteString(g.Boshi12Star.String())
buf.WriteString(" ")
buf.WriteString(g.Jianqian12Star.String())
buf.WriteString(" ")
buf.WriteString(g.Suiqian12Star.String())
fmt.Fprintf(buf, "\n %d-%d ", g.DaxianStart, g.DaxianStart+9)
for i := 0; i < 6; i++ {
if i != 0 {
buf.WriteString(",")
}
fmt.Fprintf(buf, "%d", g.Xiaoxian+12*i)
}
return buf.String()
}
func appendStars(buf *bytes.Buffer, title string, stars []*Star) {
for _, star := range stars {
buf.WriteString(" ")
buf.WriteString(star.Element.String())
if star.Light != 0 {
buf.WriteString(star.Light.String())
}
if star.Hua != 0 {
buf.WriteString(star.Hua.String())
}
}
}
type Star struct {
Element Element
Level Element
Light Element
Hua Element
}