示例#1
0
        public void TestProperties()
        {
            // constructor
            Maze maze = new Maze (10, 13, Maze.WallInit.None);

            // size
            Assert.AreEqual (maze.Count, 13*10);

            // rows and columns
            Assert.AreEqual (13, maze.Rows);
            Assert.AreEqual (10, maze.Cols);

            // wall setting and unsetting
            Assert.IsTrue (maze.IsOpen (0, 0, Maze.Direction.N));
            maze.SetWall (0, 0, Maze.Direction.N);
            Assert.IsFalse (maze.IsOpen (0, 0, Maze.Direction.N));
            maze.UnsetWall (0, 0, Maze.Direction.N);
            Assert.IsTrue (maze.IsOpen (0, 0, Maze.Direction.N));

            // wall of contiguous cells
            Assert.IsTrue (maze.IsOpen(5,5, Maze.Direction.E));
            Assert.IsTrue (maze.IsOpen(6,5, Maze.Direction.W));
            maze.SetWall (5,5, Maze.Direction.E);
            Assert.IsFalse (maze.IsOpen(5,5, Maze.Direction.E));
            Assert.IsFalse (maze.IsOpen(6,5, Maze.Direction.W));
            maze.UnsetWall (6,5, Maze.Direction.W);
            Assert.IsTrue (maze.IsOpen(5,5, Maze.Direction.E));
            Assert.IsTrue (maze.IsOpen(6,5, Maze.Direction.W));
        }
示例#2
0
        public void TestProperties()
        {
            // constructor
            Maze maze = new Maze(10, 13, Maze.WallInit.None);

            // size
            Assert.AreEqual(maze.Count, 13 * 10);

            // rows and columns
            Assert.AreEqual(13, maze.Rows);
            Assert.AreEqual(10, maze.Cols);

            // wall setting and unsetting
            Assert.IsTrue(maze.IsOpen(0, 0, Maze.Direction.N));
            maze.SetWall(0, 0, Maze.Direction.N);
            Assert.IsFalse(maze.IsOpen(0, 0, Maze.Direction.N));
            maze.UnsetWall(0, 0, Maze.Direction.N);
            Assert.IsTrue(maze.IsOpen(0, 0, Maze.Direction.N));

            // wall of contiguous cells
            Assert.IsTrue(maze.IsOpen(5, 5, Maze.Direction.E));
            Assert.IsTrue(maze.IsOpen(6, 5, Maze.Direction.W));
            maze.SetWall(5, 5, Maze.Direction.E);
            Assert.IsFalse(maze.IsOpen(5, 5, Maze.Direction.E));
            Assert.IsFalse(maze.IsOpen(6, 5, Maze.Direction.W));
            maze.UnsetWall(6, 5, Maze.Direction.W);
            Assert.IsTrue(maze.IsOpen(5, 5, Maze.Direction.E));
            Assert.IsTrue(maze.IsOpen(6, 5, Maze.Direction.W));
        }
示例#3
0
        public void TestStringBuilder()
        {
            Maze maze;

            maze = new Maze(2, 2, Maze.WallInit.None);
            Assert.AreEqual(new string[] {
                "     ",
                "     ",
                "     ",
                "     ",
                "     ",
            }, maze.StrLines(2, 2, false));

            maze = new Maze(2, 2, Maze.WallInit.Perimeter);
            Assert.AreEqual(new string[] {
                "+--+--+",
                "|     |",
                "+     +",
                "|     |",
                "+--+--+",
            }, maze.StrLines(3, 2, false));

            maze = new Maze(3, 3, Maze.WallInit.Perimeter);
            Assert.AreEqual(new string[] {
                "+--+--+--+",
                "|        |",
                "|        |",
                "+        +",
                "|        |",
                "|        |",
                "+        +",
                "|        |",
                "|        |",
                "+--+--+--+",
            }, maze.StrLines(3, 3, false));

            maze = new Maze(4, 3, Maze.WallInit.Perimeter);
            maze.UnsetWall(0, 0, Maze.Direction.N);
            maze.UnsetWall(0, 2, Maze.Direction.W);
            maze.SetWall(0, 0, Maze.Direction.S);
            maze.SetWall(1, 0, Maze.Direction.E);
            maze.SetWall(1, 1, Maze.Direction.E);
            maze.SetWall(1, 1, Maze.Direction.W);
            maze.SetWall(0, 2, Maze.Direction.N);
            maze.SetWall(2, 2, Maze.Direction.N);
            maze.SetWall(3, 2, Maze.Direction.N);
            Assert.AreEqual(new string[] {
                "+   +---+---+---+",
                "|       |       |",
                "|       |       |",
                "+---+   +       +",
                "|   |   |       |",
                "|   |   |       |",
                "+---+   +---+---+",
                "                |",
                "                |",
                "+---+---+---+---+",
            }, maze.StrLines(4, 3, false));
        }
