public RandomLifelet(World world, Vector pos)
     : base(world,pos)
 {
     // Init
     _direction = new Vector(this.RandomGen.Next(-1,2),this.RandomGen.Next(-1,2));
     _speed = 2.0;
 }
Ejemplo n.º 2
0
 public Obstacle(World world, Vector pos)
 {
     // Init
     _world = world;
     _uid = _gid++;
     _pos = pos;
 }
Ejemplo n.º 3
0
 public Food(World world, Vector pos, double energy)
     : base(world,pos)
 {
     // Init
     _energy = energy;
     _maxAge = Math2.JitteredValue(Config.FoodMaxAge,Config.FoodMaxAgeJitter);
 }
        private double _speed; // Our speed we want

        #endregion Fields

        #region Constructors

        public CannibalLifelet(World world, Vector pos)
            : base(world,pos)
        {
            // Init
            _speed = 1.0;

            // Initial message to find each other
            talk('!');
        }
        private double _speed; // Our speed we want

        #endregion Fields

        #region Constructors

        public SnakeLifelet(World world, Vector pos)
            : base(world,pos)
        {
            // Init
            _direction = new Vector(this.RandomGen.Next(-1,2),this.RandomGen.Next(-1,2));
            _speed = 2.0;

            // Initial message to find each other
            talk('!');
        }
Ejemplo n.º 6
0
 /// <summary>
 /// Initializes a new instance of the <see cref="LifeSimulation.Core.Lifelet"/> class.
 /// </summary>
 public Lifelet(World world, Vector pos)
 {
     // Init
     _world = world;
     _uid = _gid++;
     _pos = pos;
     _vel = new Vector(0,0);
     _velReq = new Vector(0,0);
     _color = (Color)world.Statistics[this.Type + "_Color"]; // We assign a fixed color based on the value kept in the statistics
     _age = 0;
     _health = Config.LifeletInitialHealth;
     _energy = Config.LifeletInitialEnergy;
 }
        public override void Simulate()
        {
            base.Simulate();

            // Change direction randomly
            if(this.RandomGen.Next(200) == 0) {
                _direction = new Vector(this.RandomGen.Next(-1,2),this.RandomGen.Next(-1,2));
            }

            // Change speed randomly
            if(this.RandomGen.Next(150) == 0) {
                _speed = this.RandomGen.Next(0,3);
            }

            // Random chatter...
            if(this.RandomGen.Next(250) == 0) {
                this.talk(Config.MessageLanguage[this.RandomGen.Next(Config.MessageLanguage.Length)]);
            }

            // Move
            this.move(_direction);
        }
Ejemplo n.º 8
0
 /// <summary>
 /// Sets a request to move the lifelet with the given velocity.
 /// </summary>
 protected void move(Vector v)
 {
     // Put a cap on vel
     double n = v.Norm();
     if(n > Config.LifeletMaximumVelocityRequest) {
         v = v.Normalize() * Config.LifeletMaximumVelocityRequest;
     }
     // Update requested velocity for next simulate
     _velReq = v;
 }
Ejemplo n.º 9
0
 public double Distance(Vector other)
 {
     return Vector.Distance(this,other);
 }
