private void Resolve(Grille sudoku, bool thenDisplay = false)
        {
            var worker = new BackgroundWorker();

            worker.DoWork += (s, ev) =>
            {
                var watch = Stopwatch.StartNew();
                watch.Start();
                sudoku.Resolve();
                watch.Stop();
                sudoku.SolvingTime = watch.ElapsedMilliseconds;
            };
            if (thenDisplay)
            {
                worker.RunWorkerCompleted += (s, ev) =>
                {
                    updateView();
                };
            }
            worker.RunWorkerAsync();
        }
Esempio n. 2
0
        public void ForceBrute()
        {
            var cellsByHypotesisNumber = from c in Cells
                                         where !c.Resolved
                                         orderby c.Hypotheses.Count()
                                         select c;

            foreach (var cell in cellsByHypotesisNumber)
            {
                foreach (var choice in cell.Hypotheses)
                {
                    var trial   = new Grille(this);
                    var changed = trial.Cells.Single(c => c.X == cell.X && c.Y == cell.Y);
                    changed.Value = choice;
                    trial.Resolve();
                    if (trial.IsValid && trial.Resolved)
                    {
                        copy(trial);
                    }
                }
            }
        }
 private void Resolve(Grille sudoku,bool thenDisplay = false)
 {
     var worker = new BackgroundWorker();
     worker.DoWork += (s, ev) =>
     {
         var watch = Stopwatch.StartNew();
         watch.Start();
         sudoku.Resolve();
         watch.Stop();
         sudoku.SolvingTime = watch.ElapsedMilliseconds;
     };
     if (thenDisplay)
     {
         worker.RunWorkerCompleted += (s, ev) =>
         {
             updateView();
         };
     }
     worker.RunWorkerAsync();
 }
Esempio n. 4
0
 public void ForceBrute()
 {
     var cellsByHypotesisNumber = from c in Cells
                                  where !c.Resolved
                                  orderby c.Hypotheses.Count()
                                  select c;
     foreach (var cell in cellsByHypotesisNumber)
     {
         foreach (var choice in cell.Hypotheses)
         {
             var trial = new Grille(this);
             var changed = trial.Cells.Single(c => c.X == cell.X && c.Y == cell.Y);
             changed.Value = choice;
             trial.Resolve();
             if (trial.IsValid && trial.Resolved)
                 copy(trial);
         }
     }
 }