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

            return(Verify(handler));
        }
Beispiel #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);
        }
Beispiel #3
0
        public bool VerifyRow(int rowNumber)
        {
            CellCoordinate cell    = new CellCoordinate(rowNumber, 0);
            Del            handler = cell.MoveToNextCellInRow;

            return(Verify(handler));
        }
Beispiel #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));
        }
Beispiel #5
0
        public void DeleteRandomCell()
        {
            CellCoordinate cell = new CellCoordinate();

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

            ClearCell(cell);
        }
Beispiel #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);
        }
Beispiel #7
0
        public bool TrySetCell(CellCoordinate cell, int value)
        {
            SetCell(cell, value);

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

            FillBoard(cell);
        }