private void DistributeBallotsByFirstPreference(List <string> Candidates, List <AVote> Ballots) { foreach (AVote Ballot in Ballots) { int Index = 0; foreach (int Value in this.ExtractBallotPreferences(Ballot.showAllVoteForCandidate())) { if (Value == 1) { this.CandidateBallotFragments[Candidates[Index]].Add(Ballot, 2); } Index++; } } Dictionary <string, int> Results = new Dictionary <string, int>(); for (int i = 0; i < Candidates.Count; i++) { Results.Add(Candidates[i], (this.CandidateBallotFragments.ContainsKey(Candidates[i])? this.CandidateBallotFragments[Candidates[i]].Count : 0)); } this.RoundsResults.Add(Results); this.RoundExhaustedBallots.Add(0); this.RoundValidBallots.Add(this.TotalBallots - this.InvalidBallots - this.RoundExhaustedBallots[0]); this.RoundMajority.Add(this.RoundValidBallots[0] / 2 + 1); this.CurrentRound++; this.TotalRounds++; }
private int EliminateInvalidBallots(List <AVote> Ballots) { List <AVote> InvalidBallots = new List <AVote>(); foreach (AVote Ballot in Ballots) { int index = 0; List <int> Preferences = this.ExtractBallotPreferences(Ballot.showAllVoteForCandidate()); bool IsEliminated = false; do { if (Preferences.Count(i => i == Preferences[index]) > 1 || Preferences[index] > Preferences.Count || Preferences[index] < 1) { InvalidBallots.Add(Ballot); IsEliminated = true; } index++; } while (!IsEliminated && index < Preferences.Count); } foreach (AVote Ballot in InvalidBallots) { Ballots.Remove(Ballot); } return(InvalidBallots.Count); }