func NewEnv(belief *Belief) (this *Env) { this = new(Env) this.numActions = len(belief.counts) this.belief = belief this.obs = rlglue.NewObservation([]int32{0}, nil, nil) return }
func (this *Env) MakeObs() (obs rlglue.Observation) { k := this.hunter.x + this.hunter.y*4 this.observed[k] = this.hunter.belief[k] intarray := []int32{this.hunter.x, this.hunter.y, this.hunter.dir} indices := make([]int32, 16) for i, v := range this.observed { indices[i] = GetIndex(v) } intarray = append(intarray, indices...) obs = rlglue.NewObservation(intarray, []float64{}, []byte{}) return }
func (this *Environment) ConstructObs() (obs rlglue.Observation) { ints := make([]int32, this.cfg.NumSystems) for i := range ints { if this.status[i] { ints[i] = 1 } } obs = rlglue.NewObservation(ints, []float64{}, []byte{}) this.hash = this.task.Obs.Ints.Index(ints) count++ return }
func (this *Env) makeObs() (obs rlglue.Observation) { ints := make([]int32, 4*len(this.Cans)) for i, can := range this.Cans { if can.Painted { ints[i*4] = 1 } if can.Polished { ints[i*4+1] = 1 } if can.Scratched { ints[i*4+2] = 1 } if can.Done { ints[i*4+3] = 1 } } obs = rlglue.NewObservation(ints, []float64{}, []byte{}) return }
func (ge *Env) EnvStep(action rlglue.Action) (obs rlglue.Observation, r float64, t bool) { t = ge.Pos.Equals(ge.Goal) r = -1 if t { r = 0 } dir := action.Ints()[0] u := rand.Float64() if u < .1 { dir += 1 } else if u < .2 { dir += 3 } dir %= 4 newPos := ge.Pos switch dir { case 0: newPos.Y++ case 1: newPos.X++ case 2: newPos.Y-- case 3: newPos.X-- } if newPos.X < 0 { newPos.X = 0 } if newPos.Y < 0 { newPos.Y = 0 } if newPos.X >= ge.Width { newPos.X = ge.Width - 1 } if newPos.Y >= ge.Height { newPos.Y = ge.Height - 1 } ge.Pos = newPos obs = rlglue.NewObservation([]int32{ge.Pos.X, ge.Pos.Y}, []float64{}, []byte{}) return }
func (this *Env) EnvStart() (obs rlglue.Observation) { startState := discrete.State(stat.NextRange(int64(this.mdp.GetTask().Obs.Ints.Count()))) obs = rlglue.NewObservation(this.mdp.GetTask().Obs.Ints.Values(startState.Hashcode()), []float64{}, []byte{}) this.LastState = startState return }
func (ge *Env) EnvStart() (obs rlglue.Observation) { ge.Pos = ge.Start obs = rlglue.NewObservation([]int32{ge.Pos.X, ge.Pos.Y}, []float64{}, []byte{}) return }