public LucPacMCTS() : base("LucPacMCTS") { _greenBlock = Image.FromFile("green_block.png"); _redBlock = Image.FromFile("red_block.png"); _blueBlock = Image.FromFile("blue_block.png"); LucPac._greenBlock = _greenBlock = Image.FromFile("green_block.png"); LucPac._redBlock = Image.FromFile("red_block.png"); LucPac._blueBlock = Image.FromFile("blue_block.png"); _instance = this; // Create the session ID that will be used for testing this._testSessionId = GenerateSessionID(); this._testStats.SessionID = _testSessionId; // Create the directory that the data is going to be stored in _testDataFolder = Directory.CreateDirectory(Environment.CurrentDirectory + string.Format("/{0}", _testSessionId)); _testImagesFolder = _testDataFolder.CreateSubdirectory("images"); _testLogFolder = _testDataFolder.CreateSubdirectory("logs"); _stopWatch.Start(); this.Milliseconds = 0; this.LastLifeMilliseconds = 0; this.LastRoundMilliseconds = 0; this.GameStartTimestamp = DateTime.Now; // For determining how long it took to complete level. this.LifeStartTimestamp = GameStartTimestamp; }
/// <summary> /// Save a given game state to an image /// </summary> /// <param name="pGameState">The game state that we wish to render it to</param> /// <param name="pController">The controller that we are obtaining information from</param> /// <param name="pImageName">The name of the image once we write it to disk</param> /// <param name="pRenderMCTS">Whether or not we render the tree for the MCTS agent</param> public static void SaveStateAsImage(GameState pGameState, LucPacMCTS pController, string pImageName, bool pRenderMCTS) { // Clone the image that we are going to be rendering to Image _newimage = (Image)Visualizer.RenderingImage.Clone(); Graphics _drawingObject = Graphics.FromImage(_newimage); _drawingObject.DrawImage(_redBlock, new Point(50, 50)); // Draw the map, pacman and the ghosts to the image pGameState.Map.Draw(_drawingObject); pGameState.Pacman.Draw(_drawingObject, Visualizer.RenderingSprites); foreach (var item in pGameState.Ghosts) { item.Draw(_drawingObject, Visualizer.RenderingSprites); } // Determine whether or not the tree root is valid before // continuing if (pController.TreeRoot != null) { _drawingObject.DrawImage(_greenBlock, new Point()); // Draw the output accordingly. pController.TreeRoot.Draw(_drawingObject); _drawingObject.DrawImage(_redBlock, new Point(pController.TreeRoot.PathNode.CenterX, pController.TreeRoot.PathNode.CenterY)); } string _filename = ""; if (pImageName != "") { _filename = pImageName; } else { _filename = "screengrab"; } // Save the image out so that we can observe it _newimage.Save(string.Format("{2}\\{0}_{1}_{3}.bmp", DateTime.Now.ToString("ddMMyyyyHHmmssff"), _filename, pController._testImagesFolder.FullName, pController._testStats.TotalGames)); _newimage.Dispose(); }
public LucPacMCTS() : base("LucPacMCTS") { instance = this; // Create the session ID that will be used for testing this.m_TestSessionID = GenerateSessionID(); this.m_TestStats.SessionID = m_TestSessionID; // Create the directory that the data is going to be stored in //m_TestDataFolder = Directory.CreateDirectory(Environment.CurrentDirectory + string.Format("/{0}", m_TestSessionID)); //m_TestImagesFolder = m_TestDataFolder.CreateSubdirectory("images"); //m_TestLogFolder = m_TestDataFolder.CreateSubdirectory("logs"); m_Stopwatch.Start(); this.m_MS = 0; this.m_LastLifeMS = 0; this.m_LastRoundMS = 0; m_GameStart = DateTime.Now; // For determining how long it took to complete level. m_LifeStart = m_GameStart; }