コード例 #1
0
 public static void SaveToFile(string FileName, SudokuGrid Grid)
 {
     byte[] Array = Grid.LinearArr;
     DataContractJsonSerializer Serializer = new DataContractJsonSerializer(typeof(byte[]));
     FileStream fs = new FileStream(FileName, FileMode.OpenOrCreate);
     Serializer.WriteObject(fs, Array);
     fs.Close();
 }
コード例 #2
0
 public static void LoadFromFile(string FileName, SudokuGrid Grid)
 {
     DataContractJsonSerializer Serializer = new DataContractJsonSerializer(typeof(byte[]));
     FileStream fs = new FileStream(FileName, FileMode.Open);
     byte[] Array = (byte[])Serializer.ReadObject(fs);
     fs.Close();
     Grid.LinearArr = Array;
 }
コード例 #3
0
        public static void SaveToFile(string FileName, SudokuGrid Grid)
        {
            byte[] Array = Grid.LinearArr;
            DataContractJsonSerializer Serializer = new DataContractJsonSerializer(typeof(byte[]));
            FileStream fs = new FileStream(FileName, FileMode.OpenOrCreate);

            Serializer.WriteObject(fs, Array);
            fs.Close();
        }
コード例 #4
0
        public static void LoadFromFile(string FileName, SudokuGrid Grid)
        {
            DataContractJsonSerializer Serializer = new DataContractJsonSerializer(typeof(byte[]));
            FileStream fs = new FileStream(FileName, FileMode.Open);

            byte[] Array = (byte[])Serializer.ReadObject(fs);
            fs.Close();
            Grid.LinearArr = Array;
        }
コード例 #5
0
ファイル: SudokuSolver.cs プロジェクト: Aftnet/SudokuSolver
        public SudokuGrid ConvertSolution(int SolutionIx)
        {
            SudokuGrid Output           = new SudokuGrid();
            var        SelectedSolution = Solutions[SolutionIx];

            int CellValue, RowNo, ColNo;

            foreach (int i in SelectedSolution)
            {
                CoverMatrixIndexToVal(i, out CellValue, out RowNo, out ColNo);
                Output.Data[RowNo, ColNo] = (byte)CellValue;
            }

            return(Output);
        }
コード例 #6
0
ファイル: SudokuSolver.cs プロジェクト: Aftnet/SudokuSolver
        public void SetInput(SudokuGrid Input)
        {
            ClearSolution();

            if (Input.Valid == false)
            {
                throw new ArgumentException();
            }

            int NumRows = 729;
            int NumCols = 324;

            InputSudoku = Input;
            BuildFrame(NumRows, NumCols);

            bool[] CoverMatrixRow = new bool[NumCols];
            int    CellValue, RowNo, ColNo;

            for (int i = 0; i < NumRows; i++)
            {
                CoverMatrixIndexToVal(i, out CellValue, out RowNo, out ColNo);
                GenerateCoverMatrixRow(CellValue, RowNo, ColNo, CoverMatrixRow);
                AddInputRow(i, CoverMatrixRow);

                //Test
                int test = CoverMatrixValToIndex(CellValue, RowNo, ColNo);
                if (test != i)
                {
                    throw new Exception();
                }
            }

            //Select rows according to given knowns
            for (RowNo = 0; RowNo < InputSudoku.Data.GetLength(0); RowNo++)
            {
                for (ColNo = 0; ColNo < InputSudoku.Data.GetLength(1); ColNo++)
                {
                    CellValue = (int)InputSudoku.Data[RowNo, ColNo];
                    if (CellValue != 0)
                    {
                        ForceRowInSolution(CoverMatrixValToIndex(CellValue, RowNo, ColNo));
                    }
                }
            }
        }
コード例 #7
0
        public void SetInput(SudokuGrid Input)
        {
            ClearSolution();

            if (Input.Valid == false)
            {
                throw new ArgumentException();
            }

            int NumRows = 729;
            int NumCols = 324;

            InputSudoku = Input;
            BuildFrame(NumRows, NumCols);

            bool[] CoverMatrixRow = new bool[NumCols];
            int CellValue, RowNo, ColNo;
            for (int i = 0; i < NumRows; i++)
            {
                CoverMatrixIndexToVal(i, out CellValue, out RowNo, out ColNo);
                GenerateCoverMatrixRow(CellValue, RowNo, ColNo, CoverMatrixRow);
                AddInputRow(i, CoverMatrixRow);

                //Test
                int test = CoverMatrixValToIndex(CellValue, RowNo, ColNo);
                if (test != i)
                {
                    throw new Exception();
                }
            }

            //Select rows according to given knowns
            for (RowNo = 0; RowNo < InputSudoku.Data.GetLength(0); RowNo++)
            {
                for (ColNo = 0; ColNo < InputSudoku.Data.GetLength(1); ColNo++)
                {
                    CellValue = (int)InputSudoku.Data[RowNo, ColNo];
                    if (CellValue != 0)
                    {
                        ForceRowInSolution(CoverMatrixValToIndex(CellValue, RowNo, ColNo));
                    }
                }
            }
        }
コード例 #8
0
        public SudokuGrid ConvertSolution(int SolutionIx)
        {
            SudokuGrid Output = new SudokuGrid();
            var SelectedSolution = Solutions[SolutionIx];
            
            int CellValue, RowNo, ColNo;
            foreach (int i in SelectedSolution)
            {
                CoverMatrixIndexToVal(i, out CellValue, out RowNo, out ColNo);
                Output.Data[RowNo, ColNo] = (byte)CellValue;
            }

            return Output;
        }