Esempio n. 1
0
    public void obsTargets(VectorSensor sensor)
    {
        //obs stats about selected ones
        sensor.AddOneHotObservation(targetSelector, numTargets);

        Vector3 tarPos = m_TargetArea.TargetsList[targetSelector].transform.localPosition;

        sensor.AddObservation(normalizer(Vector3.Distance(transform.localPosition, tarPos), 0, hypotenuse));
        sensor.AddObservation(normalizer(Vector3.Angle(transform.localPosition, tarPos), 0, 360));
        sensor.AddObservation(m_TargetArea.TargetsList[targetSelector].GetComponent <ObjectLogic>().targetSearched);


        foreach (GameObject tar in m_TargetArea.TargetsList)
        {
            //obs targetID
            sensor.AddOneHotObservation(tar.GetComponent <ObjectLogic>().targetID, numTargets);

            //obs distance
            sensor.AddObservation(normalizer(Vector3.Distance(transform.localPosition, tar.transform.localPosition), 0, hypotenuse));

            //obs angle
            sensor.AddObservation(normalizer(Vector3.Angle(transform.localPosition, tar.transform.localPosition), 0, 360));

            //obs stat
            bool status = tar.GetComponent <ObjectLogic>().targetSearched;
            sensor.AddObservation(status);
        }
    }
 public override void CollectObservations(VectorSensor sensor)
 {
     foreach (var field in board.Fields)
     {
         sensor.AddOneHotObservation(field.ObserveField(type), 3);
     }
 }
Esempio n. 3
0
    public override void CollectObservations(VectorSensor sensor)
    {
        sensor.AddOneHotObservation((int)moveDir, 4);
        sensor.AddOneHotObservation((int)currentPosFieldType, 4);

        sensor.AddObservation(transform.position);
        sensor.AddObservation(worldArea.Ghosts[0].transform.position);
        sensor.AddObservation(Vector3.Distance(worldArea.Ghosts[0].transform.position, transform.position));
        sensor.AddObservation(worldArea.Ghosts[0].moveDirection);
        sensor.AddObservation(worldArea.Ghosts[1].transform.position);
        sensor.AddObservation(Vector3.Distance(worldArea.Ghosts[1].transform.position, transform.position));
        sensor.AddObservation(worldArea.Ghosts[1].moveDirection);
        sensor.AddObservation(m_ResetParams.GetWithDefault("percent_needed", 0.5f) - 1.0f * worldArea.fieldsOwned / worldArea.numberOfFields);
        sensor.AddObservation(isDrawing);
        sensor.AddObservation(isPathInfected);
    }
Esempio n. 4
0
        public void TestAddObservationOneHot()
        {
            var sensor = new VectorSensor(4);

            sensor.AddOneHotObservation(2, 4);
            SensorTestHelper.CompareObservation(sensor, new[] { 0f, 0f, 1f, 0f });
        }
Esempio n. 5
0
    public override void CollectObservations(VectorSensor sensor)
    {
        // Current Mana (1 observation)
        sensor.AddObservation(_mana);

        // current cards + cards mana (18 observations)
        for (int i = 0; i < _monstersAvailable.Length; i++)
        {
            sensor.AddOneHotObservation(((int)_monstersAvailable[i]), 5);
            sensor.AddObservation(_monstersSTS[_monstersAvailable[i]].Value);
        }

        // lifes remaining (2 observations)
        if (_type == AgentType.PLAYER)
        {
            sensor.AddObservation(_battleGameArea._playerLifes);
            sensor.AddObservation(_battleGameArea._enemyLifes);
        }
        else
        {
            sensor.AddObservation(_battleGameArea._enemyLifes);
            sensor.AddObservation(_battleGameArea._playerLifes);
        }

        // Direction (2 observations)
        sensor.AddObservation(Mathf.Abs(_directionArrow.transform.localRotation.z) > 0.1f);
        sensor.AddObservation(_battleGameArea.getOppositeArrowsDirection(_type));

        // Get Units (40 units * (2 x, z + (1 type * 5 posibilities))) = 280)
        float[,] units = _battleGameArea.getUnits(_type, transform.localPosition);
        for (int i = 0; i < _battleGameArea.MAX_NUM_UNITS; i++)
        {
            sensor.AddOneHotObservation((int)units[i, 0], 5);
            sensor.AddObservation(units[i, 1]);
            sensor.AddObservation(units[i, 2]);
        }
        units = _battleGameArea.getUnits(_type == AgentType.PLAYER ? AgentType.ENEMY : AgentType.PLAYER, transform.localPosition);
        for (int i = 0; i < _battleGameArea.MAX_NUM_UNITS; i++)
        {
            sensor.AddOneHotObservation((int)units[i, 0], 5);
            sensor.AddObservation(units[i, 1]);
            sensor.AddObservation(units[i, 2]);
        }

        // Total 303 observations
    }
