public Case(Grille grille, int x, int y, ObservableCollection <char> hypotheses) { X = x; Y = y; Grille = grille; Hypotheses = hypotheses; }
public Case(Case cell, Grille grille) { X = cell.X; Y = cell.Y; Hypotheses = new ObservableCollection <char>(cell.Hypotheses); Grille = grille; }
public void copy(Grille grille) { Content = grille.Content.Select((line, y) => line.Select((value, x) => new Case(value, this) ).ToArray() ).ToArray(); }
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; }
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); } }
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 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(); }
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(); }
public SudokuManagerViewModel(string title) { Title = title; SelectedSudoku = null; Sudokus = new ObservableCollection <Grille>(); }
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); } } }
public void copy(Grille grille) { Content = grille.Content.Select((line,y) => line.Select((value,x) => new Case(value,this) ).ToArray() ).ToArray(); }