public void Kill()
    {
        children.Clear();
        brain = null;
        map.RemoveCreatureFromTileList(tileDetail[0], tileDetail[1], this);
        map = null;

        world.RemoveCreature(this);
        GameObject.Destroy(trans.gameObject);
    }
    public Creature_V2(int ID, int generation, Transform trans, LineRenderer leftLine, LineRenderer rightLine, LineRenderer[] sensorLine, LineRenderer spikeLine,
                       Brain_V2 brain, HSBColor bodyColor, Vector3 bodyPos, Vector3 leftPos, Vector3 rightPos, float sensorSize,
                       float angle, float worldDeltaTime, float initialRadius, float initialEnergy, float currentEnergy, float life, float minLife, float lifeDecerase, float eatDamage, float veloDamage, float angDamage, float fightDamage, float veloForward, float veloAngular,
                       TileMap_V2 map, WolrdManager_V2 world, String parentNames)
        : base(initialRadius, bodyPos, angle, veloForward, veloAngular, 1f, worldDeltaTime)
    {
        this.ID         = ID;
        this.generation = generation;
        this.trans      = trans;

        this.leftLine   = leftLine;
        this.rightLine  = rightLine;
        this.sensorLine = sensorLine;
        this.spikeLine  = spikeLine;

        this.brain          = brain;
        this.bodyColor      = bodyColor;
        this.leftPos        = leftPos;
        this.rightPos       = rightPos;
        this.sensorSize     = sensorSize;
        this.worldDeltaTime = worldDeltaTime;
        this.initialRadius  = initialRadius;
        this.map            = map;
        this.world          = world;
        this.parentNames    = parentNames;

        this.textMesh   = trans.GetChild(1).GetComponent <TextMesh>();
        this.fightTrans = trans.GetChild(3);


        for (int i = 0; i < sensorPos.Length; i++)
        {
            sensorPos[i] = Vector3.zero;
        }

        this.spikeLength = 0f;
        this.spikePos    = Vector3.zero;

        this.children = new List <Creature_V2>();
        //energyDensity = 1f/(Mathf.PI * initialRadius * initialRadius);

        this.bodyMaterial  = trans.GetComponent <Renderer>().material;
        this.mouthMaterial = trans.GetChild(0).GetComponent <Renderer>().material;

        this.energy = new Energy(initialEnergy, map, worldDeltaTime, minLife, lifeDecerase, eatDamage, veloDamage, angDamage, fightDamage);
        this.energy.SetEnergy(currentEnergy);
        this.energy.SetLife(life);

        this.bodyColor  = new HSBColor(UnityEngine.Random.Range(0f, 1f), 1f, 1f);
        this.mouthColor = new HSBColor(UnityEngine.Random.Range(0f, 1f), 1f, 1f);

        this.creatureName = brain.GetName();
    }
    public Energy(float initialEnergy, TileMap_V2 map, float worldDeltaTime, float minLife, float lifeDecerase, float eatDamage, float veloDamage, float angDamage, float fightDamage)
    {
        this.initialEnergy  = initialEnergy;
        this.currentEnergy  = initialEnergy;
        this.map            = map;
        this.worldDeltaTime = worldDeltaTime;
        this.eatDamage      = eatDamage;
        this.veloDamage     = veloDamage;
        this.angDamage      = angDamage;
        this.fightDamage    = fightDamage;

        this.minLife      = minLife;
        this.lifeDecerase = lifeDecerase;
    }
