Пример #1
0
        private InternalRow BuildDataItem(int pieceIndex, RotatedPiece rotatedPiece, Coords coords)
        {
            var numColumns = _pieces.Length + _board.BoardSize * _board.BoardSize;
            var matrixRow  = new bool[numColumns];

            matrixRow[pieceIndex] = true;

            var w = rotatedPiece.Width;
            var h = rotatedPiece.Height;

            for (var pieceX = 0; pieceX < w; pieceX++)
            {
                for (var pieceY = 0; pieceY < h; pieceY++)
                {
                    if (rotatedPiece.SquareAt(pieceX, pieceY) == null)
                    {
                        continue;
                    }
                    var boardX = coords.X + pieceX;
                    var boardY = coords.Y + pieceY;
                    var boardLocationColumnIndex = _pieces.Length + (_board.BoardSize * boardX) + boardY;
                    matrixRow[boardLocationColumnIndex] = true;
                }
            }

            return(new InternalRow(matrixRow, new PiecePlacement(rotatedPiece, coords)));
        }
Пример #2
0
        public bool CanPlacePieceAt(RotatedPiece rotatedPiece, int x, int y)
        {
            if (x < 0 || x >= BoardSize)
            {
                throw new ArgumentOutOfRangeException("x");
            }
            if (y < 0 || y >= BoardSize)
            {
                throw new ArgumentOutOfRangeException("y");
            }

            if (x + rotatedPiece.Width > BoardSize)
            {
                return(false);
            }
            if (y + rotatedPiece.Height > BoardSize)
            {
                return(false);
            }

            // Check that each square of the piece to be placed has
            // the appropriate colour for its intended board position.
            for (var pieceX = 0; pieceX < rotatedPiece.Width; pieceX++)
            {
                for (var pieceY = 0; pieceY < rotatedPiece.Height; pieceY++)
                {
                    var square = rotatedPiece.SquareAt(pieceX, pieceY);
                    if (square != null)
                    {
                        var boardX         = x + pieceX;
                        var boardY         = y + pieceY;
                        var expectedColour = ColourOfSquareZeroZero.RelativeColour(boardX, boardY);
                        if (square.Colour != expectedColour)
                        {
                            return(false);
                        }
                    }
                }
            }

            return(true);
        }