/// <summary> /// Shutdown and close the gym. /// </summary> public void Close() { if (m_ale != null) { m_ale.Shutdown(); m_ale = null; } }
/// <summary> /// Release all resources used. /// </summary> public void Dispose() { if (m_ale != null) { m_ale.Shutdown(); m_ale = null; } if (m_bmpRaw != null) { m_bmpRaw.Dispose(); m_bmpRaw = null; } if (m_bmpActionRaw != null) { m_bmpActionRaw.Dispose(); m_bmpActionRaw = null; } }
/// <summary> /// Initialize the gym with the specified properties. /// </summary> /// <param name="log">Specifies the output log to use.</param> /// <param name="properties">Specifies the properties containing Gym specific initialization parameters.</param> /// <remarks> /// The AtariGym uses the following initialization properties. /// GameRom='path to .rom file' /// </remarks> public void Initialize(Log log, PropertySet properties) { m_log = log; if (m_ale != null) { m_ale.Shutdown(); m_ale = null; } m_ale = new ALE(); m_ale.Initialize(); m_ale.EnableDisplayScreen = false; m_ale.EnableSound = false; m_ale.EnableColorData = properties.GetPropertyAsBool("EnableColor", false); m_ale.EnableRestrictedActionSet = true; m_ale.EnableColorAveraging = true; m_ale.AllowNegativeRewards = properties.GetPropertyAsBool("AllowNegativeRewards", false); m_ale.EnableTerminateOnRallyEnd = properties.GetPropertyAsBool("TerminateOnRallyEnd", false); m_ale.RandomSeed = (int)DateTime.Now.Ticks; m_ale.RepeatActionProbability = 0.0f; // disable action repeatability if (properties == null) { throw new Exception("The properties must be specified with the 'GameROM' set the the Game ROM file path."); } string strROM = properties.GetProperty("GameROM"); if (strROM.Contains('~')) { strROM = Utility.Replace(strROM, '~', ' '); } else { strROM = Utility.Replace(strROM, "[sp]", ' '); } if (!File.Exists(strROM)) { throw new Exception("Could not find the game ROM file specified '" + strROM + "'!"); } if (properties.GetPropertyAsBool("UseGrayscale", false)) { m_ct = COLORTYPE.CT_GRAYSCALE; } m_bPreprocess = properties.GetPropertyAsBool("Preprocess", true); m_bForceGray = properties.GetPropertyAsBool("ActionForceGray", false); m_bEnableNumSkip = properties.GetPropertyAsBool("EnableNumSkip", true); m_nFrameSkip = properties.GetPropertyAsInt("FrameSkip", -1); m_ale.Load(strROM); m_rgActionsRaw = m_ale.ActionSpace; m_random = new CryptoRandom(); m_rgFrameSkip = new List <int>(); if (m_nFrameSkip < 0) { for (int i = 2; i < 5; i++) { m_rgFrameSkip.Add(i); } } else { m_rgFrameSkip.Add(m_nFrameSkip); } m_rgActions.Add(ACTION.ACT_PLAYER_A_LEFT.ToString(), (int)ACTION.ACT_PLAYER_A_LEFT); m_rgActions.Add(ACTION.ACT_PLAYER_A_RIGHT.ToString(), (int)ACTION.ACT_PLAYER_A_RIGHT); if (!properties.GetPropertyAsBool("EnableBinaryActions", false)) { m_rgActions.Add(ACTION.ACT_PLAYER_A_FIRE.ToString(), (int)ACTION.ACT_PLAYER_A_FIRE); } m_rgActionSet = m_rgActions.ToList(); Reset(false); }