Beispiel #1
0
        private void InitiazeFieldPossibilities(IProgress <float> progress = null)
        {
            var slicePatterns = SlicePattern.GetAllPossible(this).ToArray();
            int fieldCount    = Fields.Length;
            int current       = 0;

            foreach (var field in Fields)
            {
                if (progress != null)
                {
                    current++;
                    progress.Report(current / (float)fieldCount);
                }

                foreach (var slicePattern in slicePatterns)
                {
                    var possibleSlice = new Slice(this, field, slicePattern);
                    if (possibleSlice.IsSufficient(this))
                    {
                        //field.PossibePatterns.Add(possibleSlice);
                        foreach (var affectedField in possibleSlice.AffectedFields)
                        {
                            affectedField.PossibleSlices.Add(possibleSlice);
                        }
                    }
                }
            }
        }
Beispiel #2
0
        public static List <Slice> SlicePizzaWithDifferentPatterns(Pizza pizza)
        {
            var slices   = new List <Slice>();
            var patterns = SlicePattern.GetAllPossible(pizza);

            foreach (var pattern in patterns.ToArray())
            {
                for (int row = 0; row < pizza.IngredientRows.Count; row++)
                {
                    for (int column = 0; column < pizza.Columns; column++)
                    {
                        var newSlice = new Slice(row, column, pattern);
                        if (newSlice.IsSufficient(pizza) &&
                            DoesNotOverlapWithSolution(slices, newSlice)
                            )
                        {
                            slices.Add(newSlice);
                            column += newSlice.Pattern.Right;
                        }
                    }
                }
            }

            return(slices);
        }
Beispiel #3
0
        public static IEnumerable <SlicePattern> GetAllPossible(int minCells, int maxCells)
        {
            for (int rows = 0; rows <= maxCells; rows++)
            {
                for (int columns = 0; columns <= maxCells; columns++)
                {
                    var pattern = new SlicePattern();
                    pattern.Right = columns;
                    pattern.Down  = rows;

                    var cellCount = pattern.CellCount();
                    if (minCells <= cellCount && cellCount <= maxCells)
                    {
                        yield return(pattern);
                        //if (pattern.Right != pattern.Down)
                        //{
                        //    // Create flipped pattern
                        //    var flippedPattern = new SlicePattern();
                        //    flippedPattern.Down = pattern.Right;
                        //    flippedPattern.Right = pattern.Down;
                        //    yield return flippedPattern;
                        //}
                    }
                }
            }
        }
Beispiel #4
0
 public Slice(Pizza pizza, Field field, SlicePattern pattern) :
     this(field.Row, field.Column, pattern)
 {
     Pizza = pizza;
     foreach (var field1 in GetFields())
     {
         AffectedFields.Add(field1);
     }
 }
Beispiel #5
0
 public Slice(int row1, int column1, int row2, int column2)
 {
     Row1    = row1;
     Row2    = row2;
     Column1 = column1;
     Column2 = column2;
     Pattern = new SlicePattern()
     {
         Down  = Row2 - Row1,
         Right = Column2 - Column1,
     };
 }
Beispiel #6
0
 protected bool Equals(SlicePattern other)
 {
     return(Right == other.Right && Down == other.Down);
 }
Beispiel #7
0
 public Slice(int row, int column, SlicePattern pattern) :
     this(row, column, row + pattern.Down, column + pattern.Right)
 {
 }