/// <summary>
        /// Update or Bind to the UI
        /// </summary>
        private void UpdateStatus()
        {
            // Clear existing report text
            richTextBoxSolverReport.Clear();

            if (controller != null && controller.Strategy != null && controller.StaticAnalysis != null)
            {
                // Draw the graphs
                PlotGraphs();

                // Show debug text
                richTextBoxSolverReport.Text = controller.DebugReport.ToString(new DebugReportFormatter());

                // Static bitmaps
                if (!bitmapViewerStatic.HasLayers)
                {
                    SokobanMap build = BuildCurrentMap(controller.Strategy.EvaluationTree.Root.Data);
                    BitmapViewer.Layer mapLayer = new BitmapViewer.Layer();
                    mapLayer.Order = 0;
                    mapLayer.Map = build;
                    mapLayer.Name = "Puzzle";
                    bitmapViewerStatic.SetLayer(mapLayer);
                    mapLayer.IsVisible = true;

                    bitmapViewerStatic.SetLayer(controller.StaticAnalysis.WallMap, new SolidBrush(Color.FromArgb(120, Color.Gray)));
                    bitmapViewerStatic.SetLayer(controller.StaticAnalysis.FloorMap, new SolidBrush(Color.FromArgb(120, Color.Green)));
                    bitmapViewerStatic.SetLayer(controller.StaticAnalysis.InitialCrateMap, new SolidBrush(Color.FromArgb(120, Color.Blue)));
                    bitmapViewerStatic.SetLayer(controller.StaticAnalysis.DeadMap, new SolidBrush(Color.FromArgb(120, Color.Brown))).IsVisible = true;
                    bitmapViewerStatic.SetLayer(controller.StaticAnalysis.BoundryMap, new SolidBrush(Color.FromArgb(120, Color.LightGray)));
                    bitmapViewerStatic.SetLayer(controller.StaticAnalysis.GoalMap, new SolidBrush(Color.FromArgb(120, Color.Yellow)));
                    bitmapViewerStatic.SetLayer(controller.StaticAnalysis.CornerMap, new SolidBrush(Color.FromArgb(120, Color.Pink)));
                    bitmapViewerStatic.SetLayer(controller.StaticAnalysis.RecessMap, new SolidBrush(Color.FromArgb(120, Color.Cyan)));

                    bitmapViewerStatic.SetLayer(controller.StaticAnalysis.RoomAnalysis.DoorBitmap, new SolidBrush(Color.FromArgb(120, Color.Khaki)));
                    foreach (Room room in controller.StaticAnalysis.RoomAnalysis.Rooms)
                    {
                        bitmapViewerStatic.SetLayer(room, new SolidBrush(Color.FromArgb(120, Color.LightCyan)));
                    }

                    BitmapViewer.Layer weightLayer = new BitmapViewer.Layer();
                    weightLayer.Order = 10;
                    weightLayer.Matrix = controller.StaticAnalysis.StaticForwardCrateWeighting;
                    weightLayer.Name = "Weightings";
                    weightLayer.Brush = new SolidBrush(Color.FromArgb(200, Color.Pink));
                    weightLayer.BrushAlt = new SolidBrush(Color.FromArgb(200, Color.Red));
                    weightLayer.Font = new Font("Arial Narrow", 7f);
                    bitmapViewerStatic.SetLayer(weightLayer);

                    bitmapViewerStatic.Render();
                }

                // Forward Tree
                if (controller.Strategy.EvaluationTree != null)
                {
                    treeViewer.Init(controller);
                    treeViewer.Controller = controller;
                    treeViewer.Render();
                }

                // Reverse Tree
                if (controller.ReverseStrategy != null && controller.ReverseStrategy.EvaluationTree != null)
                {
                    TreeVisualisation tresVisRev = new TreeVisualisation(controller.ReverseStrategy.EvaluationTree,
                                              new RectangleInt(0, 0, 1800, 1800), new SizeInt(8, 8));
                    tresVisRev.Controller = controller;
                    visualisationContainerReverseTree.Visualisation = tresVisRev;
                    visualisationContainerReverseTree.Render();
                }

                // Stats
                SolverLabelList txt = controller.Stats.GetDisplayData();
                if (txt != null)
                {
                    ReportXHTML reportCurrent = new ReportXHTML("Node Details");
                    reportCurrent.SetCSSInline(FileManager.GetContent("$html\\style.css"));
                    reportCurrent.Add(txt.ToHTML());
                    htmlViewStats.SetHTML(reportCurrent.ToString());
                }

                UpdateEvalList();
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Update or Bind to the UI
        /// </summary>
        private void UpdateStatus()
        {
            tsbStop.Enabled = SolverActive;
            tsbPause.Enabled = SolverActive;
            tsbStart.Enabled = !SolverActive;

            if (lastException != null)
            {
                webBrowserGlobalStats.DocumentText = "<code style=\"font-size: 10pt\"><pre>" +
                                                     StringHelper.Report(lastException) +
                                                     "</pre></code>";
                tslStatus.Text = lastException.Message;
                return;
            }

            tslStatus.Text = string.Format("{1} - {0}", Status, map.Puzzle.Details.Name);

            if (SolverActive || complete)
            {
                if (solver != null && solver.Strategy != null && solver.Strategy.StaticAnalysis != null)
                {
                    if (!bitmapViewerStatic.HasLayers)
                    {
                        BitmapViewer.Layer mapLayer = new BitmapViewer.Layer();
                        mapLayer.Order = 0;
                        mapLayer.IsVisible = true;
                        mapLayer.Map = solver.Map;
                        mapLayer.Name = "Puzzle";
                        bitmapViewerStatic.SetLayer(mapLayer);

                        bitmapViewerStatic.SetLayer(solver.Strategy.StaticAnalysis.WallMap,
                                                    new SolidBrush(Color.FromArgb(120, Color.Gray)));
                        bitmapViewerStatic.SetLayer(solver.Strategy.StaticAnalysis.FloorMap,
                                                    new SolidBrush(Color.FromArgb(120, Color.Green)));
                        bitmapViewerStatic.SetLayer(solver.Strategy.StaticAnalysis.InitialCrateMap,
                                                    new SolidBrush(Color.FromArgb(120, Color.Blue)));
                        bitmapViewerStatic.SetLayer(solver.Strategy.StaticAnalysis.DeadMap,
                                                    new SolidBrush(Color.FromArgb(120, Color.Brown)));
                        bitmapViewerStatic.SetLayer(solver.Strategy.StaticAnalysis.BoundryMap,
                                                    new SolidBrush(Color.FromArgb(120, Color.LightGray)));
                        bitmapViewerStatic.SetLayer(solver.Strategy.StaticAnalysis.GoalMap,
                                                    new SolidBrush(Color.FromArgb(120, Color.Yellow)));
                        bitmapViewerStatic.SetLayer(solver.Strategy.StaticAnalysis.CornerMap,
                                                    new SolidBrush(Color.FromArgb(120, Color.Pink)));
                        bitmapViewerStatic.SetLayer(solver.Strategy.StaticAnalysis.RecessMap,
                                                    new SolidBrush(Color.FromArgb(120, Color.Cyan)));
                        bitmapViewerStatic.Render();
                    }

                    if (solver.Strategy.EvaluationTree != null)
                    {
                        treeViewer.Init(solver);
                        treeViewer.Render();
                    }
                }

                // Stats
                if (solver != null && solver.Strategy != null)
                {
                    SolverLabelList txt = solver.Stats.GetDisplayData();
                    if (txt == null)
                    {
                        webBrowserGlobalStats.DocumentText = null;
                    }
                    else
                    {
                        webBrowserGlobalStats.DocumentText = txt.ToHTMLDocument();
                    }

                    UpdateEvalList();
                }
            }
        }
        /// <summary>
        /// Select a SPECIFIC node and display its details
        /// </summary>
        /// <param name="solverNode"></param>
        private void BindNode(SolverNode solverNode)
        {
            if (solverNode == null) return;

            SokobanMap build = BuildCurrentMap(solverNode);
            if (build != null)
            {
                BitmapViewer.Layer puzzleLayer = new BitmapViewer.Layer();
                puzzleLayer.Name = "Puzzle";
                puzzleLayer.Map = build;
                puzzleLayer.Order = 0;
                puzzleLayer.IsVisible = true;
                bitmapViewerNodeMaps.SetLayer(puzzleLayer).IsVisible = true;
            }

            if (solverNode.MoveMap != null)
            {
                SolverBitmap move = new SolverBitmap("MoveMap", solverNode.MoveMap);
                bitmapViewerNodeMaps.SetLayer(move, new SolidBrush(Color.FromArgb(120, Color.Green))).IsVisible = true;
            }

            if (solverNode.DeadMap != null)
            {
                bitmapViewerNodeMaps.SetLayer(solverNode.DeadMap, new SolidBrush(Color.FromArgb(120, Color.Black))).IsVisible = true;
            }

            // Build details
            SolverLabelList txt = solverNode.GetDisplayData();

            ReportXHTML reportCurrent = new ReportXHTML("Node Details");
            reportCurrent.SetCSSInline(FileManager.GetContent("$html\\style.css"));
            reportCurrent.Add(txt.ToHTML());
            if (build != null)
            {
                reportCurrent.Add(string.Format("<code><pre>{0}</pre></code>", build.ToString()));
            }
            webBrowserNodeCurrent.DocumentText = reportCurrent.ToString();

            bitmapViewerNodeMaps.Render();

            RootPathVisualisation localVis = new RootPathVisualisation(new SizeInt(16, 16), controller);
            localVis.RenderCanvas =
                new RectangleInt(0, 0, visualisationContainerLocalNodes.Width - 30,
                                 visualisationContainerLocalNodes.Height - 30);
            localVis.Init(solverNode);
            visualisationContainerLocalNodes.ClearImage();
            visualisationContainerLocalNodes.Visualisation = localVis;
            visualisationContainerLocalNodes.Render();
        }
Exemplo n.º 4
0
        /// <summary>
        /// Select a node in the tree browser
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void OnVisualisationClick_TreeViewer(object sender, VisEventArgs e)
        {
            if (e.Element == null) return;

            SolverNode solverNode = null;

            TreeVisualisationElement element = e.Element as TreeVisualisationElement;
            if (element != null) solverNode = element.Data;

            RootPathElement rele = e.Element as RootPathElement;
            if (rele != null) solverNode = rele.Node;

            if (solverNode == null) return;

            SokobanMap build = BuildCurrentMap(solverNode);
            if (build != null)
            {
                BitmapViewer.Layer puzzleLayer = new BitmapViewer.Layer();
                puzzleLayer.Name = "Puzzle";
                puzzleLayer.Map = build;
                puzzleLayer.Order = 0;
                puzzleLayer.IsVisible = true;
                bitmapViewerNodeMaps.SetLayer(puzzleLayer);
            }

            if (solverNode.MoveMap != null)
            {
                SolverBitmap move = new SolverBitmap("MoveMap", solverNode.MoveMap);
                bitmapViewerNodeMaps.SetLayer(move, new SolidBrush(Color.FromArgb(120, Color.Green)));
            }

            if (solverNode.DeadMap != null)
            {
                bitmapViewerNodeMaps.SetLayer(solverNode.DeadMap, new SolidBrush(Color.FromArgb(120, Color.Black)));
            }

            // Build details
            SolverLabelList txt = solverNode.GetDisplayData();

            webBrowserNodeCurrent.DocumentText = txt.ToHTMLDocument();

            bitmapViewerNodeMaps.Render();

            if (sender != visualisationContainerLocalNodes)
            {
                RootPathVisualisation localVis = new RootPathVisualisation(new SizeInt(10, 10), solver);
                localVis.RenderCanvas =
                    new RectangleInt(0, 0, visualisationContainerLocalNodes.Width - 30,
                                     visualisationContainerLocalNodes.Height - 30);
                localVis.Init(solverNode);
                visualisationContainerLocalNodes.ClearImage();
                visualisationContainerLocalNodes.Visualisation = localVis;
                visualisationContainerLocalNodes.Render();
            }
        }