Exemplo n.º 1
0
        public bool ApplyRule(ref Board board)
        {
            bool ruleSucceeded = false;

            for (int squareNumber = 0; squareNumber < 9; squareNumber++)
            {
                CellData cellData = board.GetCellDataForSquare(squareNumber);

                foreach (int unsolvedValue in cellData.GetUnsolvedValues())
                {
                    List <int> cellIndicesWithUnsolvedValue = cellData.GetCellIndicesWithValue(unsolvedValue);
                    if (InSameRow(cellIndicesWithUnsolvedValue))
                    {
                        CellData allCellsInRow    = board.GetCellDataForRow(GridMath.GetRowForIndex(cellIndicesWithUnsolvedValue.First()));
                        bool     removalSucceeded = RemoveUnsolvedValueFromCellsNotInSquare(ref board, unsolvedValue, squareNumber, allCellsInRow);
                        ruleSucceeded |= removalSucceeded;
                    }
                    else if (InSameColumn(cellIndicesWithUnsolvedValue))
                    {
                        CellData allCellsInColumn = board.GetCellDataForColumn(GridMath.GetColumnForIndex(cellIndicesWithUnsolvedValue.First()));
                        bool     removalSucceeded = RemoveUnsolvedValueFromCellsNotInSquare(ref board, unsolvedValue, squareNumber, allCellsInColumn);
                        ruleSucceeded |= removalSucceeded;
                    }
                }
            }

            return(ruleSucceeded);
        }
Exemplo n.º 2
0
 public void MoveDown()
 {
     if (GridMath.GetRowForIndex(selectedCell) < 8)
     {
         SetSelectedIndex(selectedCell + 9);
     }
 }
Exemplo n.º 3
0
 public void MoveUp()
 {
     if (GridMath.GetRowForIndex(selectedCell) > 0)
     {
         SetSelectedIndex(selectedCell - 9);
     }
 }
Exemplo n.º 4
0
 private bool InSameRow(List <int> cellIndicesWithValue)
 {
     return(cellIndicesWithValue.Select(x => GridMath.GetRowForIndex(x)).Distinct().Count() == 1);
 }
Exemplo n.º 5
0
 public void TestRowForIndex(int index, int expectedRow)
 {
     GridMath.GetRowForIndex(index).Should().Be(expectedRow);
 }