Exemple #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));
        }
Exemple #2
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));
        }
Exemple #3
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;
        }
Exemple #4
0
        private MazeGenerator SetupGenerator(Maze maze)
        {
            // pretty algorithm to generate mazes
            DepthFirst generator = new DepthFirst (maze);

            // dont enter into the 3x3 center
            generator.SetVisited (5, 5, true);
            generator.SetVisited (6, 5, true);
            generator.SetVisited (7, 5, true);
            generator.SetVisited (5, 6, true);
            generator.SetVisited (6, 6, true);
            generator.SetVisited (7, 6, true);
            generator.SetVisited (5, 7, true);
            generator.SetVisited (6, 7, true);
            generator.SetVisited (7, 7, true);

            return generator;
        }
Exemple #5
0
        public void TestWalls()
        {
            Maze maze;

            maze = new Maze (2, 2, Maze.WallInit.None);
            for (int c = 0; c < maze.Count; c++) {
                Assert.AreEqual (maze[c], Maze.Cell_0);
            }

            maze = new Maze (3, 3, Maze.WallInit.Perimeter);
            byte[] expected = new byte[] {
                Maze.Cell_NW, Maze.Cell_N, Maze.Cell_NE,
                Maze.Cell_W, Maze.Cell_0, Maze.Cell_E,
                Maze.Cell_SW, Maze.Cell_S, Maze.Cell_ES,
            };
            for (int c = 0; c < maze.Count; c++) {
                Assert.AreEqual (expected [c], maze [c]);
            }
        }