Esempio n. 4
0
    public void SetTexture(Texture2D tex)
    {
        Application.runInBackground = this.runInBackground;

        string filename = "world_hyper_parameters.txt";

        if (!File.Exists(filename))
        {
            StreamWriter writer = new StreamWriter(filename);
            writer.WriteLine("neural_layers: 32");
            writer.WriteLine("min_creature_count: 60");
            writer.WriteLine("max_visual_speed: 11");
            writer.WriteLine("climate: 2.8");
            writer.WriteLine("min_life: 5.5");
            writer.WriteLine("life_decrease: 0.5");
            writer.WriteLine("eat_damage: 1");
            writer.WriteLine("velo_damage: 3");
            writer.WriteLine("ang_damage: 0.5");
            writer.WriteLine("fight_damage: 0.1");
            writer.WriteLine("@world_delta_time: 0.002");
            writer.WriteLine("@mutation_number: 1000");
            writer.WriteLine("@mutation_weaker_parent_factor: 1");
            writer.WriteLine("@mutation_sign: 1");
            writer.WriteLine("@mutation_random: 1");
            writer.WriteLine("@mutation_increase: 1");
            writer.WriteLine("@mutation_decrease: 1");
            writer.WriteLine("@seed_soil_fracture: 1");
            writer.WriteLine("@seed_soil_color: 0.5");
            writer.WriteLine("@seed_disp_water: 1425");
            writer.WriteLine("@seed_disp_soil: 134");
            writer.WriteLine("@seed_soil_power: 1.25");
            writer.WriteLine("@seed_disp_fertility: 8925");
            writer.WriteLine("@seed_soil_fertility: 5");
            writer.Write("@seed_soil_fertility_power: 0.3");
            writer.Close();
        }

        StreamReader reader = new StreamReader(filename);

        string[] neuralLayerLine                = reader.ReadLine().Split(' ');
        string[] minCreatureCountLine           = reader.ReadLine().Split(' ');
        string[] maxVisualSpeedLine             = reader.ReadLine().Split(' ');
        string[] climateLine                    = reader.ReadLine().Split(' ');
        string[] minLifeLine                    = reader.ReadLine().Split(' ');
        string[] lifeDecreaseLine               = reader.ReadLine().Split(' ');
        string[] eatDamageLine                  = reader.ReadLine().Split(' ');
        string[] veloDamageLine                 = reader.ReadLine().Split(' ');
        string[] angDamageLine                  = reader.ReadLine().Split(' ');
        string[] fightDamageLine                = reader.ReadLine().Split(' ');
        string[] worldDeltaTimeLine             = reader.ReadLine().Split(' ');
        string[] mutationNumberLine             = reader.ReadLine().Split(' ');
        string[] mutationWeakerParentFactorLine = reader.ReadLine().Split(' ');
        string[] mutationSignLine               = reader.ReadLine().Split(' ');
        string[] mutationRandomLine             = reader.ReadLine().Split(' ');
        string[] mutationIncreaseLine           = reader.ReadLine().Split(' ');
        string[] mutationDecreaseLine           = reader.ReadLine().Split(' ');
        string[] seedSoilFractureLine           = reader.ReadLine().Split(' ');
        string[] seedSoilColorLine              = reader.ReadLine().Split(' ');
        string[] seedWaterLine                  = reader.ReadLine().Split(' ');
        string[] seedSoilLine                   = reader.ReadLine().Split(' ');
        string[] seedSoilPowerLine              = reader.ReadLine().Split(' ');
        string[] seedFirtLine                   = reader.ReadLine().Split(' ');
        string[] seedSoilFirtLine               = reader.ReadLine().Split(' ');
        string[] seedSoilFirtPowerLine          = reader.ReadLine().Split(' ');

        //make brain network
        int layerLength = (neuralLayerLine.Length - 1);

        brainNetwork    = new int[layerLength + 2];
        brainNetwork[0] = inputNeurons;
        brainNetwork[brainNetwork.Length - 1] = outputNeurons;
        for (int i = 1; i < neuralLayerLine.Length; i++)
        {
            brainNetwork[i] = int.Parse(neuralLayerLine[i]);
        }

        minCreatureCount           = int.Parse(minCreatureCountLine[1]);
        playSpeedVisual            = int.Parse(maxVisualSpeedLine[1]);
        worldDeltaTime             = float.Parse(worldDeltaTimeLine[1]);
        climate                    = float.Parse(climateLine[1]);
        minLife                    = float.Parse(minLifeLine[1]);
        lifeDecrease               = float.Parse(lifeDecreaseLine[1]);
        eatDamage                  = float.Parse(eatDamageLine[1]);
        veloDamage                 = float.Parse(veloDamageLine[1]);
        angDamage                  = float.Parse(angDamageLine[1]);
        fightDamage                = float.Parse(fightDamageLine[1]);
        mutationNumber             = int.Parse(mutationNumberLine[1]);
        mutationWeakerParentFactor = int.Parse(mutationWeakerParentFactorLine[1]);
        mutationSign               = int.Parse(mutationSignLine[1]);
        mutationRandom             = int.Parse(mutationRandomLine[1]);
        mutationIncrease           = int.Parse(mutationIncreaseLine[1]);
        mutationDecrease           = int.Parse(mutationDecreaseLine[1]);
        seedSoilFracture           = float.Parse(seedSoilFractureLine[1]);
        seedSoilColor              = float.Parse(seedSoilColorLine[1]);
        seedWater                  = float.Parse(seedWaterLine[1]);
        seedSoil                   = float.Parse(seedSoilLine[1]);
        seedSoilPower              = float.Parse(seedSoilPowerLine[1]);
        seedFirt                   = float.Parse(seedFirtLine[1]);
        seedSoilFirt               = float.Parse(seedSoilFirtLine[1]);
        seedSoilFirtPower          = float.Parse(seedSoilFirtPowerLine[1]);

        reader.Close();


        map_v2 = new TileMap_V2(tex, sizeX, sizeY, climate, worldDeltaTime, seedSoilFracture, seedSoilColor, seedWater, seedSoil, seedSoilPower, seedFirt, seedSoilFirt, seedSoilFirtPower);
    }