Ejemplo n.º 1
0
        private void RepopulateAnswers()
        {
            _answers = new List <Answer>(GetEnd() - GetStart());
            for (int i = _start; i <= _end; i++)
            {
                _answers.Add(new Answer(i));
            }

            AnswerItemsChanged?.Invoke(this, EventArgs.Empty);

            NumberEquationComputed?.Invoke(this, 0);
        }
Ejemplo n.º 2
0
        private void ComputeNumbers()
        {
            _puzzleSolver = new PuzzleSolver(GetDigits())
            {
                StartValue = GetStart(),
                EndValue   = GetEnd()
            };
            _puzzleSolver.CompletedValue += delegate(object?sender, CompletedValueArgs e)
            {
                var answer = _answers.FirstOrDefault(an => an.Number == e.Value);
                if (answer is null)
                {
                    return;
                }

                InvokeOnMainThread(() => answer.AddEquation(e.Equation));
            };
            _puzzleSolver.FinishedComputing += delegate(object?sender, EventArgs e)
            {
                CancelAnyComputations();
            };
            _puzzleSolver.EquationsComputed += delegate(object?sender, int equationsComputed)
            {
                InvokeOnMainThread(() => NumberEquationComputed?.Invoke(this, equationsComputed));
            };
            _puzzleSolver.CurrentPass += delegate(object?sender, int pass)
            {
                InvokeOnMainThread(() => PassChanged?.Invoke(this, pass));
            };
            _puzzleSolver.CurrentGroupCombination += delegate(object?sender, List <string> currentGroupCombination)
            {
                InvokeOnMainThread(() => CurrentGroupingEquations?.Invoke(this, currentGroupCombination));
            };

            _puzzleSolver.Solve();
        }