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); }
public void MoveDown() { if (GridMath.GetRowForIndex(selectedCell) < 8) { SetSelectedIndex(selectedCell + 9); } }
public void MoveUp() { if (GridMath.GetRowForIndex(selectedCell) > 0) { SetSelectedIndex(selectedCell - 9); } }
private bool InSameRow(List <int> cellIndicesWithValue) { return(cellIndicesWithValue.Select(x => GridMath.GetRowForIndex(x)).Distinct().Count() == 1); }
public void TestRowForIndex(int index, int expectedRow) { GridMath.GetRowForIndex(index).Should().Be(expectedRow); }