Esempio n. 6
0
 public void obsZones(VectorSensor sensor)
 {
     //observe all agent's zones
     foreach (int zone in getAgentZones(sensor))
     {
         sensor.AddOneHotObservation(zone, 4);
     }
 }
Esempio n. 7
0
    public override void CollectObservations(VectorSensor sensor)
    {
        for (int y = 0; y < HEIGHT; y++)
        {
            for (int x = 0; x < WIDTH; x++)
            {
                int cellValue = board[y, x];
                sensor.AddOneHotObservation(NormalizeValue(cellValue), 15);
            }
        }

        sensor.AddOneHotObservation(NormalizeValue(nextValues[0]), 15);
        if (nextValues.Count > 1)
        {
            sensor.AddOneHotObservation(NormalizeValue(nextValues[1]), 15);
            if (nextValues.Count > 2)
            {
                sensor.AddOneHotObservation(NormalizeValue(nextValues[2]), 15);
            }
            else
            {
                sensor.AddOneHotObservation(NormalizeValue(nextValues[1]), 15);
            }
        }
        else
        {
            sensor.AddOneHotObservation(NormalizeValue(nextValues[0]), 15);
            sensor.AddOneHotObservation(NormalizeValue(nextValues[0]), 15);
        }
    }
Esempio n. 8
0
    //Método llamado antes de recibir la acción donde se pasa información del entorno a través de observaciones al agente
    public override void CollectObservations(VectorSensor sensor)
    {
        //Si obervaciones solo vecinos

        /*
         * List<Material> lista = new List<Material>();
         * lista.Add(actualmaterial);
         * lista.Add(cubeForward);
         * lista.Add(cubeForwardRight);
         * lista.Add(cubeRight);
         * lista.Add(cubeBackRight);
         * lista.Add(cubeBack);
         * lista.Add(cubeBackLeft);
         * lista.Add(cubeLeft);
         * lista.Add(cubeForwardLeft);
         * List<float> listanum = new List<float>();
         * foreach (Material material in lista)
         * {
         *  if (material == dead)
         *  {
         *      //AddVectorObs(0);
         *      listanum.Add(0);
         *  }
         *  else if (material == black)
         *  {
         *      //AddVectorObs(1);
         *      listanum.Add(1);
         *  }
         *  else if (material == green)
         *  {
         *      //AddVectorObs(2);
         *      listanum.Add(2);
         *  }
         *  else if (material == red)
         *  {
         *      //AddVectorObs(3);
         *      listanum.Add(3);
         *  }
         *  else
         *  {
         *      //AddVectorObs(4);
         *      listanum.Add(4);
         *  }
         * }
         * foreach (int num in listanum)
         * {
         *  sensor.AddOneHotObservation(num,4);
         * }
         */

        //Si obervaciones malla entera
        foreach (int cubo in histograma.getListaCompleto())
        {
            sensor.AddOneHotObservation(cubo, 4);
        }
    }
Esempio n. 9
0
 public override void CollectObservations(VectorSensor sensor)
 {
     base.CollectObservations(sensor);
     // observe board state
     for (int i = 0; i < 7; i++)
     {
         for (int j = 0; j < 6; j++)
         {
             int value = _gameController.GetValueAt(i, j);
             sensor.AddOneHotObservation(observation: value, range: 3);
         }
     }
 }