示例#4
0
        private Maze CreateMaze(int side)
        {
            // square and fully walled
            Maze maze = new Maze(side, side, Maze.WallInit.Full);

            // clear the walls inside 2x2 center cells
            maze.UnsetWall(7, 7, Maze.Direction.S);
            maze.UnsetWall(7, 7, Maze.Direction.E);
            maze.UnsetWall(8, 7, Maze.Direction.S);
            maze.UnsetWall(7, 8, Maze.Direction.E);

            return(maze);
        }
示例#5
0
        private void VisitRec(int col, int row)
        {
            // mark visited
            Visited [col, row] = true;

            // list of possible destinations
            List <Maze.Direction> pending = new List <Maze.Direction> (FourRoses);

            // while possible destinations
            while (pending.Count > 0)
            {
                // extract one from the list
                int            index     = RndFactory.Next() % pending.Count;
                Maze.Direction direction = pending[index];
                pending.RemoveAt(index);

                // relative to this cell
                int c = col, r = row;

                // calculate the next one
                switch (direction)
                {
                case Maze.Direction.N:
                    r--;
                    break;

                case Maze.Direction.E:
                    c++;
                    break;

                case Maze.Direction.S:
                    r++;
                    break;

                case Maze.Direction.W:
                    c--;
                    break;
                }

                // if destination is valid
                if (CellIsValid(c, r) && !Visited [c, r])
                {
                    // open the wall and explore recursively
                    Maze.UnsetWall(col, row, direction);
                    VisitRec(c, r);
                }
            }
        }
示例#6
0
        private void Run()
        {
            // create a square maze with 13 cells on every side
            Maze maze = CreateMaze(16);

            // the finish door
            maze.UnsetWall(8, 8, Maze.Direction.S);

            // prepare de generator
            MazeGenerator generator = SetupGenerator(maze);

            // generate from top-left corner
            generator.Generate(0, 0);

            // show the version
            Console.WriteLine("OSHWDEM Maze Generator v{0}.{1} R{2}", Version.Major, Version.Minor, Version.Revision);

            // output to the console
            Console.Write(maze);

            // wait for <enter>
            Console.ReadLine();
        }
示例#7
0
        private Maze CreateMaze(int side)
        {
            // square and fully walled
            Maze maze = new Maze (side, side, Maze.WallInit.Full);

            // clear the walls inside 3x3 center cells
            maze.UnsetWall (5, 5, Maze.Direction.S);
            maze.UnsetWall (5, 5, Maze.Direction.E);
            maze.UnsetWall (6, 5, Maze.Direction.S);
            maze.UnsetWall (6, 5, Maze.Direction.E);
            maze.UnsetWall (7, 5, Maze.Direction.S);
            maze.UnsetWall (5, 6, Maze.Direction.S);
            maze.UnsetWall (5, 6, Maze.Direction.E);
            maze.UnsetWall (6, 6, Maze.Direction.S);
            maze.UnsetWall (6, 6, Maze.Direction.E);
            maze.UnsetWall (7, 6, Maze.Direction.S);
            maze.UnsetWall (5, 7, Maze.Direction.E);
            maze.UnsetWall (6, 7, Maze.Direction.E);

            return maze;
        }
示例#8
0
        public void TestStringBuilder()
        {
            Maze maze;

            maze = new Maze (2, 2, Maze.WallInit.None);
            Assert.AreEqual (new string[] {
                "     ",
                "     ",
                "     ",
                "     ",
                "     ",
            }, maze.StrLines(2, 2, false));

            maze = new Maze (2, 2, Maze.WallInit.Perimeter);
            Assert.AreEqual (new string[] {
                "+--+--+",
                "|     |",
                "+     +",
                "|     |",
                "+--+--+",
            }, maze.StrLines(3, 2, false));

            maze = new Maze (3, 3, Maze.WallInit.Perimeter);
            Assert.AreEqual (new string[] {
                "+--+--+--+",
                "|        |",
                "|        |",
                "+        +",
                "|        |",
                "|        |",
                "+        +",
                "|        |",
                "|        |",
                "+--+--+--+",
            }, maze.StrLines(3, 3, false));

            maze = new Maze (4, 3, Maze.WallInit.Perimeter);
            maze.UnsetWall (0, 0, Maze.Direction.N);
            maze.UnsetWall (0, 2, Maze.Direction.W);
            maze.SetWall (0, 0, Maze.Direction.S);
            maze.SetWall (1, 0, Maze.Direction.E);
            maze.SetWall (1, 1, Maze.Direction.E);
            maze.SetWall (1, 1, Maze.Direction.W);
            maze.SetWall (0, 2, Maze.Direction.N);
            maze.SetWall (2, 2, Maze.Direction.N);
            maze.SetWall (3, 2, Maze.Direction.N);
            Assert.AreEqual (new string[] {
                "+   +---+---+---+",
                "|       |       |",
                "|       |       |",
                "+---+   +       +",
                "|   |   |       |",
                "|   |   |       |",
                "+---+   +---+---+",
                "                |",
                "                |",
                "+---+---+---+---+",
            }, maze.StrLines(4, 3, false));
        }