public EmelieSimulationContext() { name = "SIMULATION_NAME"; states = new EmelieState[2]; states[0] = new EmelieState(); states[1] = new EmelieState(); events = new EmelieEvent[2]; events[0] = new EmelieEvent(); events[1] = new EmelieEvent(); personalityMeasurements = new string[4]; personalityMeasurements[0] = "KIND"; personalityMeasurements[1] = "5"; personalityMeasurements[2] = "BRAVE"; personalityMeasurements[3] = "5"; traits = new EmelieTrait[2]; traits[0] = new EmelieTrait(); traits[1] = new EmelieTrait(); startingState = "STATE_INFANCY"; }
public string Run(EmelieSimulationContext context, string programVersion) { string resultingEvert = ""; simulationLog = new List <string>(); if (context.simulationStep <= 0f) { Log.Error("simulationStep cannot be" + " 0"); return("Simulation Failed"); } // Create charcter EmelieCharacter c = new EmelieCharacter(context); c.name = "<# " + c.gender + "_name>∫<# surName>"; c.finalAge = EmelieUtilities.RandomRange(5f, 90f); resultingEvert += "<= character_name " + c.name + " >"; resultingEvert += "<= gender " + c.gender + " >"; resultingEvert += "<= finalAge " + c.finalAge + " >"; c.currentAge = 0f; int numOfTraits = 3; while (c.traits.Count < numOfTraits) { EmelieTrait randomTrait = context.traits[EmelieUtilities.RandomRange(0, context.traits.Length)]; if (c.AddTrait(randomTrait)) { SimLog(c.currentAge, "born with trait " + randomTrait.name); } } foreach (EmelieTrait trait in context.traits) { bool r = c.traits.Contains(trait); resultingEvert += "<= IS_" + trait.name + " " + r.ToString().ToLower() + ">"; } foreach (string s in context.personalityMeasurements) { resultingEvert += "<= " + s + " " + c.personalityPoints[s] + ">"; } float currentYear = context.year - c.finalAge; EmelieState startingState = context.GetStartingState(); SimLog(c.currentAge, "Character Born, gender=" + c.gender + ", final age=" + System.Math.Round((double)c.finalAge).ToString()); resultingEvert += "<# CHARACTER_BORN><= currentYear " + currentYear.ToString("####") + ">"; EmelieState currentState = startingState; while (c.currentAge < c.finalAge) { List <string> possibleEvents = new List <string>(); possibleEvents.AddRange(currentState.events); possibleEvents.AddRange(context.alwaysPossibleEvents); foreach (string eventName in possibleEvents) { EmelieEvent _event = context.GetEvent(eventName); if (EmelieUtilities.PercentageChance(_event.probability)) { bool passedAlltests = true; foreach (EmelieRequirement req in _event.requirements) { if (!req.IsMet(c, _event)) { passedAlltests = false; break; } } if (!passedAlltests) { continue; } SimLog(c.currentAge, "EVENT: " + _event.name); resultingEvert += "<= currentAge " + c.currentAge + ">"; resultingEvert += "<= currentYear " + currentYear.ToString("####") + ">"; resultingEvert += "<# EVENT_" + _event.name + ">"; foreach (string attr in _event.attributesAdded) { c.AddAttribute(attr); SimLog(c.currentAge, "ATTRIBUTE_ADDED: " + attr); resultingEvert += "<= HAS_ATTRIBUTE_" + attr + " true>"; } if (_event.destinationState != "") { currentState = context.GetState(_event.destinationState); SimLog(c.currentAge, "STATE: " + currentState.name); continue; } } } c.currentAge += context.simulationStep; currentYear += context.simulationStep; if (c.currentAge > c.finalAge) { c.currentAge = c.finalAge; } } resultingEvert += "<# story_end>\n"; return(resultingEvert); }
public bool IsMet(EmelieCharacter c, EmelieEvent _event) { switch (comparer) { case HAVE_ATTRIBUTE: { return(c.attributes.Contains(text)); } case DONT_HAVE_ATTRIBUTE: { return(!c.attributes.Contains(text)); } case HAVE_TRAIT: { return(c.HaveTrait(text)); } case DONT_HAVE_TRAIT: { return(!c.HaveTrait(text)); } case IS_OLDER_THAN: { return(c.currentAge > number); } case IS_YOUNGER_THAN: { return(c.currentAge < number); } case HAS_GENDER: { return(c.gender == text); } case PERSONALITY_POINT_GREATER_THAN: { return(c.personalityPoints[text] > number); } case PERSONALITY_POINT_LESS_THAN: { return(c.personalityPoints[text] < number); } case CLASS_GREATER_THAN: { return(c.economicClass > number); } case CLASS_LESS_THAN: { return(c.economicClass < number); } default: Log.SyntaxError("Undefined requirement comaparer:" + comparer); break; } return(true); }