示例#1
0
        public bool VerifyColumn(int columnNumber)
        {
            CellCoordinate cell    = new CellCoordinate(0, columnNumber);
            Del            handler = cell.MoveToNextCellInColumn;

            return(Verify(handler));
        }
示例#2
0
        public bool FillBoard(CellCoordinate cell)
        {
            if (IsCellEmpty(cell))
            {
                iterations++;

                foreach (int value in Enumerable.Range(1, 9))
                {
                    if (!TrySetCell(cell, value))
                    {
                        continue;
                    }

                    Print();

                    if (FillBoard(cell))
                    {
                        return(true);
                    }
                }

                ClearCell(cell);

                return(false);
            }

            if (cell.MoveToNextCellInGrid())
            {
                return(FillBoard(cell));
            }
            return(true);
        }
示例#3
0
        public bool VerifyRow(int rowNumber)
        {
            CellCoordinate cell    = new CellCoordinate(rowNumber, 0);
            Del            handler = cell.MoveToNextCellInRow;

            return(Verify(handler));
        }
示例#4
0
        public bool VerifyBlock(int blockNumber)
        {
            int rowOffset    = (blockNumber / 3) * 3;
            int columnOffset = (blockNumber % 3) * 3;

            CellCoordinate cell    = new CellCoordinate(rowOffset, columnOffset);
            Del            handler = cell.MoveToNextCellInBlock;

            return(Verify(handler));
        }
示例#5
0
        public void DeleteRandomCell()
        {
            CellCoordinate cell = new CellCoordinate();

            do
            {
                cell.Randomize();
            } while (IsCellEmpty(cell));

            ClearCell(cell);
        }
示例#6
0
        public bool IncreaseCellValue(CellCoordinate cell)
        {
            if (board[cell.row, cell.column] < 9)
            {
                board[cell.row, cell.column]++;
                return(true);
            }

            board[cell.row, cell.column] = 0;

            return(false);
        }
示例#7
0
        public bool TrySetCell(CellCoordinate cell, int value)
        {
            SetCell(cell, value);

            return(VerifyBoard());
        }
示例#8
0
 public bool IsCellEmpty(CellCoordinate cell)
 {
     return(board[cell.row, cell.column] == 0);
 }
示例#9
0
 public void ClearCell(CellCoordinate cell)
 {
     board[cell.row, cell.column] = 0;
 }
示例#10
0
 public int GetCell(CellCoordinate cell)
 {
     return(board[cell.row, cell.column]);
 }
示例#11
0
 public void SetCell(CellCoordinate cell, int value)
 {
     board[cell.row, cell.column] = value;
 }
示例#12
0
        public void Solve()
        {
            CellCoordinate cell = new CellCoordinate();

            FillBoard(cell);
        }