public Optibacktracker(Grille grid) { UnsolvedGrid = grid; board = new char[UnsolvedGrid.Size, UnsolvedGrid.Size]; rowSet = new bool[UnsolvedGrid.Size,UnsolvedGrid.Size]; columnSet = new bool[UnsolvedGrid.Size,UnsolvedGrid.Size]; blockSet = new bool[UnsolvedGrid.RegionSize, UnsolvedGrid.RegionSize, UnsolvedGrid.Size]; InitArrays(); int i = 0; foreach (char symbol in UnsolvedGrid.Symbols) { eq.Add(symbol, i++); } }
public SudokuValidator(Grille grid) { var lines = new List<string>(); int count = grid.Cases.GetLength(1); for (int i = 0; i < count; i++) { string line = ""; for (int j = 0; j < count; j++) { line += grid.Cases[i, j].Value; } lines.Add(line); } _lines = lines; _characterSet = grid.Symbols; _grid = grid; }
/// <summary> /// Save a single grid into a new file /// </summary> /// <param name="grid">The grid to be saved</param> /// <param name="fileName">Exact location of the file where the grid will be saved</param> /// <returns></returns> public static bool SaveGrid(Grille grid, string fileName) { try { var stream = File.CreateText(fileName); stream.WriteLine(grid.Comment); stream.WriteLine(grid.Name); stream.WriteLine(grid.Date); stream.WriteLine(grid.Symbols); stream.WriteLine(grid); return true; } catch (IOException) { return false; } }
/// <summary> /// Create grids objects from a file, init them and check if they are valid /// </summary> /// <param name="filename">The exact location of the file containing the grids</param> /// <returns>The list of parsed grids</returns> public static List<Grille> ParseGridsFromFile(string filename) { List<Grille> grids = new List<Grille>(); var file = new StreamReader(filename); string line; while ((line = file.ReadLine()) != null) { var grid = new Grille(line, file.ReadLine(), file.ReadLine(), file.ReadLine().ToCharArray()); string[] tempLines = new string[grid.Symbols.Length]; for (int j = 0; j < grid.Symbols.Length; j++) { tempLines[j] = file.ReadLine(); } var validator = new SudokuValidator(grid.Symbols, tempLines, ref grid); validator.ExecuteTests(); grids.Add(grid); } return grids; }
public SudokuValidator(IEnumerable<char> characterSet, IEnumerable<string> lines, ref Grille grid) { _characterSet = characterSet; _lines = lines; _grid = grid; }