Ejemplo n.º 1
0
        private void Flee(Strand strand, Chemoeffector noxious)
        {
            double distance;

            distance = Geometry.GetDistance(strand.Position, noxious.Position);

            if (distance <= 1)
            {
                this.ProcessCollision(strand, noxious, _repellents, _repellentCollisionAction, () => this.AddRepellent());
            }
            else
            {
                if (distance < strand.PreviousSensor)
                {
                    this.Tumble(strand);
                    this.CheckCollisions(strand);
                }
                else
                {
                    double newDistance;
                    Point  heading;
                    heading = strand.Heading;
                    this.Tumble(strand);
                    strand.Move();
                    newDistance = Geometry.GetDistance(strand.Position, noxious.Position);
                    if (newDistance < distance)
                    {
                        strand.Heading = heading;
                    }
                    strand.UndoMove();
                }

                strand.PreviousSensor = distance;
            }
        }
Ejemplo n.º 2
0
        private void MoveStrand(Strand strand)
        {
            Chemoeffector noxious;

            strand.Move();

            noxious = this.GetClosestRepellor(strand);

            if (noxious != null)
            {
                this.Flee(strand, noxious);
            }
            else
            {
                Chemoeffector food;

                food = this.GetClosestAttractor(strand);

                if (food != null)
                {
                    this.Approach(strand, food);
                }
                else if (strand.PreviousSensor != 0)
                {
                    strand.Heading = Compass.GetOpposite(strand.Heading);
                    this.Tumble(strand);
                    strand.PreviousSensor = 0;
                    this.CheckCollisions(strand);
                }
                else
                {
                    this.Tumble(strand);
                    strand.PreviousSensor = 0;
                    this.CheckCollisions(strand);
                }
            }
        }
Ejemplo n.º 3
0
        private void Approach(Strand strand, Chemoeffector food)
        {
            double distance;

            distance = Geometry.GetDistance(strand.Position, food.Position);

            if (distance <= 1)
            {
                this.ProcessCollision(strand, food, _attractors, _attractorCollisionAction, this.CheckRespawn);

                strand.PreviousSensor = 0;
            }
            else
            {
                if (distance > strand.PreviousSensor)
                {
                    this.Tumble(strand);
                    this.CheckCollisions(strand);
                }
                else
                {
                    double newDistance;
                    Point  heading;
                    heading = strand.Heading;
                    this.Tumble(strand);
                    strand.Move();
                    newDistance = Geometry.GetDistance(strand.Position, food.Position);
                    if (newDistance >= distance)
                    {
                        strand.Heading = heading;
                    }
                    strand.UndoMove();
                }

                strand.PreviousSensor = distance;
            }
        }