Example #1
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);
                }
            }
        }
Example #2
0
        private void CheckCollisions(Strand strand)
        {
            for (int i = 0; i < _repellents.Count; i++)
            {
                if (Geometry.GetDistance(strand.Position, _repellents[i].Position) <= 1)
                {
                    this.ProcessCollision(strand, _repellents[i], _repellents, _repellentCollisionAction, () => this.AddRepellent());
                }
            }

            for (int i = 0; i < _attractors.Count; i++)
            {
                if (Geometry.GetDistance(strand.Position, _attractors[i].Position) <= 1)
                {
                    this.ProcessCollision(strand, _attractors[i], _attractors, _attractorCollisionAction, this.CheckRespawn);
                    break;
                }
            }

            if (_solidStrands)
            {
                for (int i = 0; i < _strands.Count; i++)
                {
                    Strand other;

                    other = _strands[i];

                    if (!object.ReferenceEquals(strand, other) && strand.Position == other.Position)
                    {
                        strand.UndoMove();
                        strand.Heading = _movementRandom.NextDouble() >= 0.5 ? Compass.GetNextQuarter(strand.Heading) : Compass.GetPreviousQuarter(strand.Heading);
                        break;
                    }
                }
            }
        }