This commit is contained in:
a 2022-04-13 02:51:52 -05:00
parent c5b178c018
commit 3f38862df1
2 changed files with 11 additions and 7 deletions

View File

@ -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)
}

View File

@ -16,10 +16,14 @@ type Game struct {
TotalProbability float64
}
func NewFromRoot(datadir string) (*Game, error) {
out := &Game{
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 {