private void Btn_Solve_Click(object sender, RoutedEventArgs e) { //generate the sudoku from the textboxes var cells = new ICell[size, size]; textBoxes.ForEach((TextBox textbox, RowColumnPointer pointer) => { cells[pointer.Row, pointer.Column] = new Cell(textbox.Text.Equals("") ? 0 : uint.Parse(textbox.Text)); }); var sudoku = new Sudoku(cells); //solves the sudoku var solver = new SmartBruteForceSolver(sudoku); solver.Solve(); //set the textboxes to the solved values textBoxes.ForEach((TextBox textbox, RowColumnPointer pointer) => { textbox.Text = solver.Sudoku.Cells[pointer.Row, pointer.Column].Value.ToString(); }); }
public void SmartBruteForceTest() { var sudoku = new Sudoku(new ICell[, ] { { new Cell(6), new Cell(4), new Cell(0), new Cell(2), new Cell(9), new Cell(8), new Cell(5), new Cell(0), new Cell(7) }, { new Cell(0), new Cell(5), new Cell(2), new Cell(1), new Cell(0), new Cell(6), new Cell(9), new Cell(8), new Cell(4) }, { new Cell(7), new Cell(9), new Cell(8), new Cell(0), new Cell(4), new Cell(5), new Cell(0), new Cell(6), new Cell(2) }, { new Cell(9), new Cell(0), new Cell(3), new Cell(6), new Cell(1), new Cell(4), new Cell(8), new Cell(7), new Cell(0) }, { new Cell(0), new Cell(8), new Cell(6), new Cell(5), new Cell(3), new Cell(0), new Cell(4), new Cell(2), new Cell(9) }, { new Cell(5), new Cell(7), new Cell(4), new Cell(0), new Cell(8), new Cell(2), new Cell(6), new Cell(0), new Cell(3) }, { new Cell(8), new Cell(3), new Cell(0), new Cell(7), new Cell(6), new Cell(9), new Cell(2), new Cell(4), new Cell(1) }, { new Cell(4), new Cell(1), new Cell(9), new Cell(8), new Cell(0), new Cell(3), new Cell(7), new Cell(5), new Cell(6) }, { new Cell(2), new Cell(0), new Cell(7), new Cell(4), new Cell(5), new Cell(1), new Cell(3), new Cell(0), new Cell(8) } }); var solver = new SmartBruteForceSolver(sudoku); solver.Solve(); //TODO: check if result is correct }