PageRenderTime 22ms CodeModel.GetById 15ms app.highlight 5ms RepoModel.GetById 2ms app.codeStats 0ms

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