Exemplo n.º 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)));
        }
Exemplo n.º 2
0
        private void AddDataItemsForPieceWithSpecificOrientation(int pieceIndex, Piece piece, Orientation orientation)
        {
            var rotatedPiece = new RotatedPiece(piece, orientation);

            for (var x = 0; x < _board.BoardSize; x++)
            {
                for (var y = 0; y < _board.BoardSize; y++)
                {
                    if (!_board.CanPlacePieceAt(rotatedPiece, x, y))
                    {
                        continue;
                    }
                    var dataItem = BuildDataItem(pieceIndex, rotatedPiece, new Coords(x, y));
                    _data.Add(dataItem);
                }
            }
        }
Exemplo n.º 3
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);
        }