Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            BoolMatrixUsage();
            int argc = args.Length;

            if (argc != 0 && argc != 1)
            {
                Usage("mono for-cs.exe");
            }
            StreamReader file;

            if (argc == 1)
            {
                file = new StreamReader(args[0]);
            }
            else
            {
                file = new StreamReader(Console.OpenStandardInput());
            }
            int[] board = GetSudokuFromFile(file);
            file.Close();
            int[] board_dancing = new int[board.Length];
            board.CopyTo(board_dancing, 0);

            {
                Sudoku sudo = new Sudoku((int row, int col) =>
                {
                    int index = (row - 1) * 9 + col - 1;
                    return(board[index]);
                }, (int row, int col, int value, SolveType type) =>
                {
                    int index    = (row - 1) * 9 + col - 1;
                    board[index] = value;
                    Console.WriteLine("Solve: {0} row:{1} column:{2} value:{3}", Sudoku.SolveTypeName(type), row, col, value);
                }, SolveDisplay);
                int count = sudo.GetKnownCount();
                Console.WriteLine("Sudoku Known Count: {0}", count);
                Console.WriteLine("Calculate step by step");
                int num = sudo.CalculateSudokuAll(false, null);
                Console.WriteLine("Answer Count: {0}", num);
                DisplaySudoku(board);
                bool status = Sudoku.VerifySudokuBoard(board);
                Console.WriteLine("Verify: {0}", status ? "True" : "False");
            }
            Console.WriteLine("");
            {
                Sudoku sudo = new Sudoku((int row, int col) =>
                {
                    int index = (row - 1) * 9 + col - 1;
                    return(board_dancing[index]);
                }, (int row, int col, int value, SolveType type) =>
                {
                    int index            = (row - 1) * 9 + col - 1;
                    board_dancing[index] = value;
                }, null);
                Console.WriteLine("Calculate using dancing");
                int num = sudo.CalculateSudokuAll(true, null);
                Console.WriteLine("Answer Count: {0}", num);
                Console.WriteLine("One of it:");
                DisplaySudoku(board_dancing);
                bool status = Sudoku.VerifySudokuBoard(board_dancing);
                Console.WriteLine("Verify: {0}", status ? "True" : "False");
            }
            GC.Collect();
        }