/rlglue/example/environment.go

https://code.google.com/p/go-glue/ · Go · 29 lines · 26 code · 3 blank · 0 comment · 1 complexity · c56a5b7433875f1f4bda4b4ce24015c5 MD5 · raw file

  1. package example
  2. import (
  3. "code.google.com/p/go-glue/rlglue"
  4. "fmt"
  5. "math/rand"
  6. )
  7. type Environment int
  8. func (re Environment) EnvInit() (taskString string) {
  9. format := "VERSION RL-Glue-3.0 PROBLEMTYPE episodic DISCOUNTFACTOR 1 OBSERVATIONS INTS (0 %d) ACTIONS INTS (0 1) REWARDS (0 1.0)"
  10. tstr := fmt.Sprintf(format, re-1)
  11. return tstr
  12. }
  13. func (re Environment) EnvStart() (obs rlglue.Observation) {
  14. return rlglue.NewObservation([]int32{rand.Int31n(int32(re))}, []float64{}, []byte{})
  15. }
  16. func (re Environment) EnvStep(action rlglue.Action) (obs rlglue.Observation, r float64, t bool) {
  17. obs = rlglue.NewObservation([]int32{rand.Int31n(int32(re))}, []float64{}, []byte{})
  18. r = -1
  19. t = rand.Intn(2) == 1
  20. return
  21. }
  22. func (re Environment) EnvCleanup() {
  23. }
  24. func (re Environment) EnvMessage(message string) (reply string) {
  25. return ""
  26. }