Example #1
0
 /// <summary>
 /// Overloaded Helper.
 /// </summary>
 /// <param name="Bitmap"></param>
 /// <param name="BrushColor"></param>
 public Layer SetLayer(SolverBitmap Bitmap, Brush BrushColor)
 {
     Layer tmp = new Layer();
     tmp.Order = layers.Count;
     tmp.IsVisible = false;
     if (Bitmap != null)
     {
         tmp.Name = Bitmap.Name;
         tmp.Bitmap = Bitmap;
     }
     else
     {
         tmp.Name = "None";
     }
     tmp.Brush = BrushColor;
     return SetLayer(tmp);
 }
        /// <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();
        }
        /// <summary>
        /// Set the simple maps, walls, etc
        /// </summary>
        private void SetSimpleMaps()
        {
            // Wall Map
            Bitmap twall = controller.Map.ToBitmap(CellStates.Wall);
            twall = twall.BitwiseOR(controller.Map.ToBitmap(CellStates.Void));
            wallMap = new SolverBitmap("Wall Map", twall);

            // Floor Map
            floorMap = new SolverBitmap("Floor Map", MapAnalysis.GenerateFloorMap(controller.Map));

            // Goal Map
            Bitmap tgoal = controller.Map.ToBitmap(CellStates.FloorGoal);
            tgoal = tgoal.BitwiseOR(controller.Map.ToBitmap(CellStates.FloorGoalCrate));
            tgoal = tgoal.BitwiseOR(controller.Map.ToBitmap(CellStates.FloorGoalPlayer));
            goalMap = new SolverBitmap("Goal Map", tgoal);

            // Crate Map
            Bitmap tcrate = controller.Map.ToBitmap(CellStates.FloorCrate);
            tcrate = tcrate.BitwiseOR(controller.Map.ToBitmap(CellStates.FloorGoalCrate));
            initialCrateMap = new SolverBitmap("Initial Crate Map", tcrate);
        }
 /// <summary>
 /// Build the 'DeadMap' for all positions on which a crate will make the puzzle unsolvable
 /// </summary>
 private void BuildDeadMap()
 {
     DeadMapAnalysis anal = new DeadMapAnalysis();
     DeadMapState deadMapResult = anal.BuildDeadMap(null, goalMap, wallMap, controller.Strategy);
     deadMap = deadMapResult;
     cornerMap = deadMapResult.CornerMap;
     recessMap = deadMapResult.RecessMap;
 }
        /// <summary>
        /// Build a map of all unreachable positions (void + wall, etc)
        /// </summary>
        private void BuildBoundryMap()
        {
            Bitmap boundry = controller.Map.ToBitmap(CellStates.Wall);
            boundry = boundry.BitwiseOR(controller.Map.ToBitmap(CellStates.Void));

            // TODO: Convert all external floor, goal, etc to void or wall
            boundryMap = new SolverBitmap("Boundry", boundry);
        }
        /// <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();
            }
        }
Example #7
0
 public SolverBitmap(SolverBitmap copy)
     : this(copy.name, new Bitmap(copy))
 {
 }