Esempio n. 1
0
        /// <summary>
        /// Performs a single environment update to the Academy, Brain and Agent
        /// objects within the environment.
        /// </summary>
        void EnvironmentStep()
        {
            if (m_ModeSwitched)
            {
                ConfigureEnvironment();
                m_ModeSwitched = false;
            }

            if ((m_IsCommunicatorOn) &&
                (m_LastCommunicatorMessageNumber != m_BrainBatcher.GetNumberMessageReceived()))
            {
                m_LastCommunicatorMessageNumber = m_BrainBatcher.GetNumberMessageReceived();
                if (m_BrainBatcher.GetCommand() ==
                    CommunicatorObjects.CommandProto.Reset)
                {
                    UpdateResetParameters();

                    SetIsInference(!m_BrainBatcher.GetIsTraining());

                    ForcedFullReset();
                }

                if (m_BrainBatcher.GetCommand() ==
                    CommunicatorObjects.CommandProto.Quit)
                {
#if UNITY_EDITOR
                    EditorApplication.isPlaying = false;
#endif
                    Application.Quit();
                    return;
                }
            }
            else if (!m_FirstAcademyReset)
            {
                UpdateResetParameters();
                ForcedFullReset();
            }

            AgentSetStatus(m_StepCount);

            AgentResetIfDone();

            AgentSendState();

            BrainDecideAction();

            AcademyStep();

            AgentAct();

            m_StepCount      += 1;
            m_TotalStepCount += 1;
        }
Esempio n. 2
0
        /// <summary>
        /// Performs a single environment update to the Academy, Brain and Agent
        /// objects within the environment.
        /// </summary>
        void EnvironmentStep()
        {
            if (modeSwitched)
            {
                ConfigureEnvironment();
                modeSwitched = false;
            }

            if ((isCommunicatorOn) &&
                (lastCommunicatorMessageNumber != brainBatcher.GetNumberMessageReceived()))
            {
                lastCommunicatorMessageNumber = brainBatcher.GetNumberMessageReceived();
                if (brainBatcher.GetCommand() ==
                    CommandProto.Reset)
                {
                    // Update reset parameters.
                    var newResetParameters = brainBatcher.GetEnvironmentParameters();
                    if (newResetParameters != null)
                    {
                        foreach (var kv in newResetParameters.FloatParameters)
                        {
                            resetParameters[kv.Key] = kv.Value;
                        }
                    }

                    SetIsInference(!brainBatcher.GetIsTraining());

                    ForcedFullReset();
                }

                if (brainBatcher.GetCommand() ==
                    CommandProto.Quit)
                {
#if UNITY_EDITOR
                    EditorApplication.isPlaying = false;
#endif
                    Application.Quit();
                    return;
                }
            }
            else if (!firstAcademyReset)
            {
                ForcedFullReset();
            }

            if ((stepCount >= maxSteps) && maxSteps > 0)
            {
                maxStepReached = true;
                Done();
            }

            AgentSetStatus(maxStepReached, done, stepCount);

            brainBatcher.RegisterAcademyDoneFlag(done);

            if (done)
            {
                EnvironmentReset();
            }

            AgentResetIfDone();

            AgentSendState();

            BrainDecideAction();

            AcademyStep();

            AgentAct();

            stepCount += 1;
        }