コード例 #1
0
ファイル: AIncident.cs プロジェクト: tod2garner/StorySkeleton
        public void RollDiceAndExecuteOneOutcome(SocietySnapshot currentCast, Random rng)
        {
            InitializeTextSummary();

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

            this.outcomeTextSummary.AddRange(chosen.Execute());
            this.textSummary.AddRange(outcomeTextSummary);
        }
コード例 #2
0
        //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);
        }
コード例 #3
0
ファイル: AIncident.cs プロジェクト: tod2garner/StorySkeleton
        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();
            }
        }
コード例 #4
0
ファイル: AIncident.cs プロジェクト: tod2garner/StorySkeleton
        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);
        }
コード例 #5
0
ファイル: AIncident.cs プロジェクト: tod2garner/StorySkeleton
        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();
            }
        }
コード例 #6
0
        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);
        }
コード例 #7
0
ファイル: Plot.cs プロジェクト: tod2garner/StorySkeleton
 public void ExecuteIncidentAndStoreAfter(IIncident oneIncident, SocietySnapshot currentCast, Random rng)
 {
     oneIncident.RollDiceAndExecuteOneOutcome(currentCast, rng);
     this.TheIncidents.Add(oneIncident);
     this.TheCastOverTime.Add(currentCast.Copy());
 }
コード例 #8
0
ファイル: Plot.cs プロジェクト: tod2garner/StorySkeleton
 public Plot(SocietySnapshot givenStartingCast)
 {
     startingCast    = givenStartingCast.Copy();
     theIncidents    = new List <IIncident>();
     theCastOverTime = new List <SocietySnapshot>();
 }
コード例 #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);
        }
コード例 #10
0
 public abstract bool IsCharacterViableFirstCandidateForRole(Character candidate, string nameOfRole, SocietySnapshot currentCast);
コード例 #11
0
        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);
        }