public static Player Create(EnvStats env, GameObject prefab, Vector3 pos, Vector3 forward, OrgStats stats) { GameObject p = Instantiate(prefab, pos, Quaternion.LookRotation( forward )); Player playa = p.GetComponent <Player>(); playa.Init(stats, env); return(playa); }
public void Init(OrgStats stats, EnvStats envStats) { speed = stats.speed; range = stats.range; angle = stats.angle; rSpeed = stats.rSpeed; moveSpeed = speed; rotSpeed = rSpeed; this.envStats = envStats; score = 0; if (radar == null) { Debug.LogError("Radar is Null"); } radar.SetValues(range, angle); }
void Start() { foodSet = new HashSet <GameObject>(); agents = new List <Player>(); stats = new EnvStats(); stats.initialCount = initCount; stats.foodCount = initCount; stats.popCount = population; SpawnFood(); SpawnFirstPopulation(); outPath = Application.dataPath + outPath; writer = File.AppendText(outPath); }
/*IEnumerator*/ private void newGeneration() { //Sort agents by score agents.Sort(new AgentComparer()); //Write data of each generation line by line for (int i = 0; i < agents.Count; ++i) { string line = gen + " " + agents[i].Score() + " " + stats.initialCount + " "; float[] gene = agents[i].Stats().Gene(); for (int j = 0; j < gene.Length; ++j) { line = line + gene[j].ToString("0.00") + " "; } writer.WriteLine(line); } //Generate a new population List <OrgStats> children = GetNewStats(agents); foreach (Player player in agents) { if (player != null) { player.End(); } } agents.Clear(); //Start Spawning foreach (GameObject f in foodSet) { if (f != null) { Destroy(f); } } foodSet.Clear(); stats = new EnvStats(); stats.initialCount = initCount; stats.foodCount = initCount; stats.popCount = population; SpawnFood(); SpawnGeneratedPopulation(children); ++gen; //yield return new WaitForSecondsRealtime(2); }