Example #1
0
 // WI: ? make virtual calls
 /// <summary>
 /// Converts data in the specified binary file to the instance of grid.
 /// </summary>
 /// <param name="binaryFile">Binary file containing 
 /// compressed grid.</param>
 /// <returns>Instance of a particular grid.</returns>
 public static SudokuGrid FromBinary(FileStream binaryFile)
 {
     SudokuGridConstraints constraints;
     SudokuGridMetrics metrics;
     byte[] numbersKinds;
     string content = SudokuConverter.ToText(binaryFile, out constraints, out numbersKinds, out metrics);
     //string content = SudokuConverter.ToText(binaryFile, out constraints, out metrics);
     switch (metrics.MaximumNumber)
     {
         case 9:
             var grid = new SudokuGrid9x3(constraints);
             grid.IterateLinesXY((x, y) =>
             {
                 var cell = new SudokuGridCell(grid, 
                     new SudokuGridPosition(x, y, false), 
                     byte.Parse(content[metrics.MaximumNumber * y + x].ToString()));
                 //cell.NumberChanged += (s, e) => grid.OnCellNumberChanged(new CellNumberChangedEventArgs((SudokuGridCell)s));
                 //grid.cells[y, x] = cell;
                 AssignNewCell(grid, cell);
             });
             return grid;
         default:
             throw new SudokuGridNotSupportedException();
     }
 }
Example #2
0
        // WI: ? make virtual calls
        /// <summary>
        /// Converts data in the specified binary file to the instance of grid.
        /// </summary>
        /// <param name="binaryFile">Binary file containing
        /// compressed grid.</param>
        /// <returns>Instance of a particular grid.</returns>
        public static SudokuGrid FromBinary(FileStream binaryFile)
        {
            SudokuGridConstraints constraints;
            SudokuGridMetrics     metrics;

            byte[] numbersKinds;
            string content = SudokuConverter.ToText(binaryFile, out constraints, out numbersKinds, out metrics);

            //string content = SudokuConverter.ToText(binaryFile, out constraints, out metrics);
            switch (metrics.MaximumNumber)
            {
            case 9:
                var grid = new SudokuGrid9x3(constraints);
                grid.IterateLinesXY((x, y) =>
                {
                    var cell = new SudokuGridCell(grid,
                                                  new SudokuGridPosition(x, y, false),
                                                  byte.Parse(content[metrics.MaximumNumber * y + x].ToString()));
                    //cell.NumberChanged += (s, e) => grid.OnCellNumberChanged(new CellNumberChangedEventArgs((SudokuGridCell)s));
                    //grid.cells[y, x] = cell;
                    AssignNewCell(grid, cell);
                });
                return(grid);

            default:
                throw new SudokuGridNotSupportedException();
            }
        }