public void SolvePuzzle() { var board = BoardFactory.CreateRedDonkeyPuzzle(); var someSuperIntelligentPerson = new SomeSuperIntelligentPerson(); var solution = someSuperIntelligentPerson.SolvePuzzle(board); var solutionViewer = new SolutionViewer(); solutionViewer.ShowSolution(board, solution); }
private void SolutionViewerSetUpBestSolution(bool wrapper = false) { TreeNodeCollection nodes = SolutionViewer.Nodes; String str = solutio_str + " " + pm.BestSolutionIndex; int i; Font font = new Font(SolutionViewer.Font, FontStyle.Bold); //aggiungo anche la sol del wrapper se esite... if (pm is PMed3) { if (pm.WrapperSolutionClusters != null) { TreeNode node = new TreeNode("Solution Wrapper"); if (wrapper) { node.NodeFont = font; } for (i = 0; i < pm.p; i++) { node.Nodes.Add(cluster_str + " " + i.ToString()); } SolutionViewer.Nodes.Insert(0, node); } } if (!wrapper) { for (i = 0; i < nodes.Count; i++) { if (nodes[i].Text == str) { break; } } if (i < nodes.Count) //if (nodes.Length == 1) { //Font font = new Font(nodes[i].NodeFont.FontFamily, nodes[i].NodeFont.Size, FontStyle.Bold); nodes[i].NodeFont = font; nodes[i].Text = str; } else { MessageBox.Show("Error in SolutionViewerSetUpBestSolution()", "c'è più di un nodo!!"); } } SolutionViewer.Refresh(); }
static void Main() { var puzzle = BoardFactory.CreateRedDonkeyPuzzle(); //8s and 114 moves //var puzzle = BoardFactory.CreateSimpleTrafficJamPuzzle(); //?s and 82 moves //var puzzle = BoardFactory.CreateCenturyBoard(); // 14s 131moves //var puzzle = BoardFactory.CreateSuperCenturyBoard(); //12s 179moves Console.BackgroundColor = ConsoleColor.Black; Console.Clear(); Console.WriteLine(DateTimeOffset.UtcNow); var someSuperIntelligentPerson = new SomeSuperIntelligentPerson(); var solution = someSuperIntelligentPerson.SolvePuzzle(puzzle); var solutionViewer = new SolutionViewer(); solutionViewer.ShowSolution(puzzle, solution); }
public void Initialize(ScreenManager screenManager) { this.screenManager = screenManager; this.GraphicsDevice = screenManager.GraphicsDevice; _content = new ContentManager(screenManager.ServiceProvider, Constants.CONTENT_DIRECTORY); Color[] repColors = new Color[6]; for (int i = 0; i < repColors.Length; i++) { repColors[i] = Settings.Instance.RubiksCube.GetVisualColor(i); } rubiksSolver = new RubiksBeginnerSolver(); try { solutionMoves = rubiksSolver.Solve(cube, repColors).Split(); solutionMoves = ConvertAndShortenSolution(solutionMoves); } catch (RubiksCubeUnsolvableException) { Console.WriteLine("Unsolvable"); } viewer = new SolutionViewer(solutionMoves, _content); control = new SolutionControl(_content); control.OnPlay += new EventHandler((s, e) => { if (moveIdx >= solutionMoves.Length) { control.Play = false; } }); control.OnForward += new EventHandler((s, e) => { if (moveIdx <= solutionMoves.Length) { viewer.Increment(); if (moveIdx < solutionMoves.Length) { cube.ResetMove(); CubeRotate(0); cube.Update(); moveIdx++; } control.Play = false; } }); control.OnBackward += new EventHandler((s, e) => { if (moveIdx > 0) { viewer.Decrement(); moveIdx--; cube.ResetMove(); CubeRotateBackward(0); cube.Update(); control.Play = false; } }); control.OnFastBackward += new EventHandler((s, e) => { if (moveIdx > 0) { int times = moveIdx > 4 ? 5 : moveIdx; Console.WriteLine(times); cube.ResetMove(); for (int i = 0; i < times; i++) { viewer.Decrement(); moveIdx--; CubeRotateBackward(0); cube.Update(); } control.Play = false; } }); control.OnFastForward += new EventHandler((s, e) => { if (moveIdx <= solutionMoves.Length) { int times = (solutionMoves.Length - moveIdx) > 4 ? 5 : solutionMoves.Length - moveIdx; Console.WriteLine(times); cube.ResetMove(); for (int i = 0; i < times; i++) { viewer.Increment(); if (moveIdx < solutionMoves.Length) { CubeRotate(0); cube.Update(); moveIdx++; } } control.Play = false; } }); }
private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e) { backgroundWorkerParameter param = e.Argument as backgroundWorkerParameter; if (pm is PMed3) { if (!pm.ComputeSolutions(param.Parallel, param.Clusters)) { MessageBox.Show("An Error as occured, check Console Text Box for info.\r\n Maybe out of memory exception.", "PMedLib.dll error"); //MessageBox.Show("It's Better Close program and restart it!!!", "Warning !!!", MessageBoxButtons.OK, MessageBoxIcon.Stop); } // else //tutto ok... // { // } } else { pm.ComputeSolutions(param.Parallel, param.Clusters); } //metto qui l'aggiornamenti della form e vari... ConsoleAppendText("\r\nFinished Computing Solutions..."); ConsoleAppendText(String.Format("\r\n--- Best Solution is {0} = {1}", pm.BestSolutionIndex, pm.Solutions[pm.BestSolutionIndex])); if (pm.WrapperSolution > 0) { ConsoleAppendText(String.Format("\r\n--- Wrapper Solution is = {0}", pm.WrapperSolution)); } pm.ShowElapsedTime(); ConsoleAppendText(String.Format("\r\nPopulating solution viewer...")); Stopwatch solw = new Stopwatch(); solw.Start(); //aggiorno la lista delle soluzioni alla fine... così da rendere l'algortimo più efficente... try { for (uint i = 0; i < pm.Nsolution; i++) { if (SolutionViewer.InvokeRequired) { SolutionViewer.Invoke(UpdateSolutionVieverCallBack, i); } else { UpdateSolutionViever(i); } } } catch (Exception ex) { MessageBox.Show(ex.Message, "PMedian Project - Solution Viewer"); //cancello la lista altrimenti può crashare tutto!!! //e metto solo il meglio trovato... if (SolutionViewer.InvokeRequired) { SolutionViewer.Invoke(SolutionViewerClearCallBack); SolutionViewer.Invoke(UpdateSolutionVieverCallBack, pm.BestSolutionIndex); } else { SolutionViewer.Nodes.Clear(); UpdateSolutionViever(pm.BestSolutionIndex); } } solw.Stop(); ConsoleAppendText(String.Format("\r\nTime Elapsed Pouplation Solution Viewer {0}", solw.Elapsed)); }