示例#1
0
        public List <(OneSidedShape, OneSidedShape)> GenerateCuts(FixedShape fixedShape)
        {
            int n      = fixedShape.Points.Length;
            var result = new List <(OneSidedShape, OneSidedShape)>();
            var matrix = new bool[n, n];

            foreach (var point in fixedShape.Points)
            {
                matrix[point.X, point.Y] = true;
            }

            for (int i = 0; i < n - 1; i++)
            {
                int gapHeight = 0;
                for (int j = 0; j < n; j++)
                {
                    if (matrix[i, j] && matrix[i + 1, j])
                    {
                        gapHeight += 1;
                        if (j == n - 1)
                        {
                            var(canCut, resultShapes) = CutShape(matrix, n, i, j - gapHeight, gapHeight);
                            if (canCut)
                            {
                                result.Add(resultShapes);
                            }
                        }
                    }
                    else
                    {
                        if (gapHeight > 0)
                        {
                            var(canCut, resultShapes) = CutShape(matrix, n, i, j - gapHeight, gapHeight);
                            if (canCut)
                            {
                                result.Add(resultShapes);
                            }
                            gapHeight = 0;
                        }
                    }
                }
            }

            return(result);
        }
示例#2
0
        protected List <Point> MatchShapeOnBoard(int[,] board, FixedShape shape, Point location)
        {
            var shapePoints    = shape.Points;
            int width          = board.GetLength(0);
            int height         = board.GetLength(1);
            var boardPositions = shapePoints.Select(p => location.Add(p)).ToList();

            var fittingPositions = new List <Point>();

            foreach (var position in boardPositions)
            {
                if (position.X < 0 || position.X >= width || position.Y < 0 || position.Y >= height)
                {
                    continue;
                }

                if (board[position.X, position.Y] == EmptyField)
                {
                    fittingPositions.Add(position);
                }
            }

            return(fittingPositions);
        }
示例#3
0
        public static List <Texel> ShapeDisplay(int index, int fieldSize, Color color, FixedShape fixedShape,
                                                List <int> shapeHeights)
        {
            int yShift = index * SplittingLineThickness + shapeHeights.Take(index).Sum() * fieldSize;

            var result = new List <Texel>();

            foreach (var point in fixedShape.Points)
            {
                for (int i = 0; i < fieldSize; i++)
                {
                    for (int j = 0; j < fieldSize; j++)
                    {
                        result.Add(new Texel(point.X * fieldSize + i, yShift + point.Y * fieldSize + j, color));
                    }
                }
            }

            return(result);
        }