예제 #1
0
        public static IDominoShape[] AddRowColumn(IRowColumnAddableDeletable reference,
                                                  bool column, int position, bool southeast, int count, int color, out int[] inserted_positions)
        {
            int[][] shapes = new int[count][];
            for (int i = 0; i < count; i++)
            {
                shapes[i] = new int[reference.getLengthOfTypicalRowColumn(column)];
                for (int j = 0; j < shapes[i].Length; j++)
                {
                    shapes[i][j] = color;
                }
            }
            var pos   = reference.getPositionFromIndex(position);
            var res_y = southeast ? (pos.Y + (!column ? 1 : 0)) : pos.Y;
            var res_x = southeast ? (pos.X + (column ? 1 : 0)) : pos.X;

            if (!column && (res_y == -1 || res_y == reference.current_height + (column ? 0 : count)) ||
                column && (res_x == -1 || res_x == reference.current_width + (column ? count : 0)))
            {
                throw new InvalidOperationException("Can't insert row/column here, borders must remain borders");
            }
            return(AddRowColumn(reference, column, Enumerable.Repeat(new PositionWrapper()
            {
                X = res_x, Y = res_y, CountInsideCell = 0
            },
                                                                     count).ToArray(), shapes, out inserted_positions));
        }
예제 #2
0
        public static IDominoShape[] AddRowColumn(IRowColumnAddableDeletable reference, bool column,
                                                  PositionWrapper[] positions, int[][] shapes, out int[] inserted_positions)
        {
            int total_added = positions.Length;
            int new_width   = reference.current_width + (column ? total_added : 0);
            int new_height  = reference.current_height + (!column ? total_added : 0);

            int[] distinct = getDistinct(column, reference, positions);
            total_added = distinct.Sum();
            IDominoShape[] new_shapes        = reference.getNewShapes(new_width, new_height);
            int            typicallength     = reference.getLengthOfTypicalRowColumn(column);
            List <int>     insertedPositions = new List <int>();
            int            added_counter     = 0;

            for (int i = -1; i < distinct.Length; i++)
            {
                if (i != -1 && distinct[i] > 0)
                {
                    for (int i2 = 0; i2 < distinct[i]; i2++)
                    {
                        reference.ReinsertRowColumn(shapes[added_counter + i2], column,
                                                    i + added_counter + i2, new_shapes, new_width, new_height);
                        insertedPositions.AddRange(getAllIndicesInRowColumn(reference, i + i2 + added_counter, column, new_shapes.Length, new_width, new_height));
                    }
                    added_counter += distinct[i];
                }
                copyColors(reference, new_shapes, -1, column ? reference.current_height : reference.current_width, i, i,
                           0, added_counter, new_width, new_height, column);
            }
            reference.current_width  = new_width;
            reference.current_height = new_height;
            inserted_positions       = insertedPositions.ToArray();
            return(new_shapes);
        }
예제 #3
0
        public static int[] getAllIndicesInRowColumn(IRowColumnAddableDeletable reference, int rowColumn, bool column, int maxindex, int current_width, int current_height)
        {
            int[] result   = new int[reference.getLengthOfTypicalRowColumn(column)];
            int   position = 0;

            for (int i = -1; i <= (column ? reference.current_height : reference.current_width); i++)
            {
                var(a, b) = reference.getIndicesOfCell(column ?  i : rowColumn, column ? rowColumn : i, current_width, current_height);
                for (int j = a; j <= b; j++)
                {
                    if (j >= 0 && j < maxindex && position < result.Length)
                    {
                        result[position] = j;
                        position++;
                    }
                    else
                    {
                    }
                }
            }
            return(result);
        }