コード例 #1
0
        /// <summary>
        /// Steps the gym one or more steps with a given action.
        /// </summary>
        /// <param name="nAction">Specifies the action to run.</param>
        /// <param name="nSteps">Specifies the number of steps to run the action.</param>
        /// <returns>A tuple containing a double[] with the data, a double with the reward and a bool with the terminal state is returned.</returns>
        public CurrentState Step(int nAction, int nSteps = 1)
        {
            if (m_igym == null)
            {
                throw new Exception("You must call 'Initialize' first!");
            }

            for (int i = 0; i < nSteps - 1; i++)
            {
                m_igym.Step(nAction);
            }

            Tuple <State, double, bool> state = m_igym.Step(nAction);

            bool bIsOpen = (m_nUiId >= 0) ? true : false;
            Tuple <Bitmap, SimpleDatum> data = m_igym.Render(bIsOpen, 512, 512, true);
            int         nDataLen             = 0;
            SimpleDatum sd  = state.Item1.GetData(false, out nDataLen);
            Observation obs = new Observation(data.Item1, ImageData.GetImage(data.Item2), m_igym.RequiresDisplayImage, sd.GetData <double>(), state.Item2, state.Item3);

            if (bIsOpen)
            {
                if (m_rgrgActionDistributions != null)
                {
                    overlay(obs.ImageDisplay, m_rgrgActionDistributions);
                }

                m_gymui.Render(m_nUiId, obs);
                Thread.Sleep(m_igym.UiDelay);
            }

            if (m_igym.SelectedDataType == DATA_TYPE.BLOB)
            {
                sd = data.Item2;
            }
            else
            {
                sd.Clip(nDataLen, null, nDataLen, null);
            }

            m_state = new Tuple <SimpleDatum, double, bool>(sd, state.Item2, state.Item3);

            return(new CurrentState(m_state.Item1.GetData <double>(), m_state.Item2, m_state.Item3));
        }