void GiveBirth() { Vector3 location = UnityEngine.Random.onUnitSphere; location.y = 0; location.Normalize(); location *= Size * 1.1f; location += transform.position; VillagerBody newChild = Instantiate(VillagerPrefab, location, Quaternion.identity); newChild.transform.parent = transform.parent; newChild.Home = this; newChild.Alignment = Alignment; newChild.Female = UnityEngine.Random.value >= 0.5f; BrainWrapper newBrain = newChild.gameObject.AddComponent<BrainWrapper>(); newBrain.Brain = BrainLoader.NewBrain(); newBrain.SetRules(GameManager.Instance.Rules); if (FemaleMaterials.Count > 0 && MaleMaterials.Count > 0) { GeneticMaterial mother = FemaleMaterials.Dequeue(); GeneticMaterial father = MaleMaterials.Dequeue(); AiProtocol.IBrainGenetics childBrain = null; if (mother.BrainGenetics != null && father.BrainGenetics != null) childBrain = mother.BrainGenetics.Cross(father.BrainGenetics); newChild.Strength = (int)(mother.Strength + father.Strength + UnityEngine.Random.Range(-1f, 2f)); newChild.Intelligence = (int)(mother.Intelligence + father.Intelligence + UnityEngine.Random.Range(-1f, 2f)); newChild.Agility = (int)(mother.Agility + father.Agility + UnityEngine.Random.Range(-1f, 2f)); newBrain.Initialize(childBrain); } else { newChild.Strength = (int)(UnityEngine.Random.Range(LowStrength, HighStrength) + 0.5f); newChild.Agility = (int)(UnityEngine.Random.Range(LowAgility, HighAgility) + 0.5f); newChild.Intelligence = (int)(UnityEngine.Random.Range(LowIntelligence, HighIntelligence) + 0.5f); } }
public GeneticMaterial GenerateInitialMaterial() { List <Codon> codons = new List <Codon>(); // generate codons randomly at first for (int i = 0; i < NUM_CODONS; i++) { codons.Add(GetRandomCodon()); } GeneticMaterial gm = new GeneticMaterial(codons); return(gm); }
public void Initialise(GeneticMaterial genetics) { this.genetics = genetics; this.uid = "Unit " + Random.Range(0, 9999); this.gender = (Gender)Random.Range(0, 2); this.unitType = UnitType.None; // temporary this.maxHealth = genetics.health; this.currentHealth = maxHealth; this.attackDamage = genetics.strength; this.attackCooldown = 15f / (float)genetics.speed; this.nextAttackCounter = 0f; this.movementDelay = 10f / (float)genetics.speed; this.fleeHealth = (int)((float)maxHealth * genetics.fleeThreshold); }
public override bool Equals(object obj) { TaskSchedulingSolution scheduling = (obj as TaskSchedulingSolution); IEnumerator enumThis = GeneticMaterial.GetEnumerator(); IEnumerator enumThat = scheduling.GeneticMaterial.GetEnumerator(); while (enumThis.MoveNext() && enumThat.MoveNext()) { if (!int.Equals(enumThis.Current, enumThat.Current)) { return(false); } } if (enumThis.MoveNext() == false && enumThat.MoveNext() == false) { return(true); } return(false); }
public GeneticMaterial Breed(Unit unit1, Unit unit2) { List <Codon> newCodons = new List <Codon> (); for (int i = 0; i < NUM_CODONS; i++) { if (Random.Range(0, 2) == 0) { newCodons.Add(MutateCodon(unit1.genetics.codons [i].code)); } else { newCodons.Add(MutateCodon(unit1.genetics.codons [i].code)); } } GeneticMaterial gm = new GeneticMaterial(newCodons); Debug.Log("Health: " + gm.health + "\n" + "Strength: " + gm.strength + "\n" + "Speed: " + gm.speed + "\n" + "Technique: " + gm.technique); return(gm); }