/// <summary>
 /// Gets generated sudoku from cache.
 /// Generates and caches if missing.
 /// </summary>
 private ISudokuGrid GetGeneratedSudoku(int seed)
 {
     if (!GeneratedSolutions.TryGetValue(seed, out ISudokuGrid grid))
     {
         GeneratedSolutions[seed] = grid = SudokuFactory.GenerateSolved(_algorithm, seed);
     }
     return(grid);
 }
        public void GenerateSolved_CheckSameSeed()
        {
            var sudoku1 = SudokuFactory.GenerateSolved(_algorithm, 0);
            var sudoku2 = SudokuFactory.GenerateSolved(_algorithm, 0);

            for (int index = 0; index < 81; index++)
            {
                int  row    = index / 9;
                int  col    = index % 9;
                byte value1 = sudoku1[row, col];
                byte value2 = sudoku2[row, col];
                Assert.AreEqual(value1, value2, "Same seed generated different sudokus.");
            }
        }
        public void GenerateSolved_CheckSpecificSeed()
        {
            var validSudoku = SudokuGenerator.Original.SudokuFactory.GenerateSolved((SudokuGenerator.Original.Data.Enum.GenerationAlgorithm)_algorithm, 0);
            var testSudoku  = SudokuFactory.GenerateSolved(_algorithm, 0);

            for (int index = 0; index < 81; index++)
            {
                int  row    = index / 9;
                int  col    = index % 9;
                byte value1 = validSudoku[row, col];
                byte value2 = testSudoku[row, col];
                Assert.AreEqual(value1, value2, "Generated sudoku doesn't match original.");
            }
        }
Esempio n. 4
0
        static void Main(string[] args)
        {
            var sudoku = SudokuFactory.GenerateSolved(0);

            Console.WriteLine(sudoku);
        }