예제 #1
0
        /// <summary>
        /// Creates an <see cref="OrientedlLine"/> by combining two symmetrical
        /// <see cref="DirectionalLine"/> s related to the
        /// <paramref name="orientation"/>. For more information, see <see cref="DirectionalLine.FromBoard(Board, int, int, Piece, Directions, int, int)"/>.
        /// </summary>
        /// <param name="board">the <see cref="Board"/> to be used</param>
        /// <param name="x">the starting <see cref="Tile.X"/></param>
        /// <param name="y">the starting <see cref="Tile.Y"/></param>
        /// <param name="piece">
        /// the <see cref="Logic.Piece"/> that will determine <see cref="GetSameTiles()"/>
        /// </param>
        /// <param name="orientation">the <see cref="Orientations"/> to traverse</param>
        /// <param name="maxTile">the max number of <see cref="Tile"/> to traverse</param>
        /// <param name="blankTolerance">
        /// the max number of <see cref="Pieces.None"/> tiles before the traversing stops
        /// </param>
        /// <returns>a <see cref="OrientedlLine"/></returns>
        public static OrientedlLine FromBoard(
            Board board,
            int x,
            int y,
            Piece type,
            Orientations orientation,
            int maxTile,
            int blankTolerance)
        {
            if (board is null)
            {
                throw new ArgumentNullException(nameof(board));
            }

            if (x < 0 || x > board.Width)
            {
                throw new ArgumentException("Value is out of range", nameof(x));
            }

            if (y < 0 || y > board.Height)
            {
                throw new ArgumentException("Value is out of range", nameof(y));
            }

            if (maxTile < 0)
            {
                throw new ArgumentException(nameof(maxTile));
            }

            if (blankTolerance < 0)
            {
                throw new ArgumentException(nameof(blankTolerance));
            }

            return(orientation switch
            {
                Orientations.Horizontal => new OrientedlLine(
                    type,
                    orientation,
                    DirectionalLine.FromBoard(board, x, y, type, Directions.Left, maxTile, blankTolerance),
                    DirectionalLine.FromBoard(board, x, y, type, Directions.Right, maxTile, blankTolerance)),
                Orientations.Vertical => new OrientedlLine(
                    type,
                    orientation,
                    DirectionalLine.FromBoard(board, x, y, type, Directions.Up, maxTile, blankTolerance),
                    DirectionalLine.FromBoard(board, x, y, type, Directions.Down, maxTile, blankTolerance)),
                Orientations.Diagonal => new OrientedlLine(
                    type,
                    orientation,
                    DirectionalLine.FromBoard(board, x, y, type, Directions.UpLeft, maxTile, blankTolerance),
                    DirectionalLine.FromBoard(board, x, y, type, Directions.DownRight, maxTile, blankTolerance)),
                Orientations.RvDiagonal => new OrientedlLine(
                    type,
                    orientation,
                    DirectionalLine.FromBoard(board, x, y, type, Directions.UpRight, maxTile, blankTolerance),
                    DirectionalLine.FromBoard(board, x, y, type, Directions.DownLeft, maxTile, blankTolerance)),
                _ => throw new InvalidOperationException("Unexpected value"),
            });
예제 #2
0
        private OrientedlLine(
            Piece piece,
            Orientations orientation,
            DirectionalLine firstLine,
            DirectionalLine secondLine)
        {
            Piece       = piece;
            Orientation = orientation;
            FirstLine   = firstLine;
            SecondLine  = secondLine;

            Lines           = ImmutableArray.Create(firstLine, secondLine);
            BlankTilesCount = firstLine.BlankTiles.Length + secondLine.BlankTiles.Length;
            BlockTilesCount = firstLine.BlockTiles.Length + secondLine.BlockTiles.Length;
            SameTileCount   = firstLine.SameTiles.Length + secondLine.SameTiles.Length;
            TilesCount      = firstLine.Tiles.Length + secondLine.Tiles.Length;
            IsChained       = firstLine.IsChained && secondLine.IsChained;
        }