From 3f38862df1f21d96643f76ea3f74078ab51b3d6a Mon Sep 17 00:00:00 2001 From: a Date: Wed, 13 Apr 2022 02:51:52 -0500 Subject: [PATCH] clean --- cmd/cli/main.go | 2 +- common/game/game.go | 16 ++++++++++------ 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/cmd/cli/main.go b/cmd/cli/main.go index 249ceba..d8e7c3c 100644 --- a/cmd/cli/main.go +++ b/cmd/cli/main.go @@ -8,7 +8,7 @@ import ( ) func main() { - g, err := game.NewFromRoot(os.Getenv("CARD_DATA_DIR")) + g, err := game.New().ReadFromRoot(os.Getenv("CARD_DATA_DIR")) if err != nil { log.Panicln(err) } diff --git a/common/game/game.go b/common/game/game.go index 36af49c..1fb0530 100644 --- a/common/game/game.go +++ b/common/game/game.go @@ -16,10 +16,14 @@ type Game struct { TotalProbability float64 } -func NewFromRoot(datadir string) (*Game, error) { - out := &Game{ - Levels: make(map[string]*level.Level, 12), +func New() *Game { + return &Game{ + Levels: make(map[string]*level.Level, 12), + TotalProbability: 0, } +} + +func (g *Game) ReadFromRoot(datadir string) (*Game, error) { if datadir == "" { datadir = "./data" } @@ -30,9 +34,9 @@ func NewFromRoot(datadir string) (*Game, error) { for _, v := range grades { lvl := &level.Level{} lvl.Name = strconv.Itoa(v.Grade) - out.Levels[lvl.Name] = lvl + g.Levels[lvl.Name] = lvl lvl.SelectionWeight = v.Rate - out.TotalProbability = out.TotalProbability + v.Rate + g.TotalProbability = g.TotalProbability + v.Rate rres, err := data.NewResultsFromFile(path.Join(datadir, "ResultTable", lvl.Name+".yaml")) if err != nil { @@ -48,7 +52,7 @@ func NewFromRoot(datadir string) (*Game, error) { lvl.SpecialTable = table.New(sres) } } - return out, nil + return g, nil } func (g *Game) RandomLevel() *level.Level {