2 using System.Collections.Generic;
11 namespace droid.Runtime.Environments {
15 [AddComponentMenu(
"Neodroid/Environments/ScriptedEnvironment")]
20 Renderer _actor_renderer = null;
35 Renderer _goal_renderer = null;
56 List<IMotion> _motions =
new List<IMotion>();
61 IManager _time_simulation_manager = null;
71 public override string PrototypingTypeName {
get {
return "ScriptedEnvironment"; } }
76 get {
return this._actor_x; }
77 set { this._actor_x = Mathf.Max(0, Mathf.Min(
this._width - 1, value)); }
83 get {
return this._actor_y; }
84 set { this._actor_y = Mathf.Max(0, Mathf.Min(
this._height - 1, value)); }
90 get {
return this._goal_x; }
91 set { this._goal_x = Mathf.Max(0, Mathf.Min(
this._width - 1, value)); }
97 get {
return this._goal_y; }
98 set { this._goal_y = Mathf.Max(0, Mathf.Min(
this._height - 1, value)); }
105 this._grid =
new int[this._width, this._height];
108 for (var i = 0; i < this._width; i++) {
109 for (var j = 0; j < this._height; j++) {
110 this._grid[i, j] = k++;
114 this._time_simulation_manager =
122 if (this._goal_renderer) {
123 this._goal_renderer.transform.position =
new Vector3(this.GoalX, 0, this.GoalY);
126 if (this._actor_renderer) {
127 this._actor_renderer.transform.position =
new Vector3(this.ActorX, 0, this.ActorY);
136 this._motions.Clear();
138 var strength =
Random.Range(0, 4);
141 var rp =
new ReactionParameters(
true,
true, episode_count :
true) {IsExternal =
false};
142 return new Reaction(rp, this._motions.ToArray(), null, null, null,
"");
152 this.React(reaction);
153 return this.CollectState();
157 foreach (var motion
in reaction.Motions) {
158 switch ((
int)motion.Strength) {
172 throw new ArgumentOutOfRangeException();
180 public override void Tick() { }
183 var actor_idx = this._grid[this.ActorX, this.ActorY];
184 var goal_idx = this._grid[this.GoalX, this.GoalY];
186 var terminated = actor_idx == goal_idx;
187 var signal = terminated ? 1 : 0;
189 var time = Time.time - this._Lastest_Reset_Time;
191 var observables =
new float[] {actor_idx};
193 return new EnvironmentState(this.Identifier, 0, 0, time, signal, terminated, ref observables);
201 recipient.
PollData(this.CollectState().ToString());
Has a possible direction given by the sign of the float in strength
abstract void PollData(dynamic data)
override EnvironmentState CollectState()
override void ObservationsString(DataPoller recipient)
override void React(Reaction reaction)
override Reaction SampleReaction()
override void EnvironmentReset()
override EnvironmentState ReactAndCollectState(Reaction reaction)