public static NumbersBinary UseNumber(this NumbersBinary numbers, Int32 number)
 {
     if (number < 0)
     {
         throw new ArgumentOutOfRangeException(nameof(number));
     }
     return(numbers & ~(1 << (number - 1)));
 }
Example #2
0
 private void Process(NumbersInfo numbersInfo, GridPoint cell, NumbersBinary freeNumbers)
 {
     for (Int32 number = Defs.MinNumber; number < Defs.MaxNumber; ++number)
     {
         if ((freeNumbers & NumbersBinaryHelper.CreateForNumber(number)) != 0)
         {
             AddCell(numbersInfo, number, cell);
         }
     }
 }
Example #3
0
        private static CellsInfo ScanCells(Grid grid, GridPoint[] cells)
        {
            CellsInfo     cellsInfo  = new CellsInfo();
            NumbersBinary allNumbers = NumbersBinaryHelper.CreateForRange(Defs.MinNumber, Defs.MaxNumber);
            NumbersBinary result     = cells.Where(cell => grid[cell] != 0).Aggregate(allNumbers, (numbers, cell) => numbers.UseNumber(grid[cell]));

            foreach (GridPoint cell in cells.Where(cell => grid[cell] == 0))
            {
                cellsInfo.Data[cell] = result;
            }
            return(cellsInfo);
        }
 public static NumbersBinary AppendSquare(this NumbersBinary numbers, Grid grid, GridPoint point)
 {
     if (grid == null)
     {
         throw new ArgumentNullException(nameof(grid));
     }
     if (point.Row > grid.RowCount || point.Column > grid.ColumnCount)
     {
         throw new ArgumentOutOfRangeException(nameof(point));
     }
     return(AppendCells(numbers, grid, GridPointGenerator.GenerateSquare(point)));
 }
 public static NumbersBinary AppendColumn(this NumbersBinary numbers, Grid grid, Int32 column)
 {
     if (grid == null)
     {
         throw new ArgumentNullException(nameof(grid));
     }
     if (column < 1 || column > grid.ColumnCount)
     {
         throw new ArgumentOutOfRangeException(nameof(column));
     }
     return(AppendCells(numbers, grid, GridPointGenerator.GenerateColumn(column)));
 }
 public static NumbersBinary AppendRow(this NumbersBinary numbers, Grid grid, Int32 row)
 {
     if (grid == null)
     {
         throw new ArgumentNullException(nameof(grid));
     }
     if (row < 1 || row > grid.RowCount)
     {
         throw new ArgumentOutOfRangeException(nameof(row));
     }
     return(AppendCells(numbers, grid, GridPointGenerator.GenerateRow(row)));
 }
Example #7
0
        public CellsInfo CreateForRow(Grid grid, Int32 row)
        {
            if (grid == null)
            {
                throw new ArgumentNullException(nameof(grid));
            }
            if (row < 1 || row > grid.RowCount)
            {
                throw new ArgumentOutOfRangeException(nameof(row));
            }
            CellsInfo cellsInfo = grid.ScanRow(row);

            foreach (GridPoint cell in cellsInfo.Data.Keys.ToArray())
            {
                NumbersBinary numbers = cellsInfo.Data[cell].AppendColumn(grid, cell.Column).AppendSquare(grid, cell);
                cellsInfo.Data[cell] = numbers;
            }
            return(cellsInfo);
        }
Example #8
0
        public CellsInfo CreateForSquare(Grid grid, GridPoint point)
        {
            if (grid == null)
            {
                throw new ArgumentNullException(nameof(grid));
            }
            if (point.Row > grid.RowCount || point.Column > grid.ColumnCount)
            {
                throw new ArgumentOutOfRangeException(nameof(point));
            }
            CellsInfo cellsInfo = grid.ScanSquare(point);

            foreach (GridPoint cell in cellsInfo.Data.Keys.ToArray())
            {
                NumbersBinary number = cellsInfo.Data[cell].AppendRow(grid, cell.Row).AppendColumn(grid, cell.Column);
                cellsInfo.Data[cell] = number;
            }
            return(cellsInfo);
        }
Example #9
0
 public Boolean Equals(NumbersBinary other)
 {
     return(Value == other.Value);
 }
Example #10
0
 private static NumbersBinary AppendCells(NumbersBinary numbers, Grid grid, GridPoint[] cells)
 {
     return(cells.Select(cell => grid[cell]).Where(number => number != 0).Aggregate(numbers, UseNumber));
 }