示例#1
0
        public void TestRelatedCellIndices(int index, int[] expectedRelatedIndices)
        {
            List <int> actualRelatedIndices = GridMath.GetRelatedCellIndices(index);

            actualRelatedIndices.Should().NotBeEmpty()
            .And.HaveCount(EXPECTED_NUMBER_OF_RELATED_INDICES);

            foreach (int expectedIndex in expectedRelatedIndices)
            {
                actualRelatedIndices.Should().Contain(expectedIndex);
            }
        }
        public bool ApplyRule(ref Board board)
        {
            bool ruleSuccess = false;

            for (int i = 0; i < GridMath.TotalNumberOfCells; i++)
            {
                if (board.IsCellSolved(i))
                {
                    int        solvedValue        = board.GetPossibleValues(i).First();
                    List <int> relatedCellIndices = GridMath.GetRelatedCellIndices(i);

                    foreach (int relatedCellIndex in relatedCellIndices)
                    {
                        bool removalSuccessful = board.RemoveValueFromCell(relatedCellIndex, solvedValue);
                        ruleSuccess |= removalSuccessful;
                    }
                }
            }

            return(ruleSuccess);
        }