コード例 #1
0
 public Color GetPixel(Mazes.Point p)
 {
     try
     { return(this.mazeBmp.GetPixel(p.X, p.Y)); }
     catch
     {
         return(Color.Pink);
     }
 }
コード例 #2
0
 public bool SetPixel(Mazes.Point p, Color color)
 {
     try
     {
         this.mazeBmp.SetPixel(p.X, p.Y, color);
         return(true);
     }
     catch { return(false); }
 }
コード例 #3
0
ファイル: SolveCommand.cs プロジェクト: radishes/Mazes
        } //Execute()

        public bool PeekBlock(Mazes.Point p)
        {
            try
            {
                return(Main.tile[p.X, p.Y].active);
            }
            catch
            {
                TShock.Players[plr].SendMessage(String.Format("Solve is having a bad problem!! Server crash may be imminent!"), Color.Red);
                return(false);
            }
        }
コード例 #4
0
        public bool PeekPixel(Mazes.Point p)
        {
            Color color;

            try
            {
                color = this.mazeBmp.GetPixel(p.X, p.Y);
            }
            catch
            {
                return(false);
            }
            //bool r = (color.Name == "ff000000");
            bool r = (color.ToArgb() == wallColor.ToArgb());

            //toolbarLabel1.Text = color.ToString() + "     PeekPixel = " + r;
            return(r);
        }
コード例 #5
0
        private void buttonSolveMaze_Click(object sender, EventArgs e)
        {
            if (mazeBmp == null)
            {
                MessageBoxError("No maze to solve! Create a maze first.");
                return;
            }
            if (createInProgress)
            {
                MessageBoxError("Maze creation is currently in progress. Only completed or paused mazes may be solved.");
                return;
            }

            int sx, sy, ex, ey;

            try
            {
                sx = int.Parse(tbStartX.Text);
                sy = int.Parse(tbStartY.Text);
                ex = int.Parse(tbEndX.Text);
                ey = int.Parse(tbEndY.Text);
            }
            catch
            {
                MessageBoxError("One or more of the parameters is not a valid number. Check your parameters and try again.");
                return;
            }

            if (sx < 0 || sx > mazeBmp.Width || sy < 0 || sy > mazeBmp.Height ||
                ex < 0 || ex > mazeBmp.Width || ey < 0 || ey > mazeBmp.Height)
            {
                MessageBoxError("One or more of the parameters is outside of the maze boundaries. Check your parameters and try again.");
                return;
            }

            Mazes.Point p1 = new Mazes.Point(sx, sy);
            Mazes.Point p2 = new Mazes.Point(ex, ey);

            solver = new Solver(p1, p2, this.PeekPixel);

            solveInProgress = true;
            timer1.Start();
        }
コード例 #6
0
        private void buttonCreateMaze_Click(object sender, EventArgs e)
        {
            int wd, ht, tunnel, wall, sx, sy, algo, variant;

            try
            {
                wd      = int.Parse(tbMazeWidth.Text);
                ht      = int.Parse(tbMazeHeight.Text);
                tunnel  = int.Parse(tbTunnelWidth.Text);
                wall    = int.Parse(tbWallWidth.Text);
                sx      = int.Parse(tbStartX.Text);
                sy      = int.Parse(tbStartY.Text);
                algo    = comboAlgorithm.SelectedIndex;
                variant = comboVariant.SelectedIndex;
            }
            catch
            {
                return;
            }
            if (ht <= 0 || ht > 10000 || wd <= 0 || wd > 10000 ||
                tunnel <= 0 || tunnel > 2000 || wall <= 0 || wall > 2000 ||
                sx < 0 || sx > wd || sy < 0 || sy > ht)
            {
                return;
            }

            if (solver != null)
            {
                solver.exploredPoints.Clear();
            }
            mazeBmp = new Bitmap(wd, ht);
            mazePanel.Invalidate();
            this.prevCell = new Mazes.Point(-1, -1);
            SetRect(new Rect(0, 0, mazeBmp.Width, mazeBmp.Height), wallColor);
            this.maze = new Mazes.Maze(new Mazes.Point(0, 0), new Mazes.Point(wd, ht), new Mazes.Point(sx, sy),
                                       tunnel, wall, algo, variant, this.PeekPixel, this.SetRect);
            createInProgress = true;
            timer1.Start();
        }
コード例 #7
0
ファイル: SolveCommand.cs プロジェクト: radishes/Mazes
 public void DrawWire(Mazes.Point p)
 {
     Main.tile[p.X, p.Y].wire = true;
 }
