forked from babyname/fate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
xiyong.go
72 lines (63 loc) · 1.37 KB
/
xiyong.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
package fate
//XiYong 喜用神
type XiYong struct {
WuXingFen map[string]int
Similar []string //同类
SimilarPoint int
Heterogeneous []string //异类
HeterogeneousPoint int
}
var sheng = []string{"木", "火", "土", "金", "水"}
var ke = []string{"木", "土", "水", "火", "金"}
//AddFen 五行分
func (xy *XiYong) AddFen(s string, point int) {
if xy.WuXingFen == nil {
xy.WuXingFen = make(map[string]int)
}
if v, b := xy.WuXingFen[s]; b {
xy.WuXingFen[s] = v + point
} else {
xy.WuXingFen[s] = point
}
}
//GetFen 取得分
func (xy *XiYong) GetFen(s string) (point int) {
if xy.WuXingFen == nil {
return 0
}
if v, b := xy.WuXingFen[s]; b {
return v
}
return 0
}
func (xy *XiYong) minFenWuXing(ss ...string) (wx string) {
min := 9999
for _, s := range ss {
if xy.WuXingFen[s] < min {
min = xy.WuXingFen[s]
wx = s
} else if xy.WuXingFen[s] == min {
wx += s
}
}
return
}
//Shen 喜用神
func (xy *XiYong) Shen() string {
if !xy.QiangRuo() {
return xy.minFenWuXing(xy.Similar...)
}
return xy.minFenWuXing(xy.Heterogeneous...)
}
//QiangRuo 八字偏强(true)弱(false)
func (xy *XiYong) QiangRuo() bool {
return xy.SimilarPoint > xy.HeterogeneousPoint
}
func filterXiYong(yong string, cs ...*Character) (b bool) {
for _, c := range cs {
if c.WuXing == yong {
return true
}
}
return false
}