示例#1
0
 /// <summary>
 /// </summary>
 void Start()
 {
     this._Manager = FindObjectOfType <NeodroidManager>();
     if (Application.isPlaying)
     {
         var reset_reaction = new ReactionParameters(reset: true);
         this._states = this._Manager.ReactAndCollectStates(new Reaction(reset_reaction, "all"));
     }
 }
示例#2
0
        /// <inheritdoc />
        /// <summary>
        /// </summary>
        /// <returns></returns>
        public override Reaction SampleReaction()
        {
      #if NEODROID_DEBUG
            if (this.Debugging)
            {
                Debug.Log($"Sampling a reaction for environment {this.Identifier}");
            }
      #endif

            this._sample_motions.Clear();

            foreach (var actor in this.Actors)
            {
                var actor_value = actor.Value;
                if (actor_value != null && actor_value.Motors != null)
                {
                    foreach (var motor in actor_value.Motors)
                    {
                        var motor_value = motor.Value;
                        if (motor_value != null)
                        {
                            this._sample_motions.Add(new MotorMotion(actor.Key, motor.Key, motor_value.Sample()));
                        }
                    }
                }
            }

            if (this._Terminated)
            {
        #if NEODROID_DEBUG
                if (this.Debugging)
                {
                    Debug.Log("SampleReaction resetting environment");
                }
        #endif

                var reset_reaction =
                    new ReactionParameters(false, false, true, episode_count: true)
                {
                    IsExternal = false
                };
                return(new Reaction(reset_reaction, this.Identifier));
            }

            var rp = new ReactionParameters(true, true, episode_count: true)
            {
                IsExternal = false
            };
            return(new Reaction(rp, this._sample_motions.ToArray(), null, null, null, "", this.Identifier));
        }
        /// <inheritdoc />
        /// <summary>
        /// </summary>
        /// <returns></returns>
        public override Reaction SampleReaction()
        {
            if (this.Terminated)
            {
        #if NEODROID_DEBUG
                if (this.Debugging)
                {
                    Debug.Log("SampleReaction resetting environment");
                }
        #endif

                var reset_reaction = new ReactionParameters(StepResetObserve.Reset_, false, true);
                return(new Reaction(reset_reaction, this.Identifier));
            }

      #if NEODROID_DEBUG
            if (this.Debugging)
            {
                Debug.Log($"Sampling a reaction for environment {this.Identifier}");
            }
      #endif

            var sample_motions = new List <IMotion>();

            foreach (var actor in this.Actors)
            {
                var actor_value = actor.Value;
                if (actor_value?.Actuators != null)
                {
                    foreach (var actuator in actor_value.Actuators)
                    {
                        var actuator_value = actuator.Value;
                        if (actuator_value != null)
                        {
                            sample_motions.Add(new ActuatorMotion(actor.Key, actuator.Key, actuator_value.Sample()));
                        }
                    }
                }
            }

            var rp = new ReactionParameters(StepResetObserve.Step_, true, episode_count: true);
            return(new Reaction(rp,
                                sample_motions.ToArray(),
                                null,
                                null,
                                null,
                                "",
                                this.Identifier));
        }
示例#4
0
        /// <inheritdoc />
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        public override Reaction SampleReaction()
        {
            this._motions.Clear();

            var strength = Random.Range(0, 4);

            this._motions.Add(new MotorMotion("", "", strength));

            var rp = new ReactionParameters(true, true, episode_count: true)
            {
                IsExternal = false
            };

            return(new Reaction(rp, this._motions.ToArray(), null, null, null, ""));
        }
示例#5
0
        /// <inheritdoc />
        /// <summary>
        /// </summary>
        /// <returns></returns>
        public override Reaction SampleReaction()
        {
            this._motions.Clear();

            var strength = Random.Range(0, 4);

            this._motions.Add(new ActuatorMotion("", "", strength));

            var rp = new ReactionParameters(StepResetObserve.Step_, true, episode_count: true);

            return(new Reaction(rp,
                                this._motions.ToArray(),
                                null,
                                null,
                                null,
                                ""));
        }
