void Run() { //preparing Console Console.Clear(); Console.CursorVisible = false; _drawer = new ConsoleDrawing(); ConsoleDrawing.ShowControls(); form = new Form(); form.Width = 1920; form.Height = 1080; graphViewportPainter = new IOGraphViewportPainter(new IOGraphPainter()); graphControl = new GraphControl(); graphControl.ViewportPainter = graphViewportPainter; graphControl.Width = form.Width; graphControl.Height = form.Height; form.Controls.Add(graphControl); form.Show(); form.Visible = false; tetrisAI = new TetrisAI(this, (x) => { if (++saveCount >= 20) { saveCount = 0; Task.Run(() => form.Invoke((MethodInvoker) delegate { tetrisAI.Save(); Console.WriteLine("Network saved!"); })); } }, HandleNewBestNetwork, File.Exists("SavedProgress.xml")); tetrisAI.StartTraining(); Task.Run(() => { while (KeyPressedHandler(Console.ReadKey())) { ; } form.Invoke((MethodInvoker) delegate { form.Close(); }); }); form.ShowDialog(); tetrisAI.StopTraining(); tetrisAI.Save(); Console.ResetColor(); Console.CursorVisible = true; }
static int Main(string[] args) { //preparing Console Console.Clear(); Console.CursorVisible = false; _drawer = new ConsoleDrawing(); ConsoleDrawing.ShowControls(); Console.ReadKey(true); Console.Clear(); _game = new Game(null); _game.Start(); _gameTimer = new System.Timers.Timer(800); _gameTimer.Elapsed += new ElapsedEventHandler(OnTimedEvent); _gameTimer.Start(); _drawer.DrawScene(_game); controller = new Controller(0); if (controller.IsConnected) { controllerPollTimer = new System.Timers.Timer(50); controllerPollTimer.Elapsed += ControllerPoll; controllerPollTimer.Start(); prevControllerState = controller.GetState(); } while (_game.Status != Game.GameStatus.Finished) { if (Console.KeyAvailable) { KeyPressedHandler(Console.ReadKey(true)); _drawer.DrawScene(_game); _gameTimer.Enabled = true; } } _gameTimer.Stop(); _drawer.ShowGameOver(_game); Console.ResetColor(); Console.CursorVisible = true; return(0); }
void Run() { //preparing Console Console.Clear(); Console.CursorVisible = false; _drawer = new ConsoleDrawing(); ConsoleDrawing.ShowControls(); tetrisAI = new TetrisAI(this, (x) => Console.WriteLine("Generation: " + x), (x) => Console.WriteLine("Top Fitness: " + x)); tetrisAI.StartTraining(); while (KeyPressedHandler(Console.ReadKey(true))) { } Console.ResetColor(); Console.CursorVisible = true; }
static int Main(string[] args) { //preparing Console Console.Clear(); Console.CursorVisible = false; _drawer = new ConsoleDrawing(); _ramDrawer = new RamDrawing(); ConsoleDrawing.ShowControls(); Console.ReadKey(true); Console.Clear(); _game = new Game(_ramDrawer.Ram.Count, _ramDrawer.Ram.Max(r => r.Count())); _game.Start(); _gameTimer = new System.Timers.Timer(800); _gameTimer.Elapsed += new ElapsedEventHandler(OnTimedEvent); _gameTimer.Start(); _drawer.DrawScene(_game); _ramDrawer.DrawScene(_game); while (_game.Status != Game.GameStatus.Finished) { if (Console.KeyAvailable) { KeyPressedHandler(Console.ReadKey(true)); _drawer.DrawScene(_game); _ramDrawer.DrawScene(_game); _gameTimer.Enabled = true; } } _gameTimer.Stop(); _drawer.ShowGameOver(_game); Console.ResetColor(); Console.CursorVisible = true; return(0); }