public string SolveBoard(string path, int rows, int cols, int width, int height, int w_off, int h_off) { path = Uri.UnescapeDataString(path); Console.WriteLine(path); Bitmap bmp = new Bitmap(path); Board b = PadImage.BoardFromBitmap(rows, cols, height, width, h_off, w_off, bmp); return(JsonConvert.SerializeObject(DfsSolver.GetBestPath(b))); }
public void Configure(IApplicationBuilder app) { app.UseMvc(); return; app.Run(async(context) => { try { Board b = new Board(4, 4); Array vals = Enum.GetValues(typeof(Orb)); for (int i = 0; i < b.Height; i++) { for (int j = 0; j < b.Width; j++) { b.Orbs[i, j] = (i + j) % 2 == 0 ? Orb.Red : Orb.Blue; b.Orbs[i, j] = (Orb)vals.GetValue(1 + (i + j) % 5); } } var p = DfsSolver.GetBestPath(b); var b2 = b.GetBoardsAfterPath(p.Start.Item1, p.Start.Item2, p.Actions); Board opt = SAASSolver.GetOptimalBoards(b, SAASSolver.Options.Default, BoardScorer.Options.Horus).First(); var b3 = new Board(opt); b3.GetCombos(false); var p2 = SAASSolver.GetBestPath(b, SAASSolver.Options.Default, BoardScorer.Options.Horus); var b4 = b.GetBoardsAfterPath(p2.Start.Item1, p2.Start.Item2, p2.Actions); //await context.Response.WriteAsync(JsonConvert.SerializeObject(p)); //return; await context.Response.WriteAsync("" //+ JsonConvert.SerializeObject(p) //+ "\n\n\n" //+ JsonConvert.SerializeObject(b) //+ "\n\n\n" //+ JsonConvert.SerializeObject(b2) + b.ToString() + b2.Item1.ToString() + b2.Item2.ToString() + "\n\n" + b2.Item1.Score(BoardScorer.Options.Horus) + "\n\nSAAS optimal:" + opt.ToString() + b3.ToString() + "\n\n" + opt.Score(BoardScorer.Options.Horus) + "\n\n" + JsonConvert.SerializeObject(p2) + b4.Item1.ToString() + b4.Item2.ToString() ); } catch (Exception ex) { await context.Response.WriteAsync(ex.ToString()); } }); }
public void Dfs_Testing() { var model = new RubiksCube.Models.RubiksCubeModel(); model.Rotate90Degrees(RubiksCube.Models.LayerType.Top, RubiksCube.Models.RotationType.Clockwise); model.Rotate90Degrees(RubiksCube.Models.LayerType.Bottom, RubiksCube.Models.RotationType.Clockwise); var solver = new DfsSolver(model); var solution = solver.FindSolution(); Assert.AreEqual(2, solution.Count); }
/// <summary> /// Processes a TSP and reports errors. /// </summary> /// <param name="file">File name of TSP being processed.</param> private void ProcessTsp(string file) { System.Diagnostics.Debug.WriteLine($"Loading TSP at path {file} ...\n"); // Try convert text to TSP var success = Interface.TryTextToTsp(file, out var tsp); // If conversion was a success if (success) { // Print TSP info to debug console tsp.Print(); // Update name of problem on graph this.problemName.Text = tsp.Name; // Create solver and event handlers Solver solver = null; ProgressChangedEventHandler updateHandler = null; RunWorkerCompletedEventHandler completionHandler = null; int drawDelay = 0; // Set solvers and event handlers based on the chosen setting if (bruteForceRadioButton.IsChecked == true) { solver = new BruteForceSolver(); MessageBox.Show("Solution method not yet implemented after refactoring."); return; } else if (bfsRadioButton.IsChecked == true || dfsRadioButton.IsChecked == true) { var goal = Convert.ToInt32(searchGoal.Text); if (bfsRadioButton.IsChecked == true) { solver = new BfsSolver(); } else { solver = new DfsSolver(); } MessageBox.Show("Solution method not yet implemented after refactoring."); return; } else if (greedyRadioButton.IsChecked == true) { solver = new GreedySolver(); updateHandler = GreedyProgressChanged; completionHandler = GreedyCompletion; drawDelay = GREEDY_DRAW_DELAY; } else if (geneticRadioButton.IsChecked == true) { solver = new GeneticSolver(); updateHandler = GeneticProgressChanged; completionHandler = GreedyCompletion; drawDelay = GREEDY_DRAW_DELAY; } else { MessageBox.Show("No solution method was selected."); return; } if (progressCheckBox.IsChecked == true) { // Update continously solver.ProgressChanged += updateHandler; } else { // Update only at the end solver.RunWorkerCompleted += completionHandler; } var workerArgs = new Tuple <Tsp, int>(tsp, progressCheckBox.IsChecked == true ? drawDelay : 0); // Run solver and draw output solver.RunWorkerAsync(workerArgs); } // If conversion failed else { MessageBox.Show($"Could not convert TSP from text file: \n\n{file}"); } }