示例#6
0
        void Update()
        {
            if (this._player_motions != null)
            {
                var motions = new List <MotorMotion> ();
                foreach (var player_motion in this._player_motions.Motions)
                {
                    if (Input.GetKey(player_motion.Key))
                    {
                        if (this.Debugging)
                        {
                            print(
                                string.Format(
                                    "{0} {1} {2}",
                                    player_motion.Actor,
                                    player_motion.Motor,
                                    player_motion.Strength));
                        }

                        var motion = new MotorMotion(player_motion.Actor, player_motion.Motor, player_motion.Strength);
                        motions.Add(motion);
                    }
                }

                var step       = motions.Count > 0;
                var parameters = new ReactionParameters(true, step)
                {
                    IsExternal = false
                };
                var reaction = new Reaction(parameters, motions.ToArray(), null, null);
                this._manager.React(reaction);
            }
            else
            {
                if (this.Debugging)
                {
                    print("No playermotions scriptable object assigned");
                }
            }
        }
示例#7
0
        public override Reaction SampleReaction()
        {
            var motions = new List <MotorMotion>();

            foreach (var actor in this.Actors)
            {
                foreach (var motor in actor.Value.Motors)
                {
                    var strength = Random.Range(
                        (int)motor.Value.MotionValueSpace.MinValue,
                        (int)(motor.Value.MotionValueSpace.MaxValue + 1));
                    motions.Add(new MotorMotion(actor.Key, motor.Key, strength));
                }
            }

            var rp = new ReactionParameters(true, true)
            {
                IsExternal = false
            };

            return(new Reaction(rp, motions.ToArray(), null, null));
        }
示例#8
0
        void Update()
        {
            if (Application.isPlaying)
            {
                if (this._states == null)
                {
                    var reset_reaction_parameters = new ReactionParameters(reset: true);
                    this._states = this._Manager.ReactAndCollectStates(new Reaction(reset_reaction_parameters, "all"));
                }

                var reset = false;
                if (this._player_motions != null)
                {
                    this._motions.Clear();
                    if (this._player_motions._Motions != null)
                    {
                        foreach (var player_motion in this._player_motions._Motions)
                        {
                            if (Input.GetKey(player_motion._Key))
                            {
                                if (this.Debugging)
                                {
                                    Debug.Log($"{player_motion._Actor} {player_motion._Motor} {player_motion._Strength}");
                                }

                                if (player_motion._Motor == "Reset")
                                {
                                    reset = true;
                                    break;
                                }

                                var motion = new MotorMotion(
                                    player_motion._Actor,
                                    player_motion._Motor,
                                    player_motion._Strength);
                                this._motions.Add(motion);
                            }
                        }
                    }

                    if (reset)
                    {
                        var reset_reaction_parameters = new ReactionParameters(reset: true);
                        this._states =
                            this._Manager.ReactAndCollectStates(new Reaction(reset_reaction_parameters, "all"));
                    }
                    else
                    {
                        var step = this._motions.Count > 0;
                        if (step)
                        {
                            foreach (var state in this._states)
                            {
                                if (this._auto_reset && state.Terminated)
                                {
                                    var reset_reaction = new ReactionParameters(reset: true)
                                    {
                                        IsExternal = false
                                    };
                                    this._Manager.ReactAndCollectStates(new Reaction(reset_reaction, state.EnvironmentName));
                                }
                            }

                            var parameters = new ReactionParameters(true, true, episode_count: true)
                            {
                                IsExternal = false
                            };
                            var reaction = new Reaction(parameters, this._motions.ToArray(), null, null, null, "");
                            this._states = this._Manager.ReactAndCollectStates(reaction);
                        }
                    }
                }
                else
                {
                    if (this.Debugging)
                    {
                        Debug.Log("No PlayerMotions ScriptableObject assigned");
                    }
                }
            }
        }