public Human(Vector2 position) { this.position = position; angle = ((float)(Math.PI / 2)) * RandomGen.GetInstance().Next(0, 4); scale = new Vector2(0.10f, 0.10f); dna = new DNA(); needsManager = new NeedsManager(this); alive = true; behavior = new ActionDecide(this); }
public override Status Run(GameTime gameTime) { if (currentStatus == Status.New) { Initialize(); } else if (currentStatus != Status.Running) { return(currentStatus); } if (currentNode != null) { Status status = currentNode.Run(gameTime); switch (status) { case BaseNode.Status.Success: currentNode = null; break; case BaseNode.Status.Failure: currentNode = null; break; case BaseNode.Status.Error: Debug.Print("Node returned an error"); if (Debugger.IsAttached) { Debugger.Break(); } break; case BaseNode.Status.Running: case BaseNode.Status.New: break; } } else { // Choose random angle and rotate that amount float randomAngle = (float)RandomGen.GetInstance().Next(-200, 200) / 100; BaseNode node1 = new ActionSatisfyNeeds(human); BaseNode node2 = new ActionRotate(human, randomAngle); Queue <BaseNode> queue = new Queue <BaseNode>(); queue.Enqueue(node2); queue.Enqueue(node1); currentNode = new Sequence(queue); } return(BaseNode.Status.Running); }
// Create DNA from two parents public DNA(DNA dna1, DNA dna2) { foreach (PhysicalAttribute attribute in Enum.GetValues(typeof(PhysicalAttribute))) { // Select value from either parent float value1 = dna1.GetPhysicalAttr(attribute); float value2 = dna2.GetPhysicalAttr(attribute); float chosenValue = RandomGen.GetInstance().Next(0, 2) == 0 ? value1 : value2; // Add random variance, maximum of 5%. float finalValue = chosenValue * (RandomGen.GetInstance().Next(95, 106) / 100); physicalAttributes.Add(attribute, finalValue); } }
public DNA() { physicalAttributes = new Dictionary <PhysicalAttribute, float>(); // Thirst attributes physicalAttributes.Add(PhysicalAttribute.ThirstIncreaseRate, RandomGen.GetFloat(0.95f, 1f)); physicalAttributes.Add(PhysicalAttribute.MaxThirst, RandomGen.GetInstance().Next(98, 103)); physicalAttributes.Add(PhysicalAttribute.ThirstThreshold, RandomGen.GetFloat(0.01f, 0.03f)); //TODO set to something higher physicalAttributes.Add(PhysicalAttribute.ViewDistance, RandomGen.GetInstance().Next(50, 75)); // Speed attributes physicalAttributes.Add(PhysicalAttribute.RotateSpeed, RandomGen.GetFloat(0.50f, 3.0f)); physicalAttributes.Add(PhysicalAttribute.WalkSpeed, RandomGen.GetFloat(0.08f, 0.12f)); }
public static Color AddNoise(int amount, Color color) { int R = color.R + RandomGen.GetInstance().Next(-amount, amount + 1); int G = color.G + RandomGen.GetInstance().Next(-amount, amount + 1); int B = color.B + RandomGen.GetInstance().Next(-amount, amount + 1); R = R > 255 ? 255 : R; R = R < 0 ? 0 : R; G = G > 255 ? 255 : G; G = G < 0 ? 0 : G; B = B > 255 ? 255 : B; B = B < 0 ? 0 : B; return(new Color(R, G, B)); }