示例#1
0
        void UpdateEnergy()
        {
            float PassiveDrain = 0.15f;
            float ActiveDrain  = 0.2f;

            Energy -= ActiveDrain * (Math.Abs(Outputs[0]) + Math.Abs(Outputs[1])) / 2 + PassiveDrain * (1 + Age / (400 * Form1.fps));
            if (EatenFood.Count > 0)
            {
                float TotalFoodEnergy = 0;
                for (int i = 0; i < EatenFood.Count; i++)
                {
                    TotalFoodEnergy += EatenFood[i].Energy;
                }
                float FoodGain = (TotalFoodEnergy * 0.005f) + 0.1f;
                EatenFood[0].Energy -= FoodGain;
                Energy += FoodGain;
                if (EatenFood[0].Energy <= 0.01f)
                {
                    if (EatenFood[0].Seed)
                    {
                        UpdateWorld.AddEntity(new Seed(EatenFood[0].Parent, Pos, ChunkPos), Pos, ChunkPos);
                    }
                    EatenFood.RemoveAt(0);
                }
            }
            if (Energy <= 0)
            {
                Kill();
            }
        }
        void Hatch()
        {
            Child.IsEgg = null;
            Child.Brain.CopyFrom(Parents[0].Brain);
            int EyeMin = Parents[0].Eyes.Count;
            int EyeMax = EyeMin;

            for (int i2 = 1; i2 < Parents.Count; i2++)
            {
                int C = Parents[i2].Eyes.Count;
                if (C > EyeMax)
                {
                    EyeMax = C;
                }
                if (C < EyeMin)
                {
                    EyeMin = C;
                }
            }
            int EyeAmount = Form1.Rand.Next(EyeMin, EyeMax + 1);

            Child.Eyes = new List <Creature.Eye>();
            for (int i = 0; i < EyeAmount; i++)
            {
                int Id = Form1.Rand.Next(Parents.Count);
                while (Parents[Id].Eyes.Count < i + 1)
                {
                    Id = (Id + 1) % Parents.Count;
                }
                Child.Eyes.Add(new Creature.Eye(Child, Parents[Id].Eyes[i].Pos, Parents[Id].Eyes[i].Fov));
            }

            int    EyeId  = Form1.Rand.Next(Child.Eyes.Count);
            double Angle  = (Form1.Rand.NextDouble() * 2 - 1) * Math.PI * 0.1;
            float  Sin    = (float)Math.Sin(Angle);
            float  Cos    = (float)Math.Cos(Angle);
            Vector OldPos = Child.Eyes[EyeId].Pos;

            Child.Eyes[EyeId].Pos  = new Vector(OldPos.X * Cos + OldPos.Y * Sin, OldPos.Y * Cos - OldPos.X * Sin);
            Child.Eyes[EyeId].Fov += (float)Form1.Rand.NextDouble() * 0.1f;
            Child.Eyes[EyeId].Fov  = Child.Eyes[EyeId].Fov < 0 ? 0 : Child.Eyes[EyeId].Fov;
            Child.Eyes[EyeId].Fov  = Child.Eyes[EyeId].Fov > 1 ? 1 : Child.Eyes[EyeId].Fov;
            //mutate
            Child.Name   = Parents[0].Name;
            Child.Hue    = Parents[0].Hue;
            Child.EggHue = Parents[0].EggHue;
            Child.Mutate();

            UpdateWorld.AddEntity(Child, Pos, ChunkPos);
            UpdateWorld.RemoveEntity(this);
        }
 public void Update()
 {
     if (EnableCollide)
     {
         SeedTimer += 1 / Form1.fps;
         if (Dead)
         {
             UpdateWorld.RemoveEntity(this);
         }
         if (SeedTimer > SeedTimerMax)
         {
             Tree Tree = new Tree(Parent, Pos, ChunkPos)
             {
                 Energy = StartEnergy
             };
             UpdateWorld.AddEntity(Tree, Pos, ChunkPos);
             UpdateWorld.RemoveEntity(this);
         }
     }
 }
示例#4
0
 public void Update()
 {
     foreach (Eye E in Eyes)
     {
         E.Update();
     }
     updateBrain();
     UseSpike = Outputs[2] > 0.5;
     Move();
     UpdateEnergy();
     if (Energy > EggEnergy + StartEnergy)
     {
         Energy -= EggEnergy * 1.25f;
         UpdateWorld.AddEntity(new Egg(this), Pos, ChunkPos);
     }
     Age++;
     if (LeafEatTimer > 0)
     {
         LeafEatTimer--;
     }
 }
            public void Update(NeuralNetwork Network)
            {
                Age++;
                if (CurrentSeed != null)
                {
                    SeedTimer += Tree.MaxTimer / Form1.fps;
                    if (SeedTimer > SeedTimerMax)
                    {
                        CurrentSeed.Fall();
                        //UpdateWorld.AddEntity(CurrentSeed, CurrentSeed.Pos, CurrentSeed.ChunkPos);
                        CurrentSeed = null;
                    }
                }
                float L1 = (float)Form1.Rand.NextDouble();
                float L2 = (float)Form1.Rand.NextDouble();

                if (L1 + L2 > 1)
                {
                    L1 = 1 - L1;
                    L2 = 1 - L2;
                }
                RayPoint = Base + (Tip1 - Base) * L1 + (Tip2 - Base) * L2;

                float[] Inputs = Tree.Inputs;
                Inputs[2] = 0;
                Inputs[3] = (Parent.Layer + 1) / 3f;
                Inputs[4] = 0;
                Inputs[5] = CurrentSeed == null?0:1;
                Inputs[6] = EnergyFlow;
                Inputs[7] = Age / (AgeScale * Form1.fps);
                Inputs[8] = CurrentFlower != null ? 1 : 0;
                Inputs[9] = CurrentFlower != null ? (CurrentFlower.CurrentEnergy / FruitCost): 0;
                Network.SetInputs(Inputs);
                Network.Update();
                float[] Outputs = Network.GetOutputs();
                if (CurrentFlower != null)
                {
                    CurrentFlower.Update(Network.Clamp(Outputs[11], 0, 1));
                }
                if (Outputs[0] < -1)
                {
                    Tree.Energy += LeafCost / 2;
                    Kill();
                }
                else
                {
                    if (Outputs[9] > 0)
                    {
                        if (CurrentSeed == null && CurrentFlower == null && Tree.Energy > SeedCost)
                        {
                            Tree.Energy -= SeedCost;
                            CurrentSeed  = new Seed(Tree, this);
                            UpdateWorld.AddEntity(CurrentSeed, CurrentSeed.Pos, CurrentSeed.ChunkPos);
                        }
                        else
                        {
                            Tree.Energy -= SeedCost / 20;
                        }
                    }
                    if (Outputs[10] > 0)
                    {
                        if (CurrentSeed == null && CurrentFlower == null && Tree.Energy > FlowerCost)
                        {
                            Tree.Energy  -= FlowerCost;
                            CurrentFlower = new Flower(this);
                            UpdateWorld.AddEntity(CurrentFlower, Pos, ChunkPos);
                        }
                        else
                        {
                            Tree.Energy -= FlowerCost / 20;
                        }
                    }
                }
            }