Esempio n. 1
0
 public Reaction(Life life, Stimulus source)
 {
     if (life == null)
     {
         throw new ArgumentNullException("The life cannot be null.");
     }
     if (source == null)
     {
         throw new ArgumentNullException("The source cannot be null.");
     }
     this.Life        = life;
     this.Source      = source;
     this.behaviours  = new LifeGameX.RandomList <LifeGameX.Behaviour>();
     this.Description = "A reaction when " + this.Life + " is stimulated by " + this.Source.Name + " . ";
     life.RandomWeightList.Add(this);
 }
Esempio n. 2
0
        public Stimulus(Life life, Stimulus noReaction)
        {
            if (life == null)
            {
                throw new ArgumentNullException("The life cannot be null.");
            }

            /*if (noReaction == null)
             *  throw new ArgumentNullException("NoReaction stimulus required.");*/
            this.Reactions   = new RandomList <Reaction>();
            this.Life        = life;
            this.NoReaction  = noReaction;
            this.ID          = life.World.CreateStimulusID();
            this.Name        = "Stimulus-" + this.ID;
            this.Description = "A stimulus.";
            life.StimulusList.Add(this);
        }
Esempio n. 3
0
        public Life(string species, World world)
        {
            if (world == null)
            {
                throw new ArgumentNullException("World required.");
            }
            this.World                = world;
            this.Alive                = false;
            this.ID                   = World.CreateLifeID();
            this.Species              = species;
            this.Name                 = "Life-" + this.Species + "-" + this.ID;
            this.Resources            = new Dictionary <Substance, SubstanceCapsule>();
            this.SubstanceCapsuleList = new RandomList <SubstanceCapsule>();
            this.ReactionList         = new List <Reaction>();
            this.Behaviours           = new Dictionary <long, Behaviour>();
            this.BehaviourList        = new RandomList <Behaviour>();
            this.PendingStimulus      = new Queue <PendingStimulus>();
            this.PrevioursReactions   = new List <ReactionRecord>();
            this.Properties           = new RandomList <Property>();
            this.RandomWeightList     = new RandomList <IRandomObject>();
            this.X = -1;
            this.Y = -1;

            //init Behaviors
            #region Behaviors
            // NoResponse
            var noResponse = new Behaviours.NoResponse(this);
            // Metabolize
            var resToEnergy = new Behaviours.Metabolize.ResourceToEnergy(this, 10);
            var resToRes    = new Behaviours.Metabolize.ResourceToResource(this, 10);
            var energyToRes = new Behaviours.Metabolize.EnergyToResource(this, 10);
            var cure        = new Behaviours.Metabolize.Cure(this, 5);
            var autotomy    = new Behaviours.Metabolize.Autotomy(this, 5);
            // Multiply
            var multiply = new Behaviours.Multiply(this, 20);
            // Action
            var die  = new Behaviours.Action.Die(this);
            var move = new Behaviours.Action.Move(this, 20);
            // Interact
            var interact = new Behaviours.Interact(this, 10);
            // Learn
            var establishReaction = new Behaviours.Learn.EstablishReaction(this, 10);
            var abolishReaction   = new Behaviours.Learn.AbolishReaction(this, 10);
            var incWeight         = new Behaviours.Learn.IncreaseWeight(this, 5);
            var decWeight         = new Behaviours.Learn.DecreaseWeight(this, 5);

            var mutate = new Behaviours.Mutate(this, 50);

            #endregion

            //init Energy
            this.energy = 200;
            this.BuildReaction(this.EnergyEmptyStimulus, this.Behaviours[LifeGameX.Behaviours.Action.Die.TypeID]);

            //init Health
            this.Health = new LifeGameX.Health(this, 100);

            //init stimulus
            this.StimulusList        = new List <Stimulus>();
            this.NoReactionStimulus  = new Stimulus(this, this.NoReactionStimulus);
            this.EnergyLowStimulus   = new Stimulus(this, this.NoReactionStimulus);
            this.InteractStimulus    = new Stimulus(this, this.NoReactionStimulus);
            this.EnvironmentStimulus = new Stimulus(this, this.NoReactionStimulus);
            this.TimeUpdateStimulus  = new Stimulus(this, this.NoReactionStimulus);

            this.BuildReaction(TimeUpdateStimulus, noResponse).Weight = 500;
            this.BuildReaction(TimeUpdateStimulus, move);
            this.BuildReaction(TimeUpdateStimulus, energyToRes);
            this.BuildReaction(TimeUpdateStimulus, resToEnergy);
            this.BuildReaction(TimeUpdateStimulus, multiply).Weight = 50;
        }