clean
This commit is contained in:
parent
c5b178c018
commit
3f38862df1
|
@ -8,7 +8,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
g, err := game.NewFromRoot(os.Getenv("CARD_DATA_DIR"))
|
g, err := game.New().ReadFromRoot(os.Getenv("CARD_DATA_DIR"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Panicln(err)
|
log.Panicln(err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,10 +16,14 @@ type Game struct {
|
||||||
TotalProbability float64
|
TotalProbability float64
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewFromRoot(datadir string) (*Game, error) {
|
func New() *Game {
|
||||||
out := &Game{
|
return &Game{
|
||||||
Levels: make(map[string]*level.Level, 12),
|
Levels: make(map[string]*level.Level, 12),
|
||||||
|
TotalProbability: 0,
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (g *Game) ReadFromRoot(datadir string) (*Game, error) {
|
||||||
if datadir == "" {
|
if datadir == "" {
|
||||||
datadir = "./data"
|
datadir = "./data"
|
||||||
}
|
}
|
||||||
|
@ -30,9 +34,9 @@ func NewFromRoot(datadir string) (*Game, error) {
|
||||||
for _, v := range grades {
|
for _, v := range grades {
|
||||||
lvl := &level.Level{}
|
lvl := &level.Level{}
|
||||||
lvl.Name = strconv.Itoa(v.Grade)
|
lvl.Name = strconv.Itoa(v.Grade)
|
||||||
out.Levels[lvl.Name] = lvl
|
g.Levels[lvl.Name] = lvl
|
||||||
lvl.SelectionWeight = v.Rate
|
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"))
|
rres, err := data.NewResultsFromFile(path.Join(datadir, "ResultTable", lvl.Name+".yaml"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -48,7 +52,7 @@ func NewFromRoot(datadir string) (*Game, error) {
|
||||||
lvl.SpecialTable = table.New(sres)
|
lvl.SpecialTable = table.New(sres)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return out, nil
|
return g, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *Game) RandomLevel() *level.Level {
|
func (g *Game) RandomLevel() *level.Level {
|
||||||
|
|
Loading…
Reference in New Issue