Ejemplo n.º 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();
 }
Ejemplo n.º 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;
 }
Ejemplo n.º 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();
        }
Ejemplo n.º 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;
        }
Ejemplo n.º 5
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);
        }
Ejemplo n.º 6
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));
                    }
                }
            }
        }
Ejemplo n.º 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));
                    }
                }
            }
        }
Ejemplo n.º 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;
        }