コード例 #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);
        }
コード例 #2
0
 public void MoveLeft()
 {
     if (GridMath.GetColumnForIndex(selectedCell) > 0)
     {
         SetSelectedIndex(selectedCell - 1);
     }
 }
コード例 #3
0
 public void MoveRight()
 {
     if (GridMath.GetColumnForIndex(selectedCell) < 8)
     {
         SetSelectedIndex(selectedCell + 1);
     }
 }
コード例 #4
0
 private bool InSameColumn(List <int> cellIndicesWithValue)
 {
     return(cellIndicesWithValue.Select(x => GridMath.GetColumnForIndex(x)).Distinct().Count() == 1);
 }
コード例 #5
0
 public void TestColumnForIndex(int index, int expectedColumn)
 {
     GridMath.GetColumnForIndex(index).Should().Be(expectedColumn);
 }