Beispiel #1
0
        public static Csp FromFile(SudokuSettings settings)
        {
            var fileAsStrings = File.ReadAllLines(Path.Combine(Environment.CurrentDirectory, "Sudoku.csv")).Skip(1)
                                .ToList();

            return(new Csp(fileAsStrings, settings));
        }
Beispiel #2
0
        private Csp(IEnumerable <string> fileAsStrings, SudokuSettings settings)
        {
            Settings = settings;
            Sudokus  = fileAsStrings.Select(boardAsString =>
            {
                var board         = new int[9, 9];
                var unparsedBoard = boardAsString.Split(";")[2];

                var counter = 0;
                for (var i = 0; i < 9; i++)
                {
                    for (var j = 0; j < 9; j++)
                    {
                        board[i, j] = (int)char.GetNumericValue(unparsedBoard[counter]);
                        if (board[i, j] == -1)
                        {
                            board[i, j] = 0;
                        }

                        counter++;
                    }
                }

                return(new Sudoku(board, ParseVariableSelection(), ParseValueSelection()));
            }).ToList();
        }
Beispiel #3
0
 public SudokuSolver(Sudoku firstSudoku, SudokuSettings settings)
 {
     Settings          = settings;
     Result            = new SudokuResult();
     FirstSudoku       = firstSudoku;
     Solutions         = new List <Sudoku>();
     Algorithm         = ParseAlgorithm();
     ValueSelection    = ParseValueSelection();
     VariableSelection = ParseVariableSelection();
 }