public static void Main() { int[,] b = new int[9, 9] { { 1, 2, 3, 4, 5, 6, 7, 8, 9 }, { 1, 0, 3, 4, 5, 6, 7, 8, 9 }, { 1, 2, 3, 4, 0, 6, 0, 8, 0 }, { 1, 2, 3, 4, 0, 6, 0, 8, 0 }, { 1, 2, 3, 4, 0, 6, 0, 8, 0 }, { 1, 2, 3, 4, 0, 6, 0, 8, 0 }, { 1, 2, 3, 4, 0, 6, 0, 8, 0 }, { 1, 2, 3, 4, 0, 6, 0, 8, 0 }, { 1, 2, 3, 4, 0, 6, 0, 8, 0 }, }; int[,] c = new int[9, 9] { { 9, 2, 8, 1, 6, 7, 5, 4, 3 }, { 1, 7, 5, 4, 9, 3, 2, 8, 6 }, { 6, 4, 3, 2, 5, 8, 7, 1, 9 }, { 8, 9, 6, 3, 2, 5, 4, 7, 1 }, { 3, 1, 4, 8, 7, 9, 6, 2, 5 }, { 7, 5, 2, 6, 4, 1, 9, 3, 8 }, { 2, 3, 9, 5, 8, 4, 1, 6, 7 }, { 5, 6, 1, 7, 3, 2, 8, 9, 4 }, { 4, 8, 7, 9, 1, 6, 3, 5, 2 }, }; int[,] c1 = new int[9, 9] { { 9, 2, 8, 1, 6, 7, 5, 4, 3 }, { 1, 0, 5, 4, 9, 3, 2, 8, 6 }, { 6, 0, 3, 2, 5, 8, 7, 1, 9 }, { 8, 0, 0, 3, 2, 5, 4, 7, 1 }, { 3, 1, 4, 8, 7, 9, 6, 2, 5 }, { 7, 5, 2, 6, 4, 0, 0, 3, 8 }, { 2, 3, 9, 5, 8, 0, 0, 6, 7 }, { 5, 6, 1, 7, 3, 2, 8, 9, 4 }, { 4, 8, 7, 9, 1, 6, 3, 5, 2 }, }; sudokuBoard b1 = new sudokuBoard(c1); /// rcsInfo r1 = new rcsInfo(b1, 3, rcs.arow); ///r1.printInfo(); b1.printBoard(); sudoku.findEasyDigits(ref b1); b1.printBoard(); }
///<summary> ///Loops through all rows, colums, and squars. ///Checks for single digits that are missing and can easily fill ///</summary> public static bool findEasyDigits(ref sudokuBoard board) { rcsInfo tempRow; ///Holds info about if a change was made in the entire board ///If so, maybe another easy change can be made if we pass again on the entire board. bool changeMade = false; int i, y; ///Once working, change limit to endless, ///And add break inside loop for when no change is made. for (y = 0; y < 20; y++) { changeMade = false; ///Iterate all rows for (i = 0; i < 9; i++) { tempRow = new rcsInfo(board, i + 1, rcs.arow); ///If found one missing digit in eniter row, insert it in specific place. ///Indicated by the index of the first and only zero digit. if (tempRow.missing_digits.Length == 1) { board.board[i, tempRow.index_zeros[0]] = tempRow.missing_digits[0]; Console.WriteLine("placed easy digit in board, in row search, in index {0}", i); changeMade = true; board.printBoard(); } } ///End of row for loop ///Iterate all colom for (i = 0; i < 9; i++) { tempRow = new rcsInfo(board, i + 1, rcs.acolom); ///If found one missing digit in eniter colom, insert it in specific place. ///Indicated by the index of the first and only zero digit. if (tempRow.missing_digits.Length == 1) { board.board[tempRow.index_zeros[0], i] = tempRow.missing_digits[0]; Console.WriteLine("placed easy digit in board, in colom search, in index {0}", i); changeMade = true; board.printBoard(); } } ///End of colom for loop Console.WriteLine("got to square checking"); ///Iterate all squares for (i = 0; i < 9; i++) { tempRow = new rcsInfo(board, i + 1, rcs.asquare); Console.WriteLine("printing info about row(square)"); tempRow.printInfo(); ///If found one missing digit in eniter square, insert it in specific place. ///Indicated by the index of the first and only zero digit. if (tempRow.missing_digits.Length == 1) { board.board[i, tempRow.index_zeros[0]] = tempRow.missing_digits[0]; Console.WriteLine("placed easy digit in board, in square search, in index {0}", i); changeMade = true; board.printBoard(); } } ///End of square for loop if (!changeMade) { Console.WriteLine("no change made, breaking"); break; } } ///End of main for loop, containins row loop, colom loop, and square loop return(false); }