Esempio n. 10
0
    public void obsAgents(VectorSensor sensor)
    {
        foreach (GameObject agent in m_TargetArea.AgentsList)
        {
            if (agent.GetComponent <AgentBrain>().agentTag != agentTag)
            {
                int otherAgentTargetSelector = agent.GetComponent <AgentBrain>().targetSelector;
                sensor.AddOneHotObservation(otherAgentTargetSelector, numTargets);

                int targetChopeBy = m_TargetArea.TargetsList[otherAgentTargetSelector].GetComponent <ObjectLogic>().selectedBy;

                if (otherAgentTargetSelector != this.targetSelector && targetChopeBy == agentTag)
                {
                    AddReward(0.00005f);
                }
            }
        }
    }
Esempio n. 11
0
    public override void CollectObservations(VectorSensor sensor)
    {
        // sensor.AddObservation(m_EmotionTargets);
        sensor.AddOneHotObservation(Index, IndexRange);
        sensor.AddObservation(Mathf.Abs(m_InitialPosition.x));
        sensor.AddObservation(m_InitialPosition.y);
        sensor.AddObservation(m_InitialPosition.z);

        sensor.AddObservation(transform.localPosition.x * 40f);
        sensor.AddObservation(transform.localPosition.y * 40f);
        sensor.AddObservation(transform.localPosition.z * 40f);

        // TODO: Add more emotion detection stuff
        sensor.AddObservation(m_EmotionReceiver.Happy);
        sensor.AddObservation(m_EmotionReceiver.Sad);
        sensor.AddObservation(m_EmotionReceiver.Angry);
        sensor.AddObservation(m_EmotionReceiver.Disgusted);
        sensor.AddObservation(m_EmotionReceiver.Fearful);
        sensor.AddObservation(m_EmotionReceiver.Neutral);
        sensor.AddObservation(m_EmotionReceiver.Surprised);
        sensor.AddObservation(m_EmotionReceiver.Contempt);
    }
Esempio n. 12
0
    public override void CollectObservations(VectorSensor sensor)
    {
        float   distance      = Vector3.Distance(transform.position, pandemicAreaObj.GetComponent <PandemicArea>().rewardCube.transform.position);
        Vector3 direction     = transform.position - pandemicAreaObj.GetComponent <PandemicArea>().rewardCube.transform.position;
        var     localVelocity = transform.InverseTransformDirection(rb.velocity);

        //sensor.AddObservation(starvingLevel/100); // Dividing with 100 for normalization
        sensor.AddObservation(localVelocity.x);
        sensor.AddObservation(localVelocity.z);
        sensor.AddOneHotObservation((int)m_InfectionStatus, NUM_ITEM_TYPES); //A shortcut for one-hot-style observations.

        //Observations for getting reward easily
        //sensor.AddObservation(distance);
        //sensor.AddObservation(direction.normalized);

        //Infection sayısının healthy saysına oranı vs verilebilir but not yet.
        //sensor.AddObservation(pandemicArea.infectedBotCount);

        //Agentların health status sayısı verilebilir
        //sensor.AddObservation(pandemicArea.healthyCounter);
        //sensor.AddObservation(pandemicArea.infectedCounter);
        //sensor.AddObservation(pandemicArea.recoveredCounter);
    }
 public override void CollectObservations(VectorSensor sensor)
 {
     sensor.AddOneHotObservation(keyController.currentNumberOfKeys, 6);
     sensor.AddObservation(episodeTime);
     sensor.AddObservation(floorBuilder.floorNumber);
 }
