예제 #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);
        }