public override void Activate(SharpNeat.Phenomes.IBlackBox box, GameObject target) { this.brain = box; this.brain.ResetState(); this.Target = target; this.IsRunning = true; }
/// <summary> /// Called by SimpleEvaluator and NeatManualEvaluator. /// Instantiates and activates a unit. Adds its controller (box parameter) /// to the dictionary ControllerMap. /// </summary> public override void InstantiateCandidate(SharpNeat.Phenomes.IBlackBox box) { GameObject obj = Instantiate(Unit, Unit.transform.position, Unit.transform.rotation) as GameObject; UnitController controller = obj.GetComponent <UnitController>(); ControllerMap.Add(box, controller); controller.Activate(box); }
/// <summary> /// Gets the fitness corresponding to the unit which uses the controller "box" /// </summary> public override float GetFitness(SharpNeat.Phenomes.IBlackBox box) { if (ControllerMap.ContainsKey(box)) { // This is the function written by the user in the derived class from the // abstract UnitController script! return(ControllerMap[box].GetFitness()); } return(0); }
/// <summary> /// Waits for the trial duration and then asks for a fitness evaluation. /// Used mainly for research. /// </summary> public IEnumerator EvaluateChamp(SharpNeat.Phenomes.IBlackBox brain) { while (champRunning) { yield return(new WaitForSeconds(base.TrialDuration)); float fit = GetFitness(brain); Debug.Log("Fitness evaluation returns: " + fit + "\n"); } }
/// <summary> /// Destroys the units created by "Run Best" /// </summary> public void DestroyBest() { champRunning = false; GameObject[] bests; bests = GameObject.FindGameObjectsWithTag("BestUnit"); foreach (GameObject best in bests) { SharpNeat.Phenomes.IBlackBox box = best.GetComponent <UnitController>().GetBox(); if (ControllerMap.ContainsKey(box)) { ControllerMap.Remove(box); } // We destroy the unit Destroy(best); } }
/// <summary> /// Destroys the unit that uses a given controller (parameter box) /// </summary> public override void DestroyCandidate(SharpNeat.Phenomes.IBlackBox box) { UnitController ct = ControllerMap[box]; Destroy(ct.gameObject); }
public abstract void Activate(SharpNeat.Phenomes.IBlackBox box);