// constructor for Encog public WindowLessTraining(int mazeId, int totalIterations, int maxTemp, int minTemp, int encogCycles) { InitializeComponent(); mazerepo = new MazeRepo(); maze = mazerepo.GetByID(mazeId); MazeId = mazeId; TotalIterations = totalIterations; this.maxTemp = maxTemp; this.minTemp = minTemp; this.encogCycles = encogCycles; isEncog = true; lbl1.Content = "# of Iterations:"; lbl2.Content = "Iterations done:"; lbl3.Content = "# of Cycles per:"; lbl4.Content = "Cycles done:"; lbl5.Visibility = Visibility.Hidden; lblMazeName.Content = maze.Name; lblSessionCount.Content = totalIterations.ToString(); lblCurrentSession.Content = 0; lblMoveCount.Content = encogCycles.ToString(); lblSessionsCompleted.Content = 0; lblRandomness.Visibility = Visibility.Hidden; this.Title = "No Maze Encog Learning"; }
private void btnPlay_Click(object sender, RoutedEventArgs e) { try { // Human if (cmbPlayer.SelectedIndex == 0) { win = new MainWindow(MazeId, PlayerType.Human); win.Closed += (s, ev) => { this.Visibility = Visibility.Visible; }; win.Show(); this.Visibility = System.Windows.Visibility.Hidden; } else if (cmbPlayer.SelectedIndex == 1) // RNN AI { var selectedMaze = mazeRepo.GetByID(MazeId); if (selectedMaze != null) { var hasLearned = RlmUtils.RLMHasTrainingData("RLM_maze_" + selectedMaze.Name); if (hasLearned) { win = new MainWindow(MazeId, PlayerType.RNN, false); win.Closed += (s, ev) => { this.Visibility = Visibility.Visible; }; win.Show(); this.Visibility = System.Windows.Visibility.Hidden; } else { Xceed.Wpf.Toolkit.MessageBox.Show("You must first train the AI with the selected maze.", "Warning", MessageBoxButton.OK, MessageBoxImage.Exclamation); } } else { Xceed.Wpf.Toolkit.MessageBox.Show("You must select a maze.", "Warning", MessageBoxButton.OK, MessageBoxImage.Exclamation); } } else // Encog AI { win = new MainWindow(MazeId, PlayerType.Encog); win.Closed += (s, ev) => { this.Visibility = Visibility.Visible; }; win.Show(); this.Visibility = System.Windows.Visibility.Hidden; } } catch (Exception err) { if (err.InnerException != null && err.InnerException is RlmDefaultConnectionStringException) { Xceed.Wpf.Toolkit.MessageBox.Show($"Error: {err.InnerException.Message}"); } else { Xceed.Wpf.Toolkit.MessageBox.Show($"ERROR: {err.Message}"); } } }
public MazeCreator(int mazeId = -1) { InitializeComponent(); var repo = new MazeRepo(); if (mazeId != -1) //we are editing the maze { generated = false; MazeId = mazeId; editMode = true; ResetGrid(); var mazeToEdit = repo.GetByID(mazeId); width = mazeToEdit.Width; height = mazeToEdit.Height; generator.GoalLocation = mazeToEdit.GoalPosition; generator.StartingPosition = mazeToEdit.StartingPosition; generator.TheMazeGrid = mazeToEdit.Grid; generator.PerfectGameMovesCount = mazeToEdit.PerfectGameMovesCount; mazeName = mazeToEdit.Name; txtBoxHeight.Text = height.ToString(); txtBoxWidth.Text = width.ToString(); txtBoxMazeName.Text = mazeToEdit.Name; lblMoveCount.Content = $"Perfect Move Count: {mazeToEdit.PerfectGameMovesCount}"; this.Title = $"Maze Designer Editing {mazeToEdit.Name}"; initializeGrid(mazeGrid, width, height); generateMaze(mazeGrid); } else { editMode = false; ResetGrid(); //initialize the grid with all the blocks initializeGrid(mazeGrid, width, height); //build the maze generator.Generate(width, height); //Generate the maze in the UI generateMaze(mazeGrid); int mazeCount = repo.Count(); txtBoxMazeName.Text = $"New Maze({mazeCount + 1})"; generated = true; } }
// constructor for RNN public WindowLessTraining(int mazeId, Boolean learn, int totalIterations, int temp_num_sessions, int startRandomness = 1, int endRandomness = 1) { InitializeComponent(); mazerepo = new MazeRepo(); maze = mazerepo.GetByID(mazeId); MazeId = mazeId; Learn = learn; TotalIterations = totalIterations; Temp_num_sessions = temp_num_sessions; StartRandomness = startRandomness; EndRandomness = endRandomness; isEncog = false; lblMazeName.Content = maze.Name; lblCurrentSession.Content = 1; lblSessionCount.Content = totalIterations.ToString(); lblMoveCount.Content = 0; this.Title = "No Maze RNN Learning"; }
public MainWindow(int mazeId, PlayerType type, Boolean learn = false, int temp_num_sessions = 1, int currentIteration = 1, int totalIterations = 1, int startRandomness = 1, int endRandomness = 1) { InitializeComponent(); mazerepo = new MazeRepo(); mazeInfo = mazerepo.GetByID(mazeId); RandomnessOver = temp_num_sessions; ClosedDueToGameOver = false; Learn = learn; Type = type; if (Type == PlayerType.Human) { this.Title = "Human Player"; StatusText.Visibility = Visibility.Visible; } else if (Type == PlayerType.RNN) { if (learn) { Temp_num_sessions = totalIterations; StartRandomness = startRandomness; EndRandomness = endRandomness; this.Title = "RNN Learning"; statGrid.Visibility = Visibility.Visible; lblMazeName.Content = mazeInfo.Name; lblTotalSession.Content = totalIterations; lblCurrentSession.Content = CurrentIteration = currentIteration; lblScore.Content = LastScore; lblMoves.Content = LastMovesCount; } else { this.Title = "RNN Player"; } } else { this.Title = "Encog Player"; } game = new MazeGameLib.MazeGame(); maze = new Maze(); game.InitGame(mazeInfo); //Initialize Grid game.TheMazeGrid = mazeInfo.Grid; maze.InitializeMaze(game, mazeGrid); //Init Game //game.InitGame(this.MainGrid, new RunThreadUI_Delegate(RunUIThread)); //Send Keys to Game if (Type == PlayerType.Human) { this.KeyDown += MainWindow_KeyDown; } // reset static session count if (currentIteration == 1) { //RNNMazeTraveler.ResestStaticSessionData(); } //Send shutdown event to game //this.Closed += MainWindow_Closed; }