Exemplo n.º 1
0
 public virtual void OnCollisionEnter(Collision collision)
 {
     if (collision.gameObject.CompareTag("agent"))
     {
         TrainingAgent agentScript = collision.gameObject.GetComponent <TrainingAgent>();
         // Debug.Break();
         if (!isMulti)
         {
             agentScript.AgentDeath(reward);
         }
         else
         {
             agentScript.numberOfGoalsCollected++;
             if (agentScript.numberOfGoalsCollected == numberOfGoals)
             {
                 agentScript.AgentDeath(reward);
             }
             else
             {
                 agentScript.AddReward(reward);
             }
             gameObject.SetActive(false);
             Object.Destroy(gameObject);
         }
     }
 }
Exemplo n.º 2
0
    void Start()
    {
        _agent        = GameObject.FindGameObjectWithTag("agent").GetComponent <TrainingAgent>();
        _cameraAbove  = GameObject.FindGameObjectWithTag("MainCamera").GetComponent <Camera>();
        _cameraAgent  = _agent.transform.Find("AgentCamMid").GetComponent <Camera>();
        _cameraFollow = GameObject.FindGameObjectWithTag("camBase").GetComponent <Camera>();
        _score        = GameObject.FindObjectOfType <Text>();

        _cameraAbove.enabled  = true;
        _cameraAgent.enabled  = false;
        _cameraFollow.enabled = false;

        _cameras = new Dictionary <int, Camera>();
        _cameras.Add(0, _cameraAbove);
        _cameras.Add(1, _cameraAgent);
        _cameras.Add(2, _cameraFollow);
        _numActive = 0;
    }
Exemplo n.º 3
0
 public virtual void OnCollisionEnter(Collision collision)
 {
     if (collision.gameObject.CompareTag("agent"))
     {
         if (!isMulti)
         {
             collision.gameObject.GetComponent <TrainingAgent>().AgentDeath(reward);
         }
         else
         {
             TrainingAgent agentScript = collision.gameObject.GetComponent <TrainingAgent>();
             agentScript.numberOfGoalsCollected++;
             if (agentScript.numberOfGoalsCollected == numberOfGoals)
             {
                 agentScript.AgentDeath(reward);
             }
             else
             {
                 agentScript.AddReward(reward);
             }
             Object.Destroy(this.gameObject);
         }
     }
 }
Exemplo n.º 4
0
    // Use this for initialization
    void Start()
    {
        gameMap = GetComponent<GameMap>();

        SpawnPoints = new List<Vector2>(gameMap.map.HumanSpawnPoints);
        //
        //		//gameMap.spawnHumanImmediate(gameMap.map.getRandomHumanSpawn(), gameMap.Human.transform.rotation);
        //		gameMap.spawnHumanImmediate(gameMap.map.HumanSpawnPoints[currTarget], gameMap.Human.transform.rotation);
        //
        //		testSubject = gameMap.HumansOnMap[0].GetComponent<TestableAgent>();

        if(Options.populationName == null){

            Type genome = typeof(FiveLongFeelerGenome);
            populationSize = 50;

            population = new Genome[populationSize];

            for (int currGenome = 0; currGenome < populationSize; ++currGenome) {

                population[currGenome] = Genome.createGenome(genome);
            }

            generation = 0;
        }
        else  {

            string fileName = Options.GADirectory +"/" +Options.populationName+".txt";

            Debug.Log ("Loading Population from file "+fileName +".");

            loadPopulationFromString(File.ReadAllText(fileName));
        }

        //gameMap.spawnHumanImmediate(gameMap.map.getRandomHumanSpawn(), gameMap.Human.transform.rotation);
        gameMap.spawnHumanImmediate(gameMap.map.HumanSpawnPoints[currTarget], gameMap.Human.transform.rotation, population[0]);

        testSubject = gameMap.HumansOnMap[0].GetComponent<TrainingAgent>();

        initialize();
    }
 private void Awake()
 {
     TeamController = GetComponent <TeamController>();
     TrainingAgent  = GetComponent <TrainingAgent>();
 }