Пример #1
0
        /// <summary>
        /// A public constructor for the maze class 
        /// </summary>
        /// <param name="matrixRows"> Number of rows in a maze matrix </param>
        /// <param name="matrixCols"> Number of columns in a maze matrix </param>
        public Maze(int matrixRows, int matrixCols)
        {
            if (matrixRows % 2 != 0 || matrixCols % 2 != 0)
                throw new ArgumentException("Public Maze constructor argument exception: Rows and columns cannot be odd numbers.");

            graphRows = matrixRows / 2;
            graphCols = matrixCols / 2;

            GridGraph graph = new GridGraph(matrixRows / 2, matrixCols / 2);
            GridGraph mazeInverted = graph.PrimsAlgorithm();
            Graph = mazeInverted.ComplementaryGraph();

            this.matrixRows = matrixRows - 1;
            this.matrixCols = matrixCols - 1;

            matrix = mazeInverted.CreateWallMatrix();
        }
Пример #2
0
        /// <summary>
        /// Makes a complementary graph 
        /// </summary>
        /// <returns> A complementary grid graph</returns>
        public GridGraph ComplementaryGraph()
        {
            GridGraph complement = new GridGraph(m, n);

            for (int i = 0; i < m; i++)
            {
                for (int j = 0; j < n; j++)
                {
                    foreach (GridNode edge in grid[i, j].Edges)
                    {
                        complement[i, j].Edges.Remove(edge);
                    }
                }
            }

            return complement;
        }