func (a *File) Restore(ctx neat.Context) error { // Restore the settings name := a.makePath("config") f, err := os.Open(name) if err != nil { return err } d := json.NewDecoder(f) if err = d.Decode(&ctx); err != nil { f.Close() return err } f.Close() // Restore the state values for k, v := range ctx.State() { name := a.makePath(k) if _, err := os.Stat(name); os.IsNotExist(err) { continue } f, err = os.Open(name) if err != nil { return err } d = json.NewDecoder(f) if err = d.Decode(&v); err != nil { f.Close() return err } f.Close() } return nil }
func (s *Novelty) SetContext(x neat.Context) error { x.State()["novelty-behaviors"] = &s.behaviors if cx, ok := s.Searcher.(neat.Contextable); ok { return cx.SetContext(x) } return nil }
func (a *File) Archive(ctx neat.Context) error { // Save the settings name := a.makePath("config") var dir = path.Dir(name) if _, err := os.Stat(dir); err != nil { if os.IsNotExist(err) { os.MkdirAll(dir, os.ModePerm) } else { // other error } } f, err := os.Create(name) if err != nil { panic(err) return err } b, err := json.MarshalIndent(ctx, "", " ") if err != nil { f.Close() return err } f.Write(b) f.Close() // Save the state values for k, v := range ctx.State() { name := a.makePath(k) f, err = os.Create(name) if err != nil { return err } b, err := json.MarshalIndent(v, "", " ") if err != nil { f.Close() return err } f.Write(b) f.Close() } return nil }
func (v *Web) SetContext(x neat.Context) error { v.ctx = x x.State()["web-fitness"] = &v.fitness x.State()["web-complexity"] = &v.complexity x.State()["web-species"] = &v.species x.State()["web-best"] = &v.best return nil }