Esempio n. 14
0
    // // // Update is called once per frame
    // void FixedUpdate() //it doesnt seem possible to pull in data from the sensor components. specifically the raycast. unity may fix later
    // {

    //     using(var writer = new StreamWriter(filename, append: true))
    //     {
    //         // SensorComponent[] sensors = GetComponents<SensorComponent>();
    //         // RayPerceptionSensor sensor = gameObject.GetComponent<RayPerceptionSensor>();
    //         string AllSensorsObs = null;
    //         // foreach (var component in Sensorlist)
    //         // {

    //         float[] rowarray = sensor.M_Observations_get.Cast<float>().ToArray(); // cast it as an array of ints
    //         string sensor_string = string.Join(",", rowarray); //convert array to string separated by commas
    //         AllSensorsObs += "," + sensor_string;

    //         // }
    //         writer.WriteLine(AllSensorsObs);  //write each line to csv
    //     }
    // }


    public override void CollectObservations(VectorSensor sensor)
    {
        sensor.AddObservation(transform.forward);
        sensor.AddOneHotObservation((int)item_carried, 3);
        sensor.AddOneHotObservation(ID, 6);
    }
    // // Update is called once per frame
    // void FixedUpdate() //it doesnt seem possible to pull in data from the sensor components. specifically the raycast. unity may fix later
    // {
    //     // if (Academy.Instance.StepCount % 10 == 0)
    //     // {
    //     //     mode_freqs[item_carried + 1] = mode_freqs[item_carried + 1] + 1;

    //     //     // Debug.Log(string.Join(",", mode_freqs));
    //     // }

    //     // if (Academy.Instance.StepCount % maxStep == 0) //(Academy.Instance.EpisodeCount == nextEpisodeID)
    //     // {
    //     //     Debug.Log("Writing to CSV: " + string.Join(",", mode_freqs));
    //     //     WriteArrayToCSV(mode_freqs, filename);

    //     //     // Debug.Log("episodecount: " + Academy.Instance.EpisodeCount.ToString() + " nextID:" + nextEpisodeID.ToString()); // THe episodecount doenst appear to increase?
    //     //     // nextEpisodeID +=1;
    //     // }
    // }

    public override void CollectObservations(VectorSensor sensor)
    {
        sensor.AddObservation(transform.forward);
        sensor.AddOneHotObservation((int)item_carried, 3);
        sensor.AddOneHotObservation(ID, 6); //"ID" can be changed to a specific value e.g 1 to force all agents to act like agent 1.
    }
Esempio n. 16
0
    // // Update is called once per frame
    // void FixedUpdate() //it doesnt seem possible to pull in data from the sensor components. specifically the raycast. unity may fix later
    // {
    //     // if (Academy.Instance.StepCount % 10 == 0)
    //     // {
    //     //     mode_freqs[item_carried + 1] = mode_freqs[item_carried + 1] + 1;

    //     //     // Debug.Log(string.Join(",", mode_freqs));
    //     // }

    //     // if (Academy.Instance.StepCount % maxStep == 0) //(Academy.Instance.EpisodeCount == nextEpisodeID)
    //     // {
    //     //     Debug.Log("Writing to CSV: " + string.Join(",", mode_freqs));
    //     //     WriteArrayToCSV(mode_freqs, filename);

    //     //     // Debug.Log("episodecount: " + Academy.Instance.EpisodeCount.ToString() + " nextID:" + nextEpisodeID.ToString()); // THe episodecount doenst appear to increase?
    //     //     // nextEpisodeID +=1;
    //     // }
    // }

    public override void CollectObservations(VectorSensor sensor)
    {
        sensor.AddObservation(transform.forward);
        sensor.AddOneHotObservation((int)item_carried, 3);
        sensor.AddOneHotObservation(1, 6); //use (ID, 6) to include all agent types
    }