コード例 #8
0
/////
//////////////////////////////////////////////////
/////

        private void timer1_Tick(object sender, EventArgs e)
        {
            if (createInProgress)
            {
                // update maze here
                MazeState ms = this.maze.Step();
                //toolbarLabel1.Text = ms.status.ToString() + "     " + ms.message;

                if (ms.status == 1)
                {
                    this.firstCell = maze.mazeData.tunnelling.First();
                    SetRect(new Rect(this.firstCell, maze.mazeData.tunnelWidthP()), Color.Orange);
                }

                if (ms.status >= 2 && ms.status <= 4)
                {
                    int c = maze.mazeData.tunnelling.Count();
                    if (c > 0)
                    {
                        SetRect(new Rect(maze.mazeData.lastCell, maze.mazeData.tunnelWidthP()), Color.Red);
                    }
                    if (c > 1)
                    {
                        SetRect(new Rect(this.prevCell, maze.mazeData.tunnelWidthP()), pathColor);
                        toolbarLabel1.Text = maze.mazeData.lastCell.ToString() + " / " + this.prevCell.ToString();
                    }
                    this.prevCell = maze.mazeData.lastCell;
                    mazePanel.Invalidate();
                }
                if (ms.status == 8)
                {
                    createInProgress = false;
                    timer1.Stop();
                }

                this.lastMazeState = ms;
            }


            if (solveInProgress)
            {
                int prevExp = solver.exploredPoints.Count;

                //  Stopwatch stopwatch = Stopwatch.StartNew();
                this.solver.SolveStep();
                //   stopwatch.Stop();
                //   Debug.WriteLine(stopwatch.ElapsedMilliseconds);

                // for (int i = prevExp;  i < solver.exploredPoints.Count; i++)
                foreach (ExploredPoint ep in solver.exploredPoints)
                {
                    //mazeBmp.SetPixel(solver.exploredPoints[i].p.X, solver.exploredPoints[i].p.Y, solvePathColor);
                    // bug here - exception if edge of map is reached.
                    mazeBmp.SetPixel(ep.p.X, ep.p.Y, solvePathColor);
                }

                if (solver.state == 4)
                {
                    //solver.
                }
                else if (solver.state >= 8)
                {
                    solveInProgress = false;
                    timer1.Stop();
                }
                if (solver.state >= 12)
                {
                    foreach (Mazes.Point s in solver.solution)
                    {
                        SetPixel(s, solutionColor);
                    }
                }
                this.toolbarLabel1.Text = "alivePoints.Count: " + solver.alivePoints.Count();
                mazePanel.Invalidate();
            }
        }
コード例 #9
0
ファイル: MazeCommand.cs プロジェクト: radishes/Mazes
        } //Execute()

        public bool PeekBlock(Mazes.Point p)
        {
            return(Main.tile[p.X, p.Y].active);
        }
コード例 #10
0
ファイル: MazeCommand.cs プロジェクト: radishes/Mazes
 private bool TestPointForTunnel(Mazes.Point p)
 { // check that the point is within the selected area, and is active (has a tile on it)
     Mazes.Rect r = new Mazes.Rect(x, y, x2 - (this.totalWidth * 2), y2 - (this.totalWidth * 2));
     return(r.PointInRect(p) && Main.tile[p.X, p.Y].active);
 }
