public void LoadSudokuDialog(object sender, RoutedEventArgs e) { OpenFileDialog dlg = new OpenFileDialog(); //filter to only accept .txt dlg.DefaultExt = ".txt"; dlg.Filter = "Text documents (.txt)|*.txt"; Nullable <bool> result = dlg.ShowDialog(); if (result == true) { //Fails if the selected file is not a correct sudoku format try { string sudokuString = ConvertDotToZero(LoadSudoku(dlg.FileName)); //Initialize the attributes we need sudokuArray = CreateArrayFromString(sudokuString); sudo = SudokuFactory.CreateSudoku(sudokuString); //Initialize the sudoku based on the loaded sudoku InitializeSudoku(sudokuArray); } catch { MessageBox.Show("Den valgte fil kan ikke læses", "error"); } } }
public void ButtonPressed(byte input) { int row = int.Parse(selectedButton.Name[3] + ""); int column = int.Parse(selectedButton.Name[4] + ""); if (input == 0) { Stat.Text = "N***a, you cannot put 0 in a sudoku"; return; } ISudoku tmpSudo = sudo.Clone(); tmpSudo.SetNumberAt(column, row, input); if (tmpSudo.IsSolvable()) { sudokuArray[column, row] = (int)input; selectedButton.Content = input; selectedButton.IsEnabled = false; sudo.SetNumberAt(column, row, input); Stat.Text = "GJ N***A"; if (sudo.IsSolved()) { Stat.Text = "YOU DONE DID N***A, FRIED CHICKEN FOR EVERYONE!"; } return; } else { Stat.Text = "N***A YOU STUPID AS HELL"; return; } }
/// <summary> /// C'tor /// </summary> /// <param name="sudoku"></param> public MatrixSolver(ISudoku sudoku) { this.Sudoku = sudoku; matrix = new LinkedList <uint> [sudoku.Size, sudoku.Size]; ReCalculateMatrix(); }
/// <summary> /// Check if a sudoku is completed. /// This means that all it's blocks and rows/columns must be completed. /// </summary> /// <returns> True if the sudoku is completed </returns> public static bool IsCompleted(this ISudoku sudoku) { //check lines (rows and columns) for (int line = 0; line < sudoku.Size; line++) { if (!sudoku.Rows[line].IsCompleted() || !sudoku.Columns[line].IsCompleted()) { return(false); } } //check blocks for (int row = 0; row < sudoku.BlockSize; row++) { for (int column = 0; column < sudoku.BlockSize; column++) { if (!sudoku.Blocks[row, column].IsCompleted()) { return(false); } } } return(true); }
static void Main() { /* Code for console app */ Loader loader = new Loader(); ISudoku game = loader.LoadDefault(); new SudokuGameController(new ConsoleView(), game).Go(); }
public void SolveSudokuDialog(object sender, RoutedEventArgs e) { try { sudo = sudo.Solve(); string solvedString = Regex.Replace(sudo.ToString(), @"\t|\n|\r|\s", ""); InitializeSudoku(CreateArrayFromString(solvedString)); } catch { Stat.Text = "YOU NEED TO START A SUDOKU FIRST, MY N***A!"; } }
public static ISudoku[] FromArray(string[] strArr) { ISudoku[] result = new ISudoku[strArr.Length]; for (int i = 0; i < strArr.Length; i++) { result[i] = FromString(strArr[i]); } return(result); }
private void LoadSudoku(ISudoku sudokuToLoad, string name = "a Sudoku.") { sudokuGrid.Children.RemoveRange(0, sudokuGrid.Children.Count); for (int i = 0; i < 9; i++) { for (int j = 0; j < 9; j++) { int cell = sudokuToLoad[i, j]; Label cellLabel = new Label { Content = cell != 0 ? cell.ToString() : " ", HorizontalContentAlignment = HorizontalAlignment.Center, VerticalContentAlignment = VerticalAlignment.Center, FontSize = 32, MinWidth = 50, MinHeight = 50, Tag = Tuple.Create(i, j) }; // Alternate 3-cell group coloring. Console.WriteLine(cell); if (ShouldColorCellAt(i, j)) { cellLabel.Background = Brushes.LightGray; } // "Click" handler. cellLabel.MouseLeftButtonUp += OnCellLeftClick; Border cellBorder = new Border { BorderBrush = Brushes.Black, BorderThickness = new Thickness(1), Child = cellLabel }; // Add our border, containing our label (i.e. cell) sudokuGrid.Children.Add(cellBorder); } } sudoku = sudokuToLoad; solution = sudokuToLoad.Clone().Solve(); statusLeft.Content = "Loaded " + name; UpdateStatistics(); }
protected override void Arrange() { var row1 = new Row(1); _cell11 = row1.Cell(1); _cell11.RememberValueCanNotBe(Solver.CellValue.One); _cell11.RememberValueCanNotBe(Solver.CellValue.Two); _cell11.RememberValueCanNotBe(Solver.CellValue.Three); _cell11.RememberValueCanNotBe(Solver.CellValue.Four); _cell11.RememberValueCanNotBe(Solver.CellValue.Five); _cell11.RememberValueCanNotBe(Solver.CellValue.Six); _cell11.RememberValueCanNotBe(Solver.CellValue.Seven); Assert.That(_cell11.Value, Is.EqualTo(Solver.CellValue.Unknown)); _sudokuStub = MockRepository.GenerateStub <ISudoku>(); foreach (var cell in row1.Cells) { Link.A((ICellUnderConstruction)cell).To(_sudokuStub); } }
public bool IsSolved(int[,] sudokuBoard) { List <ISudoku> algorithms = new List <ISudoku>() { new BruteForce(_sudokuBlock), //additional algorithms can be submitted here. (Demonstrates the interface.) }; var startState = _sudokuState.State(sudokuBoard); //Once file is loaded generate state var finishState = _sudokuState.State(algorithms.FirstOrDefault().IsSolved(sudokuBoard)); //Next state is when the algorithm runs and the ending board is shown. //If Sudoku board is not solved the loop will keep running otherwise print out the ending State. while (!_sudokuState.SudokuSolved(sudokuBoard) && startState != finishState) { startState = finishState; for (int i = 0; i < algorithms.Count; i++) { ISudoku a = algorithms[i]; finishState = _sudokuState.State(a.IsSolved(sudokuBoard)); } } return(_sudokuState.SudokuSolved(sudokuBoard)); }
public void To(ISudoku sudoku) { _cell.Sudoku = sudoku; }
public SudokuGameController(IView theView, ISudoku theGame) { view = theView; game = theGame; }
public SudokuPresenter(IView view, ISudoku sudoku) { puzzleView = view; sudokuSolver = sudoku; Initialize(); }
internal SolveCommand(IGameContext gameContext, ISudoku sudoku) { _sudoku = sudoku; _gameContext = gameContext; }
public HomeController(ISudoku game) { this.game = game; }
internal GenerateCommand(IGameContext gameContext, ISudoku sudoku) { _sudoku = sudoku; _gameContext = gameContext; }
public HomeController(ILogger <HomeController> logger, ISudoku sudoku) { _logger = logger; _sudoku = sudoku; }
protected override void Arrange() { _sudoku = SudokuMother.Create1StarSudoku(); }
public static string ToHumanString(this ISudoku sudoku) { return(sudoku.ToString().Replace('0', '.')); // ☐ }
internal LoadFromFileCommand(IGameContext gameContext, ISudoku sudoku) { _sudoku = sudoku; _gameContext = gameContext; }
private SmartBruteForceSolver variation; //allows this public SmartBruteForceSolver(ISudoku sudoku) : base(sudoku) { }
public Sudoku(ISudoku sudokuSolver) { this._sudokuSolver = sudokuSolver; }
public SudokuSolver(ISudoku data) { sudoku = data; }