Esempio n. 1
0
        public IBuilder <GameLevel> Generate()
        {
            InitializeStrategies();

            do
            {
                Reset();

                foreach (IGeneratorStrategy strategy in _strategies)
                {
                    Type requiredType = strategy.RequiredStrategy();

                    if (requiredType != null)
                    {
                        IGeneratorStrategy required = GetNextCompletedStrategyOfType(requiredType);
                        strategy.SetRequiredStrategy(required);
                    }
                    strategy.RunStrategy(_map);
                }
            } while (!IsMapValid());

            foreach (IGeneratorStrategy strategy in _postValidStrategies)
            {
                Type requiredType = strategy.RequiredStrategy();
                if (requiredType != null)
                {
                    IGeneratorStrategy required = GetNextCompletedStrategyOfType(requiredType);
                    strategy.SetRequiredStrategy(required);
                }
                strategy.RunStrategy(_map);
            }

            return(this);
        }
        public SumMemoTable Generate(Int64 maxDigits, Int64 digitRange)
        {
            var maxLinearSum = maxDigits * digitRange;
            var maxSquareSum = maxDigits * digitRange * digitRange;

            var sumMemoTable = new SumMemoTable(maxDigits, digitRange);

            _strategy = new OneDigitGeneratorStrategy(sumMemoTable);
            _strategy.Run();

            for (var i = 1; i < maxDigits; i++)
            {
                for (var j = 0; j <= digitRange; j++)
                {
                    if (j == 0)
                    {
                        _strategy = new FirstDigitZeroGeneratorStrategy(sumMemoTable, i);
                    }
                    else
                    {
                        _strategy = new FirstDigitNonZeroGeneratorStrategy(sumMemoTable, i, j);
                    }

                    _strategy.Run();
                }
            }

            return sumMemoTable;
        }
Esempio n. 3
0
 public ILevelConfigurator UseStrategy(IGeneratorStrategy strategy)
 {
     _parameters.Strategy = strategy;
     return(this);
 }
Esempio n. 4
0
 public void SetRequiredStrategy(IGeneratorStrategy strategy)
 {
     _requiresStrategy = strategy;
 }
Esempio n. 5
0
 public void AddPostValidStrategy(IGeneratorStrategy strategy)
 {
     _postValidStrategies.Add(strategy);
 }
Esempio n. 6
0
 public void AddGeneratorStrategy(IGeneratorStrategy strategy)
 {
     _strategies.Add(strategy);
 }
 public void UseStrategy(IGeneratorStrategy <TDatabase> strategy)
 {
     _strategy = strategy;
 }