Exemplo n.º 1
0
 /// <summary>
 /// Apply the border of the given shape (where neighboring entries have opposite values) to the maze.
 /// The corresponding walls are switched from WS_MAYBE to WS_OUTLINE.
 /// </summary>
 private void FixOutline(OutlineShape.InsideShapeDelegate shapeTest, WallState wallState)
 {
     for (int x = 0; x < xSize; x++)
     {
         for (int y1 = 0, y2 = 1; y2 < ySize; y1++, y2++)
         {
             bool b1 = shapeTest(x, y1), b2 = shapeTest(x, y2);
             bool bothReserved = (this[x, y1].isReserved && this[x, y2].isReserved);
             if (b1 != b2 && !bothReserved && this[x, y1][WallPosition.WP_S] == WallState.WS_MAYBE)
             {
                 this[x, y1][WallPosition.WP_S] = wallState;
                 this[x, y2][WallPosition.WP_N] = wallState;
             }
         }
     }
     for (int y = 0; y < ySize; y++)
     {
         for (int x1 = 0, x2 = 1; x2 < xSize; x1++, x2++)
         {
             bool b1 = shapeTest(x1, y), b2 = shapeTest(x2, y);
             bool bothReserved = (this[x1, y].isReserved && this[x2, y].isReserved);
             if (b1 != b2 && !bothReserved && this[x1, y][WallPosition.WP_E] == WallState.WS_MAYBE)
             {
                 this[x1, y][WallPosition.WP_E] = wallState;
                 this[x2, y][WallPosition.WP_W] = wallState;
             }
         }
     }
 }
Exemplo n.º 2
0
        /// <summary>
        /// Put closed walls around the reserved areas.
        /// </summary>
        private void CloseWallsAroundReservedAreas()
        {
            // We need a test that regards the reserved squares as the "inside" of a shape.
            OutlineShape.InsideShapeDelegate test = delegate(int x, int y) { return(this.squares[x, y].isReserved); };

            this.FixOutline(test, WallState.WS_CLOSED);
        }
Exemplo n.º 3
0
        private void FixOutline(OutlineShape shape)
        {
            // We need a test for the "inside" of an OutlineShape.
            OutlineShape.InsideShapeDelegate test = delegate(int x, int y) { return(shape[x, y]); };

            FixOutline(test, WallState.WS_OUTLINE);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Creates the embedded mazes, as defined in embeddedMazeShapes.
        /// </summary>
        /// Note: The algorithm must provide that all mazes (main and embedded) are totally connected.
        private void FixEmbeddedMazes()
        {
            for (int i = 0; i < embeddedMazeShapes.Count; i++)
            {
                int embeddedMazeId = this.MazeId + 1 + i;

                if (embeddedMazeId > MazeSquare.MaxMazeId)
                {
                    break;
                }

                // We need a test that regards the reserved squares and current embedded mazes as the "inside" of a shape.
                OutlineShape.InsideShapeDelegate regularTest = delegate(int x, int y)
                {
                    return(this.squares[x, y].MazeId != MazeSquare.PrimaryMazeId);
                };

                // This test ensures that the border of the main maze must also not be covered.
                OutlineShape.InsideShapeDelegate conservativeTest = delegate(int x, int y)
                {
                    if (x - 2 < 0 || x + 2 >= this.XSize || y - 2 < 0 || y + 2 >= this.YSize)
                    {
                        return(true);
                    }
                    return(this.squares[x, y].MazeId != MazeSquare.PrimaryMazeId);
                };

                OutlineShape originalShape  = embeddedMazeShapes[i];
                OutlineShape connectedShape = originalShape.ConnectedSubset(conservativeTest).Closure(regularTest);

                // Discard the shape if the connected subset is too small.
                if (connectedShape.Area >= 0.3 * originalShape.Area)
                {
                    EmbeddedMaze embeddedMaze = new EmbeddedMaze(this, embeddedMazeId, connectedShape);
                    this.embeddedMazes.Add(embeddedMaze);
                }

                if (RegisteredOptions.GetBoolSetting(RegisteredOptions.OPT_OUTLINE_SHAPES))
                {
                    // The disconnected and enclosed parts of the original shape are handled as a regular outline shape.
                    FixOutline(originalShape);
                }
            }
        }