public void RollDiceAndExecuteOneOutcome(SocietySnapshot currentCast, Random rng)
        {
            InitializeTextSummary();

            var chosen = AObjectWithProbability.PickOne(AllPossibleOutcomes, rng);

            this.outcomeTextSummary.AddRange(chosen.Execute());
            this.textSummary.AddRange(outcomeTextSummary);
        }
        //Future: implement generic groups (ie races, nationalities, economic classes) #TODO

        public SocietySnapshot Copy()
        {
            var theCopy = new SocietySnapshot();

            foreach (Character c in AllCharacters)
            {
                theCopy.AllCharacters.Add(c.Copy());
            }

            return(theCopy);
        }
        public void PopulateAllRoles_Randomly(SocietySnapshot currentCast, Random rng)
        {
            if (rng == null)
            {
                rng = new Random();
            }

            var nonParticipants = currentCast.AllCharacters.ToList();//must copy list to avoid changes to original

            foreach (Role r in this.allRoles)
            {
                r.AddParticipantsRandomly(nonParticipants, rng);
                nonParticipants = nonParticipants.Where(n => false == r.Participants.Any(p => n.Id == p.Id)).ToList();
            }
        }
        public bool TryToPopulateIncident(SocietySnapshot currentCast, Random rng)
        {
            if (MyPrerequisites.Any() == false)
            {
                PopulateAllRoles_Randomly(currentCast, rng);
                return(true);
            }
            else
            {
                PopulateAllRoles_FollowingPrereqs(currentCast, rng);
            }

            var allAreFulfilled = !prerequisites.Any(p => p.IsMetByCurrentParticipants() == false);

            return(allAreFulfilled);
        }
        public void PopulateAllRoles_FollowingPrereqs(SocietySnapshot currentCast, Random rng)
        {
            if (rng == null)
            {
                rng = new Random();
            }

            var nonParticipants = currentCast.AllCharacters.ToList();//must copy list to avoid changes to original

            //Start with whichever role is hardest to fill
            var rolesOrderedByCountOfFirstCandidates = allRoles.OrderBy(r =>
                                                                        r.FirstCandidateOptions(nonParticipants, MyPrerequisites, currentCast).Count
                                                                        + (r.MinCount == 0 ? 1 : 0));//add to count if min particpants == 0

            var roleToStartWith = rolesOrderedByCountOfFirstCandidates.First();
            var firstCandidates = roleToStartWith.FirstCandidateOptions(nonParticipants, MyPrerequisites, currentCast);

            roleToStartWith.AddOneParticipantRandomly(firstCandidates, rng);
            nonParticipants = nonParticipants.Where(n => false == roleToStartWith.Participants.Any(p => n.Id == p.Id)).ToList();

            //One cycle through roles, adding one participant to each
            foreach (Role r in this.allRoles)
            {
                if (r.RoleName == roleToStartWith.RoleName)
                {
                    continue;
                }

                if (r.MinCount == 0 && rng.Next(0, Role.DEFAULT_ROLE_MAX_COUNT) == 0)//chance to leave empty roles that are allow to have 0 participants
                {
                    continue;
                }

                var theCandidates = r.CandidatesThatPassPrereqs(nonParticipants, MyPrerequisites);
                r.AddOneParticipantRandomly(theCandidates, rng);
                nonParticipants = nonParticipants.Where(n => false == r.Participants.Any(p => n.Id == p.Id)).ToList();
            }

            //Cycle again, adding further participants
            foreach (Role r in this.allRoles)
            {
                r.AddParticipantsRandomly_RetestingAfterEach(nonParticipants, MyPrerequisites, rng);
                nonParticipants = nonParticipants.Where(n => false == r.Participants.Any(p => n.Id == p.Id)).ToList();
            }
        }
        public override bool IsCharacterViableFirstCandidateForRole(Character candidate, string nameOfRole, SocietySnapshot currentCast)
        {
            if (nameOfRole == this.roleAlpha.RoleName)
            {
                int minRoleB = roleBeta.MinCount.HasValue ? roleBeta.MinCount.Value : 0;
                if (CountRelationsThatPassBenchmark(candidate) < minRoleB)
                {
                    return(false);
                }
            }
            else if (nameOfRole == this.roleBeta.RoleName)
            {
                if (false == currentCast.AllCharacters.Any(a => HasDirectionalRelationThatPassesBenchmark(a, candidate)))
                {
                    return(false);
                }
            }

            return(true);
        }
Exemple #7
0
 public void ExecuteIncidentAndStoreAfter(IIncident oneIncident, SocietySnapshot currentCast, Random rng)
 {
     oneIncident.RollDiceAndExecuteOneOutcome(currentCast, rng);
     this.TheIncidents.Add(oneIncident);
     this.TheCastOverTime.Add(currentCast.Copy());
 }
Exemple #8
0
 public Plot(SocietySnapshot givenStartingCast)
 {
     startingCast    = givenStartingCast.Copy();
     theIncidents    = new List <IIncident>();
     theCastOverTime = new List <SocietySnapshot>();
 }
Exemple #9
0
        public List <Character> FirstCandidateOptions(List <Character> theCandidates, List <IPrerequisite> thePrereqs, SocietySnapshot currentCast)
        {
            var viableFirstCandidates = new List <Character>();

            viableFirstCandidates = theCandidates.Where(c => false == thePrereqs.Any(p => false == p.IsCharacterViableFirstCandidateForRole(c, this.RoleName, currentCast))).ToList();
            return(viableFirstCandidates);
        }
 public abstract bool IsCharacterViableFirstCandidateForRole(Character candidate, string nameOfRole, SocietySnapshot currentCast);
        public override bool IsCharacterViableFirstCandidateForRole(Character candidate, string nameOfRole, SocietySnapshot currentCast)
        {
            if (nameOfRole == this.role.RoleName)
            {
                int minParticipants          = role.MinCount.HasValue ? role.MinCount.Value : 0;
                int countQualifyingRelations = currentCast.AllCharacters.Count(b => HaveMutualRelationThatPassesBenchmark(candidate, b));

                if (countQualifyingRelations < minParticipants)
                {
                    return(false);
                }
            }

            return(true);
        }