示例#1
0
        public Sudoku(SudokuReadData readFunc, SudokuWriteData writeFunc, SolveProcessCallback procCallback)
        {
            if (readFunc == null || writeFunc == null)
            {
                throw new Exception("read function and write function should not be null!");
            }
            IntPtr readPtr = Marshal.GetFunctionPointerForDelegate(new SudokuLib.SudokuReadData((IntPtr data, int row, int col) =>
            {
                return(readFunc.Invoke(row, col));
            }));
            IntPtr writePtr = Marshal.GetFunctionPointerForDelegate(new SudokuLib.SudokuWriteData((IntPtr data, int row, int col, int value, int type) =>
            {
                writeFunc.Invoke(row, col, value, (SolveType)type);
            }));
            IntPtr solvePtr = Marshal.GetFunctionPointerForDelegate(new SudokuLib.SolveProcessCallback((IntPtr data, IntPtr proc) =>
            {
                if (procCallback == null)
                {
                    return;
                }
                SolveProcedure procedure = (SolveProcedure)Marshal.PtrToStructure(proc, typeof(SolveProcedure));
                procCallback.Invoke(procedure);
            }));

            sudo = SudokuLib.CreateSudoku(readPtr, writePtr, solvePtr, IntPtr.Zero);
        }
示例#2
0
文件: Main.cs 项目: zhyingkun/Sudoku
        static void SolveDisplay(SolveProcedure proc)
        {
            Console.Write("Improve: {0} ", Sudoku.ImproveTypeName((ImproveType)proc.type));
            switch ((ImproveType)proc.type)
            {
            case ImproveType.DoNotImprove:
                Console.WriteLine("Do Not Improve");
                break;

            case ImproveType.Row2GridWith2Posibility:
            case ImproveType.Col2GridWith2Posibility:
            case ImproveType.Block2GridWith2Posibility:
                Console.WriteLine("gridOne: {0} {1}, gridTwo: {2} {3}, value: {4} {5}",
                                  proc.gridOneX,
                                  proc.gridOneY,
                                  proc.gridTwoX,
                                  proc.gridTwoY,
                                  proc.numberOne,
                                  proc.numberTwo);
                break;

            case ImproveType.Row3GridWith3Posibility:
            case ImproveType.Col3GridWith3Posibility:
            case ImproveType.Block3GridWith3Posibility:
                Console.WriteLine("gridOne: {0} {1}, gridTwo: {2} {3}, gridThree: {4} {5}, value: {6} {7} {8}",
                                  proc.gridOneX,
                                  proc.gridOneY,
                                  proc.gridTwoX,
                                  proc.gridTwoY,
                                  proc.gridThreeX,
                                  proc.gridThreeY,
                                  proc.numberOne,
                                  proc.numberTwo,
                                  proc.numberThree);
                break;

            case ImproveType.Row2NumberIn2Grid:
            case ImproveType.Col2NumberIn2Grid:
            case ImproveType.Block2NumberIn2Grid:
                Console.WriteLine("value: {0} {1}, gridOne: {2} {3}, gridTwo: {4} {5}",
                                  proc.numberOne,
                                  proc.numberTwo,
                                  proc.gridOneX,
                                  proc.gridOneY,
                                  proc.gridTwoX,
                                  proc.gridTwoY);
                break;

            case ImproveType.Row3NumberIn3Grid:
            case ImproveType.Col3NumberIn3Grid:
            case ImproveType.Block3NumberIn3Grid:
                Console.WriteLine("value: {0} {1} {2}, gridOne: {3} {4}, gridTwo: {5} {6}, gridThree: {7} {8}",
                                  proc.numberOne,
                                  proc.numberThree,
                                  proc.numberTwo,
                                  proc.gridOneX,
                                  proc.gridOneY,
                                  proc.gridTwoX,
                                  proc.gridTwoY,
                                  proc.gridThreeX,
                                  proc.gridThreeY);
                break;

            case ImproveType.InBlockNumberInOneRow:
            case ImproveType.InBlockNumberInOneCol:
                Console.WriteLine("block: {0} {1}, value: {2}, line: {3}", proc.panelRow, proc.panelCol, proc.number, proc.line);
                break;

            case ImproveType.InRowNumberInBlock:
            case ImproveType.InColNumberInBlock:
                Console.WriteLine("line: {0}, value: {1}, block: {2} {3}", proc.line, proc.number, proc.panelRow, proc.panelCol);
                break;

            case ImproveType.TwoRowOneNumberInTwoCol:
                Console.WriteLine("row: {0} {1}, value: {2}, column: {3} {4}",
                                  proc.rowOne,
                                  proc.rowTwo,
                                  proc.number,
                                  proc.colOne,
                                  proc.colTwo);
                break;

            case ImproveType.TwoColOneNumberInTwoRow:
                Console.WriteLine("column: {0} {1}, value: {2}, row: {3} {4}",
                                  proc.colOne,
                                  proc.colTwo,
                                  proc.number,
                                  proc.rowOne,
                                  proc.rowTwo);
                break;

            case ImproveType.ThreeRowOneNumberInThreeCol:
                Console.WriteLine("row: {0} {1} {2}, value: {3}, column: {4} {5} {6}",
                                  proc.rowOne,
                                  proc.rowTwo,
                                  proc.rowThree,
                                  proc.number,
                                  proc.colOne,
                                  proc.colTwo,
                                  proc.colThree);
                break;

            case ImproveType.ThreeColOneNumberInThreeRow:
                Console.WriteLine("column: {0} {1} {2}, value: {3}, row: {4} {5} {6}",
                                  proc.colOne,
                                  proc.colTwo,
                                  proc.colThree,
                                  proc.number,
                                  proc.rowOne,
                                  proc.rowTwo,
                                  proc.rowThree);
                break;

            default:
                Console.WriteLine("Do Not To Here: Default");
                break;
            }
        }