Ejemplo n.º 10
0
 public double Distance(Vector point)
 {
     return this.Position.Distance(point);
 }
 public double Distance(Vector point)
 {
     checkIfValid();
     return _lifelet.Distance(point);
 }
        public override void Simulate()
        {
            base.Simulate();

            // Recieving messages?
            foreach(Message message in audibleMessages()) {
                if(message.Contents == '!') {
                    if(message.Sender.UID < this.UID && (_lifeletToFollowUID == -1 || message.Sender.UID > _lifeletToFollowUID)) {
                        // Follow this lifelet
                        _lifeletToFollowUID = message.Sender.UID;
                    }
                }
            }

            // Try to find our next in chain...
            ShelledLifelet _lifeletToFollow = this.getLifeletByUID(_lifeletToFollowUID);

            // Are we following the chain?
            if(_lifeletToFollow != null) {

                // Set direction
                _direction = _lifeletToFollow.Position - this.Position;

                // Do we need to catch up?
                if(_lifeletToFollow.Distance(this) > this.Visibility/2)	_speed = 2.0;
                else 													_speed = 0.0;

            } else {

                // Do we see food?
                bool foodFound = false;
                foreach(Food food in visibleFood()) {
                    _direction = food.Position - this.Position;
                    foodFound = true;
                    break;
                }

                // Change direction randomly
                if(!foodFound) {

                    // Randomly change direction
                    if(this.RandomGen.Next(80) == 0) {
                        _direction = new Vector(this.RandomGen.Next(-1,2),this.RandomGen.Next(-1,2));
                        if(_direction.X == 0 && _direction.Y == 0) _direction = new Vector(1,1);
                    }
                }

            }

            // Redistribute energy
            if(this.Energy > 100) {
                foreach(ShelledLifelet lifelet in visibleLifelets()) {
                    // Only pass down the chain and only to our race
                    if(lifelet.UID != _lifeletToFollowUID && lifelet.Type == this.Type) {
                        giveEnergy(lifelet,this.Energy-100);
                        break;
                    }
                }
            }

            // Move in the current direction
            this.move(_direction.Normalize() * _speed);
        }
Ejemplo n.º 13
0
 /// <summary>
 /// Sets a request to move the lifelet in the direction of destination with the given speed.
 /// </summary>
 protected void moveToDestination(Vector destination, double speed)
 {
     Vector direction = destination - this.Position;
     this.move(direction.Normalize() * speed);
 }
Ejemplo n.º 14
0
 public double AngleBetween(Vector other)
 {
     return Math.Atan2(this.X - other.X, this.Y - other.Y);
 }
Ejemplo n.º 15
0
        /// <summary>
        /// Simulate this instance for one timestep. Extending classes must call base.Simulate() otherwise they are disqualified.
        /// </summary>
        public virtual void Simulate()
        {
            // Age
            _age += Config.LifeletAgeIncrement;

            // Energy
            _lastEnergy = _energy;
            _energy -= Config.LifeletNaturalEnergyDecrement;
            if(_energy < 0) _energy = 0;

            // Consume food
            foreach(Food food in _world.Food) {
                if(food.Distance(this) < 10) {
                    _energy += food.Energy;
                    _world.Food.Remove(food);
                }
            }

            // Make sure we are moving within world radius
            Vector newPos = _pos + _velReq;
            if(newPos.Distance(Vector.Empty) > Config.WorldRadius) {
                // Can't do this, out of bounds!
                _velReq = new Vector(0,0);
            }

            // Calculate energy required for move
            double energyNeeded = _velReq.Norm() * Config.LifeletMovementEnergyMultiplier;
            if(_energy - energyNeeded > 0) {

                // Set the velocity and book the energy
                _energy -= energyNeeded;
                _vel = _velReq;

            } else {

                // Can't do this, no energy!
                _vel = new Vector(0,0);

            }

            // Process movement
            _pos += _vel;

            // Health
            _lastHealth = _health;
            _health -= Config.LifeletNaturalHealthDecrement;
            if(this.CriticalEnergy == true) {
                _health -= Config.LifeletLowEnergyHealthDecrement;
            }
            if ( _health <= Config.LifeletMinimumHealth )	this.die();

            // Register that the base simulate was called
            _didSimulate = true;
        }
Ejemplo n.º 16
0
 public double Dot(Vector other)
 {
     return _x*other.X + _y*other.Y;
 }
Ejemplo n.º 17
0
 public static double Distance(Vector v1, Vector v2)
 {
     return Math.Sqrt( (v2.X - v1.X)*(v2.X - v1.X) + (v2.Y - v1.Y)*(v2.Y - v1.Y) );
 }