Exemple #1
0
        static void Main(string[] args)
        {
            var mapResultToEquation = new SortedDictionary <int, List <string> >();

            var puzzleSolver = new PuzzleSolver(new int[] { 1, 2, 3, 4 });

            puzzleSolver.CompletedValue += delegate(object?sender, CompletedValueArgs e)
            {
                if (!mapResultToEquation.ContainsKey(e.Value))
                {
                    mapResultToEquation.Add(e.Value, new List <string>()
                    {
                        e.Equation
                    });

                    if (mapResultToEquation.SolvedAllValues(puzzleSolver.StartValue, puzzleSolver.EndValue))
                    {
                        Console.WriteLine("Completed! :)");
                        puzzleSolver.Cancel();
                    }
                }
                else
                {
                    mapResultToEquation[e.Value].Add(e.Equation);
                }
            };
            puzzleSolver.Solve();

            int j = 0;

            j++;
        }
        public void CancelAnyComputations()
        {
            if (_cancelInProgress)
            {
                return;
            }

            lock ( _cancelLock )
            {
                _cancelInProgress = true;
                if (IsComputationInProgress())
                {
                    _puzzleSolver?.Cancel();
                    _computeThread?.Join();
                    _computeThread = null;
                    ComputationStatusChanged?.Invoke(this, EventArgs.Empty);
                }
                _cancelInProgress = false;
            }
        }