コード例 #1
0
 public CalculationContext Create(CalculationContext source)
 {
     if (source == null)
     {
         throw new ArgumentNullException(nameof(source));
     }
     return(Create(source.Grid));
 }
コード例 #2
0
ファイル: Calculator.cs プロジェクト: stdstring/FunTasks
 private Boolean ProcessSquares(CalculationContext context)
 {
     foreach (GridPoint cell in Defs.Squares)
     {
         if (!Process(_cellsInfoFactory.CreateForSquare(context.Grid, cell), context))
         {
             return(false);
         }
     }
     return(true);
 }
コード例 #3
0
ファイル: Calculator.cs プロジェクト: stdstring/FunTasks
 private Boolean ProcessColumns(CalculationContext context)
 {
     foreach (Int32 column in Enumerable.Range(1, Defs.GridSide))
     {
         if (!Process(_cellsInfoFactory.CreateForColumn(context.Grid, column), context))
         {
             return(false);
         }
     }
     return(true);
 }
コード例 #4
0
ファイル: Calculator.cs プロジェクト: stdstring/FunTasks
        private Boolean Process(CellsInfo cellsInfo, CalculationContext context)
        {
            NumbersInfo numbersInfo       = _numbersInfoFactory.Create(cellsInfo);
            Tuple <GridPoint, Int32> data = ChooseCell(cellsInfo, numbersInfo);

            while (data != null)
            {
                context.Grid[data.Item1] = data.Item2;
                context.EmptyCount--;
                UseCell(cellsInfo, numbersInfo, data);
                if (!_checker.Check(cellsInfo, numbersInfo))
                {
                    return(false);
                }
                data = ChooseCell(cellsInfo, numbersInfo);
            }
            return(true);
        }
コード例 #5
0
ファイル: Calculator.cs プロジェクト: stdstring/FunTasks
        public CalculationResultData Process(CalculationContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }
            CalculationContinuation continuation;

            do
            {
                Int32 emptyCount = context.EmptyCount;
                continuation = ExecuteProcessors(context, ProcessRows, ProcessColumns, ProcessSquares);
                if (context.EmptyCount == 0)
                {
                    continuation = CalculationContinuation.Finish;
                }
                if (emptyCount == context.EmptyCount)
                {
                    continuation = CalculationContinuation.NeedPrediction;
                }
            } while (continuation == CalculationContinuation.Continue);
            return(CreateCalculationResultData(continuation, context));
        }
コード例 #6
0
ファイル: Calculator.cs プロジェクト: stdstring/FunTasks
 private CalculationContinuation ExecuteProcessors(CalculationContext context, params Func <CalculationContext, Boolean>[] processors)
 {
     return(processors.Any(processor => !processor(context)) ? CalculationContinuation.Stop : CalculationContinuation.Continue);
 }
コード例 #7
0
ファイル: Calculator.cs プロジェクト: stdstring/FunTasks
        private CalculationResultData CreateCalculationResultData(CalculationContinuation continuation, CalculationContext context)
        {
            switch (continuation)
            {
            case CalculationContinuation.Finish:
                return(new CalculationResultData(CalculationResult.Finish, context));

            case CalculationContinuation.NeedPrediction:
                return(new CalculationResultData(CalculationResult.NeedPrediction, context));

            case CalculationContinuation.Stop:
                return(new CalculationResultData(CalculationResult.Stop, null));

            default:
                throw new InvalidOperationException();
            }
        }