示例#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();
            }
        }
示例#2
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="parentCell"></param>
 public CandidatesSortedSet(SudokuGridCell parentCell)
 {
     ParentCell           = parentCell;
     CandidatesDecreased += (s, e) =>
     {
         // no substitutions exist => incorrect substitution has been made earlier
         if (Count == 0)
         {
             OnContradictionFound(EventArgs.Empty);
         }
         // the only possible substitution found
         else if (Count == 1)
         {
             parentCell.Number     = this.ToArray()[0];
             parentCell.Candidates = null;
         }
     };
 }
示例#3
0
 // BUG: used to avoid buggy duplicate-code decision in solver classes -- get rid of as soon as possible
 internal static void AssignNewCell(SudokuGrid grid, SudokuGridCell cell)
 {
     cell.NumberChanged += (s, e) => grid.OnCellNumberChanged(new CellNumberChangedEventArgs((SudokuGridCell)s));
     grid.cells[cell.Position.Y, cell.Position.X] = cell;
 }
示例#4
0
 public CellNumberChangedEventArgs(SudokuGridCell cell)
 {
     this.cell = cell;
 }