Esempio n. 17
0
        public override void CollectObservations(VectorSensor sensor)
        {
            //UnityEngine.Debug.Log(player.GetName() + "collectObservations");
            // NORMALIZE ALL OBSERVATIONS, BECAUSE TENSORFLOW CANNOT NORMALIZE PROPERLY!!!
            // Player Properties
            // Position information
            sensor.AddObservation((player.GetPosition().x - battleArena.GetPosition().x) / BattleArena.WIDTH);
            sensor.AddObservation((player.GetPosition().z - battleArena.GetPosition().z) / BattleArena.HEIGHT);

            // Health information
            sensor.AddObservation(player.GetHealth() / PlayerProperties.MAX_HEALTH);

            // Health potion count
            sensor.AddObservation(player.GetHealthPotionCount() / PlayerProperties.MAX_HEALTH_POTION);

            // Mana information
            sensor.AddObservation(player.GetMana() / PlayerProperties.MAX_MANA);

            // Mana potion count
            sensor.AddObservation(player.GetManaPotionCount() / PlayerProperties.MAX_MANA_POTION);

            // Speed information
            sensor.AddObservation(player.GetSpeed() / PlayerProperties.MAX_SPEED);

            // Defense information
            sensor.AddObservation(player.GetDefense() / PlayerProperties.MAX_DEFENSE);

            // Damage information
            sensor.AddObservation(player.GetDamage() / PlayerProperties.MAX_DAMAGE);

            // Attack range information
            sensor.AddObservation(player.GetAttackRange() / PlayerProperties.MAX_ATTACK_RANGE);

            // Stun information
            sensor.AddObservation(player.IsStunned());

            // Attack usage information
            sensor.AddObservation(player.IsAttacking());

            // Skill information
            IAttackSkill attackSkill;
            IBuffSkill   buffSkill;
            IBuffSkill   debuffSkill;

            foreach (ISkill skill in player.GetSkills())
            {
                sensor.AddObservation(skill.IsAvailable());
                sensor.AddOneHotObservation((int)skill.GetSkillKind(), 3);
                sensor.AddObservation(skill.GetManaConsumption() / SkillProperties.MAX_MANA_CONSUMPTION);
                sensor.AddObservation(skill.GetTimeout() / SkillProperties.MAX_TIMEOUT);

                // attack and buff skill observations should be equal to preserve total observation count
                // observation for attack skill
                if (skill.GetSkillKind() == SkillKind.ATTACK)
                {
                    attackSkill = (IAttackSkill)skill;
                    debuffSkill = attackSkill.GetDebuff();
                    sensor.AddObservation(attackSkill.GetDamage() / SkillProperties.MAX_DAMAGE);
                    sensor.AddObservation(attackSkill.GetRange() / SkillProperties.MAX_RANGE);
                    sensor.AddObservation(attackSkill.HasDebuff());
                    sensor.AddObservation(attackSkill.GetDebuffPercentage() / SkillProperties.MAX_DEBUFF_PERCENTAGE);
                    sensor.AddOneHotObservation(debuffSkill != null ? (int)debuffSkill.GetBuffKind() : -1, BuffKindExtensions.Count);
                }
                // observation for buff skill, added one dummy observation to be equal to attack skill observations
                else
                {
                    buffSkill = (IBuffSkill)skill;
                    sensor.AddObservation(buffSkill.GetDuration() / SkillProperties.MAX_DURATION);
                    sensor.AddObservation(buffSkill.GetAmount() / SkillProperties.MAX_AMOUNT);
                    sensor.AddOneHotObservation((int)buffSkill.GetBuffKind(), BuffKindExtensions.Count);
                    sensor.AddObservation(buffSkill.IsPeriodic());
                    sensor.AddObservation(0);
                }
            }

            // Distance between enemy
            sensor.AddObservation(Utils.GetDistance(player, enemy) / BattleArena.MAX_DISTANCE);

            // Enemy properties
            // Position information
            sensor.AddObservation((enemy.GetPosition().x - battleArena.GetPosition().x) / BattleArena.WIDTH);
            sensor.AddObservation((enemy.GetPosition().z - battleArena.GetPosition().z) / BattleArena.HEIGHT);

            // debuff information
            // maximum three debuff information
            IList <IBuffSkill> debuffs = enemy.GetAppliedDebuffs();

            for (int i = 0; i < 3; i++)
            {
                sensor.AddOneHotObservation(i < debuffs.Count ? (int)debuffs[i].GetBuffKind() : -1, BuffKindExtensions.Count);
            }
        }
Esempio n. 18
0
 public override void CollectObservations(VectorSensor sensor)
 {
     sensor.AddOneHotObservation(m_Position, 20);
 }
Esempio n. 19
0
    public override void CollectObservations(VectorSensor sensor)
    {
        int rewadType = (int)trainAgentSetting.rewadType;

        sensor.AddOneHotObservation(rewadType, 1);
    }