public void RunBest() { Time.timeScale = 1; Time.fixedDeltaTime = 0.02f; NeatGenome genome = null; // Try to load the genome from the XML document. try { using (XmlReader xr = XmlReader.Create(champFileLoadPath)) genome = NeatGenomeXmlIO.ReadCompleteGenomeList(xr, false, (NeatGenomeFactory)experiment.CreateGenomeFactory())[0]; } catch (Exception e1) { // print(champFileLoadPath + " Error loading genome from file!\nLoading aborted.\n" // + e1.Message + "\nJoe: " + champFileLoadPath); return; } // Get a genome decoder that can convert genomes to phenomes. var genomeDecoder = experiment.CreateGenomeDecoder(); // Decode the genome into a phenome (neural network). var phenome = genomeDecoder.Decode(genome); // Reset(); Vector3 dir = new Vector3(UnityEngine.Random.Range(-1f, 1f), 0, UnityEngine.Random.Range(-1f, 1f)); Vector3 pos = dir.normalized * 20; pos.y = 1; GameObject obj = Instantiate(HammerRobot, pos, Quaternion.identity) as GameObject; FightController robo = obj.GetComponent <FightController>(); // robo.RunBestOnly = true; if (Settings.Brain.MultipleTargets) { GameObject t = Instantiate(Target, new Vector3(0, 1, 0), Quaternion.identity) as GameObject; t.transform.localScale = new Vector3(1, 1, 1); TargetController tc = t.AddComponent <TargetController>(); tc.Activate(obj.transform); bestTargetDict.Add(robo, tc); robo.Activate(phenome, t); } else { Target.GetComponent <TargetController>().Activate(); robo.Activate(phenome, Target); } BestRunners.Add(robo); }
void Initialize() { // Camera.main.GetComponent<MousePan>().Activated = true; Slot1.ActivatePanel(); activePanel = Slot1; if (Slot1.InUse) { Slot1.GetPanel().Click += new MouseEventHandler((control, mouseEvent) => SlotClick(control, mouseEvent, 1)); } if (Slot2.InUse) { Slot2.GetPanel().Click += new MouseEventHandler((control, mouseEvent) => SlotClick(control, mouseEvent, 2)); } if (Slot3.InUse) { Slot3.GetPanel().Click += new MouseEventHandler((control, mouseEvent) => SlotClick(control, mouseEvent, 3)); } if (Slot4.InUse) { Slot4.GetPanel().Click += new MouseEventHandler((control, mouseEvent) => SlotClick(control, mouseEvent, 4)); } IBlackBox brain1 = null, brain2 = null, brain3 = null, brain4 = null, activeBrain = null; string path = ""; if (Player.Brain1 != null) { path = Application.persistentDataPath + string.Format("/{0}/{1}.champ.xml", Player.Username, Player.Brain1.ObjectId); // print("Path: " + path); brain1 = Utility.LoadBrain(path); activeBrain = brain1; } if (Player.Brain2 != null) { path = Application.persistentDataPath + string.Format("/{0}/{1}.champ.xml", Player.Username, Player.Brain2.ObjectId); brain2 = Utility.LoadBrain(path); if (activeBrain == null) { activeBrain = brain2; } } if (Player.Brain3 != null) { path = Application.persistentDataPath + string.Format("/{0}/{1}.champ.xml", Player.Username, Player.Brain3.ObjectId); brain3 = Utility.LoadBrain(path); if (activeBrain == null) { activeBrain = brain3; } } if (Player.Brain4 != null) { path = Application.persistentDataPath + string.Format("/{0}/{1}.champ.xml", Player.Username, Player.Brain4.ObjectId); brain4 = Utility.LoadBrain(path); if (activeBrain == null) { activeBrain = brain4; } } Controller.Activate(activeBrain, Target); Controller.SetBrains(brain1, brain2, brain3, brain4); // print("Current mission: " + PlayerPrefs.GetInt(MissionPanel.CURRENT_MISSION, 1)); string arena = ""; switch (PlayerPrefs.GetInt(MissionPanel.CURRENT_MISSION, 1)) { case 1: arena = "Mission 1"; Mission1.Initialize(this); break; case 2: arena = "Mission 2"; Mission2.Initialize(this); break; case 3: arena = "Mission 3"; Mission3.Initialize(this); break; case 4: arena = "Mission 4"; Mission4.Initialize(this); break; case 5: arena = "Mission 5"; Mission5.Initialize(this); break; } logger = new EventLogger(Controller, arena); logger.StartLogging(); }