public PersonaClassification GetNextTrustExchangePersonaClassification() { List <PersonaClassification> classifications = Personas.Select <Persona, PersonaClassification>(p => p.Classification).ToList(); int cooperatorCount = classifications.Where(c => c.Value == PersonaClassifications.Cooperator.Value).Count(); int defectorCount = classifications.Where(c => c.Value == PersonaClassifications.Defector.Value).Count(); int indeterminateRemainingCount = RoundCountPerTask - cooperatorCount - defectorCount; Func <PersonaClassification> getRandomPersonaClassification = () => { PersonaClassification[] options = new PersonaClassification[] { PersonaClassifications.Cooperator, PersonaClassifications.Defector }; return (options[new Random().Next(0, options.Count())]); }; if (indeterminateRemainingCount >= RoundCountPerTask / 2) { return(getRandomPersonaClassification()); } else { if (cooperatorCount > defectorCount) { if (indeterminateRemainingCount >= (cooperatorCount - defectorCount)) { return(PersonaClassifications.Defector); } else { return(PersonaClassifications.Cooperator); } } else { return(PersonaClassifications.Cooperator); } } }
public List <Persona> GetPersonas <T>(PersonaClassification personaClassification, int take = -1, List <T> notInRounds = null) where T : Round { Random r = new Random(); List <Persona> allMatchingPersonas = Personas .OrderBy(t => r.Next()) .Where ( persona => persona.Classification == personaClassification && ( ReferenceEquals(notInRounds, null) || (!ReferenceEquals(notInRounds, null) && !notInRounds.Select <T, Persona>(round => round.Persona).Contains(persona)) ) ) .ToList(); return (allMatchingPersonas .Take(take == -1 ? allMatchingPersonas.Count : take) .ToList()); }
public static int GetCount <T>(this List <T> rounds, PersonaClassification personaClassification) where T : Round { return(rounds.Where(r => r.Persona.Classification == personaClassification).Count()); }