Esempio n. 1
0
 public Case(Grille grille, int x, int y, ObservableCollection <char> hypotheses)
 {
     X          = x;
     Y          = y;
     Grille     = grille;
     Hypotheses = hypotheses;
 }
Esempio n. 2
0
 public Case(Case cell, Grille grille)
 {
     X          = cell.X;
     Y          = cell.Y;
     Hypotheses = new ObservableCollection <char>(cell.Hypotheses);
     Grille     = grille;
 }
Esempio n. 3
0
 public void copy(Grille grille)
 {
     Content = grille.Content.Select((line, y) =>
                                     line.Select((value, x) =>
                                                 new Case(value, this)
                                                 ).ToArray()
                                     ).ToArray();
 }
Esempio n. 4
0
        private Grille(Grille other)
        {
            PossibleValues = other.PossibleValues;

            Content = other.Content
                      .Select((line, y) =>
                              line.Select((value, x) =>
                                          new Case(value, this)
                                          ).ToArray()
                              ).ToArray();

            Name         = other.Name;
            CreationDate = other.CreationDate;
        }
Esempio n. 5
0
        private Grille(Grille other)
        {
            PossibleValues = other.PossibleValues;

            Content = other.Content
                .Select((line, y) =>
                    line.Select((value, x) =>
                        new Case(value, this)
                    ).ToArray()
                ).ToArray();

            Name = other.Name;
            CreationDate = other.CreationDate;
        }
Esempio n. 6
0
 public void Remove(char c)
 {
     //Debug.WriteLine("({0},{1}) : ~{2}", X, Y, c);
     if (Resolved)
     {
         //Debug.WriteLine("known...");
         return;
     }
     Hypotheses.Remove(c);
     //si retirer ça nous permet de résoudre, on le dit a la grille
     if (Resolved)
     {
         //Debug.WriteLine("({0},{1}) -> {2}",X,Y,Value);
         Grille.PropagerCertitudes(Value, X, Y);
     }
 }
Esempio n. 7
0
 private static string Stringify(Grille sudoku)
 {
     return(sudoku.Name + Environment.NewLine
            + sudoku.CreationDate + Environment.NewLine
            + sudoku.PossibleValues.Aggregate("", (c, n) => c + n) + Environment.NewLine
            + sudoku.Lines
            .Select(line =>
                    line.Select(cell =>
                                cell.Resolved
                         ? cell.Value.ToString()
                         : "."
                                )
                    )
            .Aggregate("", (current, line) =>
                       current + (current == "" ? "" : Environment.NewLine)
                       + line.Aggregate((currentLine, value) =>
                                        currentLine + value
                                        )
                       ));
 }
Esempio n. 8
0
 private static string Stringify(Grille sudoku)
 {
     return sudoku.Name + Environment.NewLine
         +  sudoku.CreationDate + Environment.NewLine
         +  sudoku.PossibleValues.Aggregate("",(c,n) => c + n) + Environment.NewLine
         +  sudoku.Lines
             .Select(line =>
                 line.Select(cell =>
                     cell.Resolved
                         ? cell.Value.ToString()
                         : "."
                 )
             )
             .Aggregate("",(current, line) =>
                 current + (current == "" ? "" : Environment.NewLine)
                 +  line.Aggregate((currentLine, value) =>
                     currentLine + value
                 )
             );
 }
        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. 10
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. 12
0
 public SudokuManagerViewModel(string title)
 {
     Title          = title;
     SelectedSudoku = null;
     Sudokus        = new ObservableCollection <Grille>();
 }
Esempio n. 13
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);
         }
     }
 }
Esempio n. 14
0
 public void copy(Grille grille)
 {
     Content = grille.Content.Select((line,y) =>
         line.Select((value,x) =>
             new Case(value,this)
         ).ToArray()
     ).ToArray();
 }