Ejemplo n.º 1
0
        /// <summary>
        /// Populate PuzzleMonolithic with data from "World's hardest Sudoku" puzzle
        /// </summary>
        /// <param name="puzzle"></param>
        private void PopulateHardestValues(PuzzleMonolithic puzzle)
        {
            PuzzleMonolithic.Cell cell = null;
            byte?[,] values =
            {
                {    8, null, null, null, null, null, null, null, null },
                { null, null,    3,    6, null, null, null, null, null },
                { null,    7, null, null,    9, null,    2, null, null },

                { null,    5, null, null, null,    7, null, null, null },
                { null, null, null, null,    4,    5,    7, null, null },
                { null, null, null,    1, null, null, null,    3, null },

                { null, null,    1, null, null, null, null,    6,    8 },
                { null, null,    8,    5, null, null, null,    1, null },
                { null,    9, null, null, null, null,    4, null, null },
            };

            // Populate each cell with a value
            for (int row = 0; row < PuzzleMonolithic.PUZZLE_GRID_SIZE; row++)
            {
                for (int col = 0; col < PuzzleMonolithic.PUZZLE_GRID_SIZE; col++)
                {
                    if (values[row, col].HasValue)
                    {
                        cell          = puzzle.GetCell(row, col);
                        cell.Value    = values[row, col];
                        cell.IsLocked = true;
                    }
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Populate each cell with a value such that the puzzle is considered solved
        /// </summary>
        /// <param name="puzzle"></param>
        private void PopulateSolvedValues(PuzzleMonolithic puzzle)
        {
            byte[,] values =
            {
                { 1, 2, 3, 4, 5, 6, 7, 8, 9 },
                { 4, 5, 6, 7, 8, 9, 1, 2, 3 },
                { 7, 8, 9, 1, 2, 3, 4, 5, 6 },

                { 2, 3, 4, 5, 6, 7, 8, 9, 1 },
                { 5, 6, 7, 8, 9, 1, 2, 3, 4 },
                { 8, 9, 1, 2, 3, 4, 5, 6, 7 },

                { 3, 4, 5, 6, 7, 8, 9, 1, 2 },
                { 6, 7, 8, 9, 1, 2, 3, 4, 5 },
                { 9, 1, 2, 3, 4, 5, 6, 7, 8 },
            };

            // Populate each cell with a value
            for (int row = 0; row < PuzzleMonolithic.PUZZLE_GRID_SIZE; row++)
            {
                for (int col = 0; col < PuzzleMonolithic.PUZZLE_GRID_SIZE; col++)
                {
                    puzzle.GetCell(row, col).Value = values[row, col];
                }
            }
        }
Ejemplo n.º 3
0
 private void LockCellValues(PuzzleMonolithic puzzle)
 {
     for (int i = 0; i < PuzzleMonolithic.PUZZLE_GRID_SIZE; i++)
     {
         puzzle.GetCell(i, i).IsLocked = true;
     }
 }
Ejemplo n.º 4
0
        public void TestSolve_Locked_3()
        {
            PuzzleMonolithic puzzle = new PuzzleMonolithic();

            PopulateSolvedValues(puzzle);
            LockAllCellValues(puzzle);
            DisplayPuzzle(puzzle);

            // Unlock the last two values
            puzzle.GetCell(0, 0).IsLocked = false;
            puzzle.GetCell(0, 1).IsLocked = false;

            puzzle.Solve();
            Console.WriteLine();
            Console.WriteLine();
            DisplayPuzzle(puzzle);
            Assert.IsTrue(puzzle.IsSolved());
        }