private void update(COLORTYPE ct, byte[] rg, int nWid, int nHt, float fTotalReward) { Bitmap bmp = new Bitmap(nWid, nHt); for (int y = 0; y < nHt; y++) { for (int x = 0; x < nWid; x++) { int nIdx = (y * nWid) + x; int nR = rg[nIdx]; int nG = nR; int nB = nR; if (ct == COLORTYPE.CT_COLOR) { nG = rg[nIdx + (nWid * nHt * 1)]; nB = rg[nIdx + (nWid * nHt * 2)]; } Color clr = Color.FromArgb(nR, nG, nB); bmp.SetPixel(x, y, clr); } } pbGame.Image = bmp; tsReward.Text = "Total reward = " + fTotalReward.ToString("N2"); }
public ColorNode(int x, int y) : base("Color Node", new SerializableRect(x, y, 200, 150)) { type = lastType = ColorNode.COLORTYPE.COLOR; gradient = new Gradient(); if (gradientColorKeys != null && gradientAlphaKeys != null) { gradient.colorKeys = SerializableGradientColorKey.ToGradientColorKeys(gradientColorKeys); gradient.alphaKeys = SerializableGradientAlphaKey.ToGradientColorKeys(gradientAlphaKeys); } color = new SerializableColor(Color.black); SetInputs(); }
public ColorNode(int x, int y) : base("Color Node", new SerializableRect(x, y, 200, 150)) { type = lastType = ColorNode.COLORTYPE.COLOR; gradient = new Gradient(); if(gradientColorKeys != null && gradientAlphaKeys != null) { gradient.colorKeys = SerializableGradientColorKey.ToGradientColorKeys(gradientColorKeys); gradient.alphaKeys = SerializableGradientAlphaKey.ToGradientColorKeys(gradientAlphaKeys); } color = new SerializableColor(Color.black); SetInputs(); }
private Tuple <DirectBitmap, SimpleDatum> getData(COLORTYPE ct, int nWid, int nHt, int nOffset, int nDownsample, byte[] rg, bool bPreprocess, bool bGetAction, bool bForceGray) { int nChannels = (bPreprocess || bForceGray) ? 1 : 3; int nSize = Math.Min(nWid, nHt); int nDsSize = nSize / nDownsample; int nX = 0; int nY = 0; bool bY = false; bool bX = false; if (m_bmpRaw != null && (m_bmpRaw.Width != nWid || m_bmpRaw.Height != nHt)) { m_bmpRaw.Dispose(); m_bmpRaw = null; } if (m_bmpActionRaw != null && (m_bmpActionRaw.Width != nDsSize || m_bmpActionRaw.Height != nDsSize)) { m_bmpActionRaw.Dispose(); m_bmpActionRaw = null; } if (m_bmpRaw == null) { m_bmpRaw = new DirectBitmap(nWid, nHt); } if (m_bmpActionRaw == null) { m_bmpActionRaw = new DirectBitmap(nDsSize, nDsSize); } DirectBitmap bmp = m_bmpRaw; Valuemap dataV = null; Bytemap dataB = null; if (bGetAction) { if (m_bPreprocess) { dataV = new Valuemap(nChannels, nDsSize, nDsSize); } else { dataB = new Bytemap(nChannels, nDsSize, nDsSize); } } for (int y = 0; y < nHt; y++) { if (y % nDownsample == 0 && y > nOffset && y < nOffset + nSize) { bY = true; } else { bY = false; } for (int x = 0; x < nWid; x++) { int nIdx = (y * nWid) + x; int nR = rg[nIdx]; int nG = nR; int nB = nR; if (x % nDownsample == 0) { bX = true; } else { bX = false; } if (ct == COLORTYPE.CT_COLOR) { nG = rg[nIdx + (nWid * nHt * 1)]; nB = rg[nIdx + (nWid * nHt * 2)]; } Color clr = Color.FromArgb(nR, nG, nB); bmp.SetPixel(x, y, clr); if (bForceGray) { int nClr = (nR + nG + nB) / 3; clr = Color.FromArgb(nClr, nClr, nClr); } if (bY && bX && (dataB != null || dataV != null)) { if (bPreprocess) { if (nR != 144 && nR != 109 && nR != 0) { dataV.SetPixel(nX, nY, 1.0); } } else { dataB.SetPixel(nX, nY, clr); } nX++; } } if (bY) { nX = 0; nY++; } } SimpleDatum sd = null; if (m_bPreprocess) { if (dataV != null) { sd = new SimpleDatum(dataV); } } else { if (dataB != null) { sd = new SimpleDatum(dataB); } } return(new Tuple <DirectBitmap, SimpleDatum>(bmp, sd)); }
/// <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); }
public ZenColor(string name) { Name = name; Type = COLORTYPE.BYNAME; }
public ZenColor(float red, float green, float blue, float alpha) { Red = red; Green = green; Blue = blue; Type = COLORTYPE.REDGREENBLUE; }
public ZenColor(float white, float alpha) { White = white; Alpha = alpha; Type = COLORTYPE.WHITEONLY; }
private void radGray_CheckedChanged(object sender, EventArgs e) { m_ct = COLORTYPE.CT_GRAYSCALE; }
private void radColor_CheckedChanged(object sender, EventArgs e) { m_ct = COLORTYPE.CT_COLOR; }