コード例 #11
0
ファイル: Form1.cs プロジェクト: radishes/MazeGUI
        /////
        //////////////////////////////////////////////////
        /////
        private void timer1_Tick(object sender, EventArgs e)
        {
            if (createInProgress)
            {
                // update maze here
                MazeState ms = this.maze.Step();
                //toolbarLabel1.Text = ms.status.ToString() + "     " + ms.message;

                if (ms.status == 1)
                {
                    this.firstCell = maze.mazeData.tunnelling.First();
                    SetRect(new Rect(this.firstCell, maze.mazeData.tunnelWidthP()), Color.Orange);
                }

                if (ms.status >= 2 && ms.status <= 4)
                {
                    int c = maze.mazeData.tunnelling.Count();
                    if (c > 0)
                    {
                        SetRect(new Rect(maze.mazeData.lastCell, maze.mazeData.tunnelWidthP()), Color.Red);
                    }
                    if (c > 1)
                    {
                        SetRect(new Rect(this.prevCell, maze.mazeData.tunnelWidthP()), pathColor);
                        toolbarLabel1.Text = maze.mazeData.lastCell.ToString() + " / " + this.prevCell.ToString();
                    }
                    this.prevCell = maze.mazeData.lastCell;
                    mazePanel.Invalidate();
                }
                if (ms.status == 8)
                {
                    createInProgress = false;
                    timer1.Stop();
                }

                this.lastMazeState = ms;
            }

            if (solveInProgress)
            {
                int prevExp = solver.exploredPoints.Count;

              //  Stopwatch stopwatch = Stopwatch.StartNew();
                this.solver.SolveStep();
             //   stopwatch.Stop();
             //   Debug.WriteLine(stopwatch.ElapsedMilliseconds);

               // for (int i = prevExp;  i < solver.exploredPoints.Count; i++)
                foreach (ExploredPoint ep in solver.exploredPoints)
                {
                    //mazeBmp.SetPixel(solver.exploredPoints[i].p.X, solver.exploredPoints[i].p.Y, solvePathColor);
                    // bug here - exception if edge of map is reached.
                    mazeBmp.SetPixel(ep.p.X, ep.p.Y, solvePathColor);
                }

                if (solver.state == 4)
                {
                    //solver.
                }
                else if (solver.state >= 8)
                {
                    solveInProgress = false;
                    timer1.Stop();
                }
                if (solver.state >= 12)
                {
                    foreach (Mazes.Point s in solver.solution)
                    {
                        SetPixel(s, solutionColor);
                    }
                }
                this.toolbarLabel1.Text = "alivePoints.Count: " + solver.alivePoints.Count();
                mazePanel.Invalidate();
            }
        }
コード例 #12
0
ファイル: Form1.cs プロジェクト: radishes/MazeGUI
        private void buttonSolveMaze_Click(object sender, EventArgs e)
        {
            if (mazeBmp == null)
            {
                MessageBoxError("No maze to solve! Create a maze first.");
                return;
            }
            if (createInProgress)
            {
                MessageBoxError("Maze creation is currently in progress. Only completed or paused mazes may be solved.");
                return;
            }

            int sx, sy, ex, ey;
            try
            {
                sx = int.Parse(tbStartX.Text);
                sy = int.Parse(tbStartY.Text);
                ex = int.Parse(tbEndX.Text);
                ey = int.Parse(tbEndY.Text);
            }
            catch
            {
                MessageBoxError("One or more of the parameters is not a valid number. Check your parameters and try again.");
                return;
            }

            if (sx < 0 || sx > mazeBmp.Width || sy < 0 || sy > mazeBmp.Height
                || ex < 0 || ex > mazeBmp.Width || ey < 0 || ey > mazeBmp.Height)
            {
                MessageBoxError("One or more of the parameters is outside of the maze boundaries. Check your parameters and try again.");
                return;
            }

            Mazes.Point p1 = new Mazes.Point(sx, sy);
            Mazes.Point p2 = new Mazes.Point(ex, ey);

            solver = new Solver(p1, p2, this.PeekPixel);

            solveInProgress = true;
            timer1.Start();
        }
コード例 #13
0
ファイル: Form1.cs プロジェクト: radishes/MazeGUI
        private void buttonCreateMaze_Click(object sender, EventArgs e)
        {
            int wd, ht, tunnel, wall, sx, sy, algo, variant;
            try
            {
                wd = int.Parse(tbMazeWidth.Text);
                ht = int.Parse(tbMazeHeight.Text);
                tunnel = int.Parse(tbTunnelWidth.Text);
                wall = int.Parse(tbWallWidth.Text);
                sx = int.Parse(tbStartX.Text);
                sy = int.Parse(tbStartY.Text);
                algo = comboAlgorithm.SelectedIndex;
                variant = comboVariant.SelectedIndex;
            }
            catch
            {
                return;
            }
            if (ht <= 0 || ht > 10000 || wd <= 0 || wd > 10000
                 || tunnel <= 0 || tunnel > 2000 || wall <= 0 || wall > 2000
                 || sx < 0 || sx > wd || sy < 0 || sy > ht )
                return;

            if (solver != null)
                solver.exploredPoints.Clear();
            mazeBmp = new Bitmap(wd, ht);
            mazePanel.Invalidate();
            this.prevCell = new Mazes.Point(-1, -1);
            SetRect(new Rect(0,0, mazeBmp.Width, mazeBmp.Height), wallColor);
            this.maze = new Mazes.Maze(new Mazes.Point(0, 0), new Mazes.Point(wd, ht), new Mazes.Point(sx, sy),
                        tunnel, wall, algo, variant, this.PeekPixel, this.SetRect);
            createInProgress = true;
            timer1.Start();
        }