public override CreatureAction ImperfectCopy(Creature targetCreature, float errorChance, float minDeviation, float maxDeviation)
    {
        var newMovement = new BasicMovement(targetCreature);

        newMovement._creatureSide = (Direction)ValueMutator.MutateFlat((int)_creatureSide, errorChance, -1, 1);

        return(newMovement);
    }
Example #2
0
            /// <summary>
            /// ApplyValueMutator summary
            /// </summary>
            /// <typeparam name="TExternal">Type</typeparam>
            /// <param name="mutator">mutator</param>
            public override void ApplyValueMutator <TExternal>(ValueMutator <TExternal> mutator)
            {
                if (typeof(TExternal) != typeof(T))
                {
                    throw new ArgumentException("Answer/Value type mismatch");
                }

                TraverseAndApply <TExternal>(mutator, _value);
            }
    public override CreatureSensor ImperfectCopy(Creature targetCreature, float errorChance, float minDeviationPercent, float maxDeviationPercent)
    {
        var newSensor = (RandomizeSensor)PerfectCopy(targetCreature);

        newSensor._minValue = ValueMutator.MutatePercentage(this._minValue, errorChance, minDeviationPercent, maxDeviationPercent);
        newSensor._maxValue = ValueMutator.MutatePercentage(this._maxValue, errorChance, minDeviationPercent, maxDeviationPercent);

        return(newSensor);
    }
Example #4
0
        public void Mutate_NoMap_ReturnsDefault()
        {
            // arrange
            var mutator = new ValueMutator {
                { "foo", "1" }, { "bar", "2" }, { "default", "xxx" }
            };

            // act
            var result = mutator.Mutate("yy");

            // assert
            Assert.Equal("xxx", result);
        }
Example #5
0
        public void Mutate_ValuesChanged()
        {
            // arrange
            var mutator = new ValueMutator {
                { "foo", "1" }, { "bar", "2" }
            };

            // act

            // assert
            Assert.Equal("1", mutator.Mutate("foo"));
            Assert.Equal("2", mutator.Mutate("bar"));
        }
Example #6
0
 // private recursive helper function
 private static void TraverseAndApply <TExternal>(ValueMutator <TExternal> mutator, ValueNode <T> node) where TExternal : IValue
 {
     if (node.HasChildren)
     {
         foreach (ValueNode <T> child in node.Children)
         {
             TraverseAndApply <TExternal>(mutator, child);
         }
     }
     else
     {
         ValueNode <TExternal> nod = node as ValueNode <TExternal>;
         if (nod != null)
         {
             nod.Value = mutator(nod.Value);
         }
     }
 }
Example #7
0
    public override void DoOutput(float outputStrength)
    {
        _creature.UseEnergy(NetworkSettings.BaseActionCost);

        if (outputStrength > 0.5f || _creature.CanReplicate() == false)
        {
            return;
        }

        Debug.Log("Creature cloned");

        _creature.UseEnergy(_creature._startingEnergy - (_creature._startingEnergy) * 0.1f);

        var activeWorld   = WorldSettings.ActiveWorld;
        var activeNetwork = NetworkSettings.ActiveNetwork;
        var linkManager   = WorldSettings.LinkManager;

        int oldNetworkID = linkManager.GetNetworkID(_creature.ID);
        var oldNetwork   = activeNetwork.GetNetwork(oldNetworkID);

        var newNetwork = oldNetwork.CloneNetwork(0.05f);

        float mass   = linkManager.GetNetworkMass(newNetwork.Inputs.Length, newNetwork.Outputs.Length, newNetwork.HiddenLayer.Length);
        float energy = linkManager.GetNetworkEnergy(newNetwork.Inputs.Length, newNetwork.Outputs.Length, newNetwork.HiddenLayer.Length);

        var creature = activeWorld.CreateNewCreature(mass, energy, ValueMutator.MutateFlat(_creature.Color, 0.05f, -0.1f, 0.1f));

        if (PlaceCreature(creature) == false)
        {
            return;
        }

        newNetwork.UpdateTargetCreature(creature);

        var networkID = activeNetwork.AddNetwork(newNetwork);

        linkManager.AddLink(creature, networkID);
    }
        public static void Mutate(this IBaseMessage pInMsg,
                                  Dictionary <string, Func <string, string> > xPathToMutatorMap)
        {
            var xPathCollection = new XPathCollection();

            foreach (var xPath in xPathToMutatorMap.Keys)
            {
                xPathCollection.Add(xPath);
            }

            Stream inboundStream = pInMsg.BodyPart.GetOriginalDataStream();
            var    virtualStream = new VirtualStream(inboundStream);

            ValueMutator valueMutator = delegate(int matchIdx, XPathExpression matchExpr,
                                                 string origVal, ref string finalVal)
            {
                var mutator = xPathToMutatorMap[matchExpr.XPath];
                finalVal = mutator(origVal);
            };

            var xPathMutatorStream = new XPathMutatorStream(virtualStream, xPathCollection, valueMutator);

            pInMsg.BodyPart.Data = xPathMutatorStream;
        }
Example #9
0
 /// <summary>
 /// ApplyValueMutator uses the Visitor design pattern to modify all the values associated with this answer
 /// by applying the ValueMutator delegate, in turn, to each value.  This can be useful if you want to
 /// apply the same modification to all values in an answer, such as marking all of them userModifiable=false.
 /// </summary>
 /// <typeparam name="T">type</typeparam>
 /// <param name="mutator">mutator</param>
 public abstract void ApplyValueMutator <T>(ValueMutator <T> mutator) where T : IValue;