示例#1
0
        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();
        }
示例#2
0
        ///<summary>
        ///Constructor for the class.
        ///Gets sudoku board and index representing the number
        ///of row to create rcsInfo instance for.
        ///Copies the row, to local variable, integer array row.
        ///</summary>
        public rcsInfo(sudokuBoard board, int index, rcs type1)
        {
            if (type1 == rcs.arow)
            {
                for (int i = 0; i < 9; i++)
                {
                    row[i] = board.board[index - 1, i];
                }
            }
            else if (type1 == rcs.acolom)
            {
                for (int i = 0; i < 9; i++)
                {
                    row[i] = board.board[i, index - 1];
                }
            }
            else
            {
                int squareRow, squareColom;
                getSquareIndex(index, out squareRow, out squareColom);
                ///Console.WriteLine("computing row and colom index of square inside board");
                ///Console.WriteLine("from index {0}, getting row {1} and colom {2}", index, squareRow, squareColom);
                for (int i = 0; i < 9; i++)
                {
                    ///Console.WriteLine("rcsinfo loop for squares, with index {0}, i {1}", index, i);
                    ///Console.WriteLine("inserting digit in row[{0}, {1}]",squareRow, squareColom );
                    row[i] = board.board[squareRow, squareColom];
                    squareRow++;

                    ///If reached index 2, 5, 8
                    ///Corresponding to # 3, 6, 9
                    ///Go down one line, and two to the left for your next recoring
                    ///of the digit from the board
                    if ((i + 1) % 3 == 0)
                    {
                        squareRow   -= 3;
                        squareColom += 1;
                    }
                }
            }
            getListMissing();
        }
示例#3
0
        ///<summary>
        ///Return array containing all missing digits from specific row,
        ///specified by row_index.
        ///</summary>
        ///<param name="board">
        ///Contains entire board of sudoku
        ///</param>
        ///<param name="row_index">
        ///row number from board to check
        ///</param>
        public static List <int> validRow(sudokuBoard board, int row_index)
        {
            List <int> all_digits = new List <int>();

            for (int i = 0; i < 9; i++)
            {
                all_digits.Add(board.board[row_index, i]);
            }

            List <int> missing_digits = new List <int>();

            for (int i = 1; i <= 9; i++)
            {
                missing_digits.Add(i);
            }

            for (int i = 0; i < 9; i++)
            {
                missing_digits.Remove(all_digits[i]);
            }

            return(missing_digits);
        }        //End of validRow function
示例#4
0
 public static bool validColumb(sudokuBoard board, int columb_index)
 {
     return(false);
 }
示例#5
0
 public static bool validBoard(sudokuBoard board)
 {
     return(false);
 }
示例#6
0
        ///<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);
        }
示例#7
0
 public static void solveBoard(sudokuBoard b)
 {
     Console.WriteLine("hell");
 }