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(); }
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; }
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); }
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)); } } } }
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; }