示例#1
0
        public static bool PieceValidate(int row, int col, CuttedPizza cuttedPizza)
        {
            var slice = cuttedPizza.Slices.FirstOrDefault(s =>
            {
                if (s.Coords.ColumnStart > col &&
                    s.Coords.ColumnStart > col)
                {
                    return(false);
                }
                if (s.Coords.ColumnEnd < col &&
                    s.Coords.ColumnEnd < col)
                {
                    return(false);
                }
                if (s.Coords.RowStart > row &&
                    s.Coords.RowStart > row)
                {
                    return(false);
                }
                if (s.Coords.RowEnd < row &&
                    s.Coords.RowEnd < row)
                {
                    return(false);
                }
                return(true);
            });

            if (slice != null)
            {
                return(false);
            }
            return(true);
        }
示例#2
0
 public bool Validate(Slice slice, CuttedPizza cuttedPizza)
 {
     if (!ValidateSliceRules(slice))
     {
         return(false);
     }
     if (!ValidatePizzaRules(slice, cuttedPizza))
     {
         return(false);
     }
     return(true);
 }
示例#3
0
        private static bool ValidatePizzaRules(Slice slice, CuttedPizza cuttedPizza)
        {
            var slices = cuttedPizza.Slices.Where(s =>
                                                  s.Coords.ColumnEnd >= slice.Coords.ColumnStart &&
                                                  s.Coords.RowEnd >= slice.Coords.RowStart
                                                  );

            var sliceUnvalid = slices.FirstOrDefault(s =>
            {
                if (s.Coords.ColumnStart > slice.Coords.ColumnStart &&
                    s.Coords.ColumnStart > slice.Coords.ColumnEnd)
                {
                    return(false);
                }
                if (s.Coords.ColumnEnd < slice.Coords.ColumnStart &&
                    s.Coords.ColumnEnd < slice.Coords.ColumnEnd)
                {
                    return(false);
                }
                if (s.Coords.RowStart > slice.Coords.RowStart &&
                    s.Coords.RowStart > slice.Coords.RowEnd)
                {
                    return(false);
                }
                if (s.Coords.RowEnd < slice.Coords.RowStart &&
                    s.Coords.RowEnd < slice.Coords.RowEnd)
                {
                    return(false);
                }
                return(true);
            });

            if (sliceUnvalid != null)
            {
                return(false);
            }
            return(true);
        }