Beispiel #1
0
    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);
    }
Beispiel #2
0
 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);
 }
Beispiel #3
0
 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);
 }
Beispiel #4
0
    /*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);
    }