Esempio n. 1
0
 public CubePiece?GetCubePiece(CubeCoordinates coordinate) => _state[coordinate.X, coordinate.Y, coordinate.Z];
Esempio n. 2
0
        /// <summary>
        /// Adds a piece to the cube if it is not being added already.
        /// <summary>
        /// <remarks>
        /// The piece is added in certain orientation. The orientation of the piece talse is defined by orientation parameters.
        /// </remarks>
        public CubeBuilder AddPiece(
            CubeCoordinates coordinate,
            Piece piece,
            Orientation tale1Orientation = Orientation.RedOrange,
            Orientation tale2Orientation = Orientation.YellowWhite,
            Orientation tale3Orientation = Orientation.None)
        {
            if (coordinate.HasOneOuterTale || piece.HasOneOuterTale)
            {
                throw new ArgumentException(
                          "The provided coordinate or piece is not valid place for putting in the cube! " +
                          "It represents a central coordinate! The central coordinates are preset by the builder!");
            }

            if (tale1Orientation == Orientation.None)
            {
                throw new ArgumentException(
                          $"The provided tale 1 orientations is not valid for putting {nameof(Piece)}!",
                          nameof(tale1Orientation));
            }

            var pieceAlreadyInTheCube = _state.AsEnumerable().Any(x => x.Piece.Equals(piece));

            if (pieceAlreadyInTheCube)
            {
                throw new ArgumentException("This piece is in the cube already!", nameof(piece));
            }

            if (piece.HasTwoOuterTales && !coordinate.HasTwoOuterTales)
            {
                throw new ArgumentException(
                          $"The provided coordinate is not valid place for putting {nameof(Piece)}!",
                          nameof(coordinate));
            }

            if (piece.HasThreeOuterTales && !coordinate.HasThreeOuterTales)
            {
                throw new ArgumentException(
                          $"The provided coordinate is not valid place for putting {nameof(Piece)}!",
                          nameof(coordinate));
            }

            // validate
            if (tale2Orientation == Orientation.None || tale1Orientation == tale2Orientation)
            {
                throw new ArgumentException(
                          $"The provided {nameof(tale2Orientation)} is not valid for putting {nameof(Piece)}!",
                          nameof(tale2Orientation));
            }

            if (piece.HasThreeOuterTales)
            {
                if (tale3Orientation == Orientation.None || tale2Orientation == tale3Orientation || tale1Orientation == tale3Orientation)
                {
                    throw new ArgumentException(
                              $"The provided {nameof(tale3Orientation)} is not valid place for putting {nameof(Piece)}!",
                              nameof(tale3Orientation));
                }
            }

            _state[coordinate.X, coordinate.Y, coordinate.Z] =
                new CubePiece(piece, tale1Orientation, tale2Orientation, tale3Orientation);

            return(this);
        }
Esempio n. 3
0
 public Piece?GetPiece(CubeCoordinates coordinate) => _state[coordinate.X, coordinate.Y, coordinate.Z]?.Piece;