Ejemplo n.º 1
0
 public RestoreManager()
 {
     ObjectsForBackup  = new List <string>();
     LastPoint         = null;
     StoringAlgorithm  = new SeparateStoringAlgorithm();
     CleaningAlgorithm = null;
 }
Ejemplo n.º 2
0
 public RobotCleaner(int x, int y, FacingTo faceTo, int battery, IMap map, IReturnAlgorithm returnAlgorithm, Dictionary <FacingTo, IMovingStrategy> movingStrategies, ICleaningAlgorithm cleaningAlgorithm)
 {
     X                 = x;
     Y                 = y;
     FaceTo            = faceTo;
     Battery           = battery;
     Map               = map;
     ReturnAlgorithm   = returnAlgorithm;
     CleaningAlgorithm = cleaningAlgorithm;
     _movingStrategies = movingStrategies;
 }
        public RestorePoint Clean(RestorePoint lastPoint, out bool areMorePointsLeft)
        {
            ICleaningAlgorithm selectedAlgorithm = null;
            long numberOfLeftPoints = 0;
            var  isNumberSet        = false;

            foreach (var algorithm in Algorithms)
            {
                if (MinimumFlag)
                {
                    // minimum
                    if (algorithm.CountLeftPoints(lastPoint) < numberOfLeftPoints || !isNumberSet)
                    {
                        isNumberSet        = true;
                        numberOfLeftPoints = algorithm.CountLeftPoints(lastPoint);
                        selectedAlgorithm  = algorithm;
                    }
                }
                else
                {
                    // maximum
                    if (algorithm.CountLeftPoints(lastPoint) > numberOfLeftPoints || !isNumberSet)
                    {
                        isNumberSet        = true;
                        numberOfLeftPoints = algorithm.CountLeftPoints(lastPoint);
                        selectedAlgorithm  = algorithm;
                    }
                }
            }

            if (selectedAlgorithm == null)
            {
                throw new NullReferenceException("Nothing selected for cleaning algorithm");
            }

            return(selectedAlgorithm.Clean(lastPoint, out areMorePointsLeft));
        }