void Update() { UpdateVisuals(); if (Money > 255) Money = 255; if (Happiness > 255) Happiness = 255; if (Boredom > 255) Boredom = 255; if (Money < 0) Money = 0; if (Happiness < 0) Happiness = 0; if (Boredom < 0) Boredom = 0; DiseaseResults(); if (updateCount <= 0) { XCS.UpdateRules(CalcBenefit(), learnRate); currentAction = XCS.BestAction(CalcState()); lastActions.Add(currentAction); lastActions.RemoveAt(0); updateCount = BehaviourUpdateTime; } //if (Time.frameCount % BreedingTime == 0 && Random.value > FindObjectsOfType<HumanAI>().Count() / (float)maxHumans) // TryBreed(); //++age; DoAction(currentAction); //if (age > 50000 * CalcFitness()) //{ // if (currentLocation != null) // currentLocation.Leave(this); // GameObject.Destroy(gameObject); //} }
public new void EnableBehaviour(bool value) { base.EnableBehaviour(value); if (value) { // Transitions var foodAround = new Transition("FoodAround", 0, FoodAround); var isCloseEnoughForEating = new Transition("IsCloseEnoughForEating", 0, IsCloseEnoughForEating); var waterAround = new Transition("WaterAround", -1, WaterAround); var isCloseEnoughForDrinking = new Transition("IsCloseEnoughForDrinking", -1, IsCloseEnoughForDrinking); var partnerAround = new Transition("PartnerAround", -2, PartnerAround); var isCloseEnoughForBreeding = new Transition("IsCloseEnoughForBreeding", -1, IsCloseEnoughForBreeding); var isTargetAlive = new Transition("IsTargetAlive", 0, IsTargetAlive); var timeout = new Transition("Timeout", -1, Timeout); // Actions var randomMovement = new Action("RandomMovement", RandomMovement); var reachFood = new Action("ReachFood", Reach); var reachWater = new Action("ReachWater", Reach); var reachPartner = new Action("ReachPartner", Reach); var eat = new Action("Eat", Eat); var drink = new Action("Drink", Drink); var reproduce = new Action("Reproduce", Reproduce); var n = "Wander"; Memes[n] = new Meme(n, new List <Action> { randomMovement }, new List <Transition> { foodAround, waterAround, partnerAround }, Color.white); n = "ReachFood"; Memes[n] = new Meme(n, new List <Action> { reachFood }, new List <Transition> { isCloseEnoughForEating }, Color.red); n = "ReachWater"; Memes[n] = new Meme(n, new List <Action> { reachWater }, new List <Transition> { isCloseEnoughForDrinking }, Color.red); n = "ReachPartner"; Memes[n] = new Meme(n, new List <Action> { reachPartner }, new List <Transition> { isCloseEnoughForBreeding }, Color.red); n = "Eat"; Memes[n] = new Meme(n, new List <Action> { eat }, new List <Transition> { isTargetAlive, partnerAround, waterAround }, Color.blue); n = "Drink"; Memes[n] = new Meme(n, new List <Action> { drink }, new List <Transition> { partnerAround }, Color.blue); n = "Breed"; Memes[n] = new Meme(n, new List <Action> { reproduce }, new List <Transition> { foodAround, waterAround, partnerAround }, Color.magenta); controller.SetupAi(Memes["Wander"], 100 / characteristics.Computation); } }