Exemplo n.º 1
0
        public override Output Run(Input input)
        {
            var output = new Output
            {
                Data   = new ulong[] { 0 },
                Energy = -1,
            };

            var magnitude = Convert.ScaledFloat(input.Data[0]);
            var cost      = Math.Max(MinCost, (long)(magnitude * EnergyScalar));

            if ((ulong)cost > input.AvailableEnergy)
            {
                return(output);
            }

            var position  = transform.position;
            var direction = transform.forward;
            var distance  = magnitude * DistanceScalar;
            var hit       = Physics.Raycast(position, direction, distance);

            output.Data   = new[] { hit?input.Data[0] : 0 };
            output.Energy = -cost;
            return(output);
        }
Exemplo n.º 2
0
        public override Output Run(Input input)
        {
            var output = new Output
            {
                Data   = new ulong[] { 0 },
                Energy = -BaseEnergyCost,
            };

            if (input.Data[0] == 0 || input.AvailableEnergy <= BaseEnergyCost)
            {
                return(output);
            }

            var energyAmount = (ulong)(Convert.ScaledFloat(input.Data[0]) * (input.AvailableEnergy - BaseEnergyCost));

            if (energyAmount < MinEnergyAmount || energyAmount < BaseEnergyCost)
            {
                return(output);
            }

            var cost = energyAmount + copyCost + BaseEnergyCost;

            if (cost > input.AvailableEnergy || cost < energyAmount)
            {
                return(output);
            }

            var child = Object.Instantiate(t.gameObject, t.position + new Vector3(0, 0, 5f), t.rotation, genGroup);

            if (child == null)
            {
                return(output);
            }

            var go = child.GetComponent <Organism>();

            if (go == null)
            {
                return(output);
            }

            var config = parent.Config;

            config.Seed           = UnityEngine.Random.Range(int.MinValue, int.MaxValue);
            config.StartingEnergy = energyAmount;
            config.Mutate         = true;
            config.NewGenome      = null;
            config.Generation++;
            config.Born = Time.frameCount;

            go.Initialize(config);

            output.Data   = new [] { ulong.MaxValue };
            output.Energy = -(long)cost;
            return(output);
        }
Exemplo n.º 3
0
        public override Output Run(Input input)
        {
            var output = new Output
            {
                Data   = new [] { input.Data[0] },
                Energy = -1,
            };

            var magnitude = Convert.ScaledFloat(input.Data[0]);
            var cost      = Math.Max(MinCost, (long)(magnitude * EnergyScalar));

            if ((ulong)cost > input.AvailableEnergy)
            {
                return(output);
            }

            var direction = rb.transform.forward;
            var force     = direction * (magnitude * ForceScalar * Time.deltaTime);

            rb.AddForce(force);

            output.Energy = -cost;
            return(output);
        }