Esempio n. 1
0
        private IEnumerable <(IEnumerable <Position> positions, IEnumerable <Value> values)> HiddenSubsetStep(
            Grid input,
            Dictionary <Value, IEnumerable <Position> > house,
            Dictionary <Position, int> positions,
            Candidates values,
            int startingIndex,
            int depth)
        {
            if (positions.Count > depth ||
                values.Count() + house.Count - startingIndex <= depth ||
                positions.Keys.Any(pos => (input.GetCandidates(pos) & values) == 0))
            {
                yield break;
            }

            if (values.Count() == depth)
            {
                if (positions.Keys.Any(pos => (input.GetCandidates(pos) & ~values) != 0))
                {
                    yield return(positions.Keys.ToList(), values.ToValues());
                }

                yield break;
            }

            for (int i = startingIndex; i < house.Keys.Count; i++)
            {
                var value = house.Keys.ElementAt(i);

                foreach (var pos in house[value])
                {
                    if (!positions.ContainsKey(pos))
                    {
                        positions[pos] = i;
                    }
                }

                var valuesNew = values | value.AsCandidates();
                foreach (var item in HiddenSubsetStep(input, house, positions, valuesNew, i + 1, depth))
                {
                    yield return(item);
                }

                foreach (var pos in house[value])
                {
                    if (positions[pos] == i)
                    {
                        positions.Remove(pos);
                    }
                }
            }
        }
Esempio n. 2
0
 public int GetFirstCandidate()
 {
     if (Candidates.Count() > 0)
     {
         return(Candidates[0]);
     }
     else
     {
         return(-1);
     }
 }
Esempio n. 3
0
 public int GetCandidate(int index)
 {
     if (index >= 0 && index < Candidates.Count())
     {
         return(Candidates[index]);
     }
     else
     {
         return(-1);
     }
 }
Esempio n. 4
0
        public override string ToString()
        {
            var result = new StringBuilder();

            result.Append("SudokuElement : [Number=");
            result.Append(Number);
            result.Append("; Candidates={");
            if (Candidates.Count() > 0)
            {
                foreach (int num in Candidates)
                {
                    result.Append(num);
                    result.Append(", ");
                }
                result.Remove(result.Length - 2, 2);
            }
            result.Append("}; FontColor=");
            result.Append(FontColor.ToString());
            result.Append("]");

            return(result.ToString());
        }
        private void Vote()
        {
            var answer = MessageBox.Show(
                Language.AreYouVote,
                Language.Question,
                MessageBoxButton.YesNo,
                MessageBoxImage.Question);

            if (answer == MessageBoxResult.No)
            {
                return;
            }

            int numberOfVotes = Candidates.Count(x => x.IsChecked);

            int?candidateIndex = numberOfVotes == 1
                    ? Candidates.IndexOf(Candidates.Single(x => x.IsChecked))
                    : (int?)null;

            mainViewModel.VoteService.SaveVote(_person, candidateIndex);

            mainViewModel.OpenResultView();
        }
Esempio n. 6
0
        public void Candidates_Count_should_depend_on_selected_candidates(Candidates candidates, int expected)
        {
            var actual = candidates.Count();

            actual.Should().Be(expected);
        }
Esempio n. 7
0
 public int GetCandidatesSize() => Candidates.Count();
Esempio n. 8
0
 public void TestNew()
 {
     Assert.Equal(9, tgt.Count());
     Assert.Equal("1-2-3-4-5-6-7-8-9", tgt.ToString());
 }