コード例 #1
0
        /// <summary>
        /// Builds a pattern of thin lines and broad stripes (horizontal or vertical).
        /// When the lines go in botth directions, they form a square or rectangular grid.
        /// </summary>
        /// <param name="r"></param>
        /// <param name="xSize"></param>
        /// <param name="ySize"></param>
        /// <returns></returns>
        private static OutlineShape StripesOrGrid(Random r, int xSize, int ySize)
        {
            TilesOutlineShape result = new TilesOutlineShape(xSize, ySize, 2, 2);

            int k = r.Next(1, 4);                              // 1, 2, 3

            result.SetValue(0, 0, (k != 3 || r.Next(2) == 0)); // maybe a disconnected grid
            result.SetValue(0, 1, ((k & 1) != 0));             // horizontal lines
            result.SetValue(1, 0, ((k & 2) != 0));             // vertical lines
            result.SetValue(1, 1, false);

            result.SetRepetitions(0, 1);                        // one-square pinstripes
            if (r.Next(0) == 0)
            {
                result.SetRepetitions(1, r.Next(4, 16));        // same x and y width
            }
            else
            {
                while (Math.Abs(result.xRepetitions[1] - result.yRepetitions[1]) < 5)
                {
                    result.SetXRepetitions(1, r.Next(4, 21));   // different x and y width
                    result.SetYRepetitions(1, r.Next(4, 21));
                }
            }

            if (result.tile[0, 0] == false && result.xRepetitions[1] > 7 && result.yRepetitions[1] > 7)
            {
                result.SetRepetitions(0, r.Next(1, 3));         // thin stripes: one or two squares
            }

            return(result);
        }
コード例 #2
0
        /// <summary>
        /// Builds a pattern made of pentominoes: five adjoining squares in different arrangements.
        /// </summary>
        /// <param name="r"></param>
        /// <param name="xSize"></param>
        /// <param name="ySize"></param>
        /// <returns></returns>
        private static OutlineShape Pentominoes(Random r, int xSize, int ySize)
        {
            int squareWidth = r.Next(2, 7);
            int xDim = 3 + xSize / (1 + squareWidth), yDim = 3 + xSize / (1 + squareWidth);

            TilesOutlineShape result = new TilesOutlineShape(xSize, ySize, 1 + 2 * xDim, 1 + 2 * yDim);

            PentominoPattern pentominoPattern = new PentominoPattern(r, xDim, yDim);

            #region Start with filled squares in all but the (odd,odd) positions.

            for (int x = 0; x < result.xTileSize; x++)
            {
                for (int y = 0; y < result.yTileSize; y++)
                {
                    result.SetValue(x, y, (x % 2 == 0 || y % 2 == 0));
                }
            }

            // result: a dense grid

            /*
             *   x x x x x x x x
             *   x o x o x o x o
             *   x x x x x x x x
             *   x o x o x o x o
             *   x x x x x x x x
             *   x o x o x o x o
             *   x x x x x x x x
             *   x o x o x o x o
             */

            for (int x = 1; x < xDim; x++)
            {
                result.SetXRepetitions(1 + 2 * x, squareWidth);
            }
            for (int y = 1; y < yDim; y++)
            {
                result.SetYRepetitions(1 + 2 * y, squareWidth);
            }

            #endregion

            #region Open the positions between pentomino squares of the same id.

            for (int x = 0; x < xDim; x++)
            {
                for (int y = 0; y < yDim; y++)
                {
                    if (x + 1 < xDim && pentominoPattern[x, y] == pentominoPattern[x + 1, y])
                    {
                        result.SetValue(2 + 2 * x, 1 + 2 * y, false);
                    }
                    if (y + 1 < yDim && pentominoPattern[x, y] == pentominoPattern[x, y + 1])
                    {
                        result.SetValue(1 + 2 * x, 2 + 2 * y, false);
                    }
                }
            }

            #endregion

            return(result);
        }