Skip to content

Commit

Permalink
update fate
Browse files Browse the repository at this point in the history
  • Loading branch information
godcong committed Jun 14, 2019
1 parent b3ec224 commit fc158fc
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 37 deletions.
4 changes: 2 additions & 2 deletions fate.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ type Generating struct {
}

func init() {
initDial()
//initDial()
}

func initDial() {
Expand Down Expand Up @@ -192,7 +192,7 @@ func filterSanCai(s []*Stroke) []*Stroke {
return nil
}
for idx := range s {
sc := NewSanCai(s[idx].wuge)
sc := NewSanCai(s[idx].wuge.TianGe, s[idx].wuge.RenGe, s[idx].wuge.DiGe)
mongo.C("wuxing").Find(bson.M{
"wu_xing": []string{sc.TianCai, sc.RenCai, sc.DiCai},
}).One(&wx)
Expand Down
2 changes: 1 addition & 1 deletion mongo/mgo.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package mongo
import "github.com/globalsign/mgo"

var session *mgo.Session
var mgoConfig = defaultConfig()
var mgoConfig *config

type config struct {
IsInit bool
Expand Down
6 changes: 3 additions & 3 deletions name_stroke.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ func (s *NameStroke) SanCaiWuGe() *nameStroke {

sanCai := &SanCai{
TianCai: sanCaiAttr(wuGe.TianGe),
TianCaiYinYang: sanCaiYinYang(wuGe.TianGe),
TianCaiYinYang: yinYangAttr(wuGe.TianGe),
RenCai: sanCaiAttr(wuGe.RenGe),
RenCaiYinYang: sanCaiYinYang(wuGe.RenGe),
RenCaiYinYang: yinYangAttr(wuGe.RenGe),
DiCai: sanCaiAttr(wuGe.DiGe),
DiCaiYingYang: sanCaiYinYang(wuGe.DiGe),
DiCaiYingYang: yinYangAttr(wuGe.DiGe),
}

return &nameStroke{
Expand Down
35 changes: 9 additions & 26 deletions sancai.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ import (
"github.com/godcong/fate/mongo"
)

const sanCai = "水木木火火土土金金水"
const yinYang = "阴阳"

type SanCai struct {
ID bson.ObjectId `bson:"_id,omitempty"`
TianCai string `bson:"tian_cai"`
Expand All @@ -22,11 +25,11 @@ type SanCai struct {
func NewSanCai(tian, ren, di int) *SanCai {
return &SanCai{
TianCai: sanCaiAttr(tian),
TianCaiYinYang: sanCaiYinYang(tian),
TianCaiYinYang: yinYangAttr(tian),
RenCai: sanCaiAttr(ren),
RenCaiYinYang: sanCaiYinYang(ren),
RenCaiYinYang: yinYangAttr(ren),
DiCai: sanCaiAttr(di),
DiCaiYingYang: sanCaiYinYang(di),
DiCaiYingYang: yinYangAttr(di),
}
}

Expand All @@ -43,29 +46,9 @@ func (cai *SanCai) Check() bool {
// GenerateThreeTalent 计算字符的三才属性
// 1-2木:1为阳木,2为阴木 3-4火:3为阳火,4为阴火 5-6土:5为阳土,6为阴土 7-8金:7为阳金,8为阴金 9-10水:9为阳水,10为阴水
func sanCaiAttr(i int) string {
var attr string
switch i % 10 {
case 1, 2:
attr = "木"
case 3, 4:
attr = "火"
case 5, 6:
attr = "土"
case 7, 8:
attr = "金"
case 9, 0:
attr = "水"
}

return attr
return string([]rune(sanCai)[i%10])
}

func sanCaiYinYang(i int) string {
var yy string
if i%2 == 1 {
yy = "阳"
} else {
yy = "阴"
}
return yy
func yinYangAttr(i int) string {
return string([]rune(yinYang)[i%2])
}
11 changes: 6 additions & 5 deletions sancai_test.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package fate_test

import (
"github.com/globalsign/mgo"
"github.com/godcong/fate"
"github.com/godcong/fate/mongo"
"log"
"runtime"
"testing"
"time"

"github.com/globalsign/mgo"
"github.com/godcong/fate"
"github.com/godcong/fate/mongo"
)

func TestMakeSanCaiWuGe(t *testing.T) {
Expand Down Expand Up @@ -47,8 +48,8 @@ func TestMakeSanCaiWuGe(t *testing.T) {

func ProcessOne(b chan<- int, l1, l2, f1, f2 int) {
log.Println(l1, l2, f1, f2)

ge := fate.NewSanCai(fate.NewWuGe(l1, l2, f1, f2))
wg := fate.NewWuGe(l1, l2, f1, f2)
ge := fate.NewSanCai(wg.TianGe, wg.RenGe, wg.DiGe)
err := mongo.InsertIfNotExist(mongo.C("sc"), ge)
log.Println(err)
b <- l1 * l2 * f1 * f2
Expand Down

0 comments on commit fc158fc

Please sign in to comment.