/rlglue/tests/test_empty_environment.go

https://code.google.com/p/go-glue/ · Go · 44 lines · 41 code · 3 blank · 0 comment · 7 complexity · 48181e83275a7dad6d15bddc2f3ff87e MD5 · raw file

  1. package main
  2. import (
  3. "go-glue.googlecode.com/hg/rlglue"
  4. )
  5. type EmptyEnv struct {
  6. whichEpisode int
  7. emptyObs rlglue.Observation
  8. nonEmptyObs rlglue.Observation
  9. }
  10. func (re *EmptyEnv) EnvInit() string {
  11. re.emptyObs = rlglue.NewObservation([]int32{}, []float64{}, []byte{})
  12. re.nonEmptyObs = rlglue.NewObservation([]int32{0, 1}, []float64{0.0 / 4.0, 1.0 / 4.0, 2.0 / 4.0, 3.0 / 4.0}, []byte{'a', 'b', 'c', 'd', 'e'})
  13. return ""
  14. }
  15. func (re *EmptyEnv) EnvStart() rlglue.Observation {
  16. re.whichEpisode += 1
  17. if re.whichEpisode%2 == 0 {
  18. return re.emptyObs
  19. }
  20. return re.nonEmptyObs
  21. }
  22. func (re *EmptyEnv) EnvStep(action rlglue.Action) (obs rlglue.Observation, r float64, t bool) {
  23. if re.whichEpisode%2 == 0 {
  24. obs = re.emptyObs
  25. } else {
  26. obs = re.nonEmptyObs
  27. }
  28. r = 0
  29. t = false
  30. return
  31. }
  32. func (re *EmptyEnv) EnvCleanup() {
  33. }
  34. func (re *EmptyEnv) EnvMessage(message string) (reply string) {
  35. return
  36. }
  37. func main() {
  38. if err := rlglue.LoadEnvironment(new(EmptyEnv)); err != nil {
  39. panic(err)
  40. }
  41. }