Esempio n. 1
0
        public Antelope FindNewMate(Field <IAnimal> field)
        {
            var      closestMateDistance = int.MaxValue;
            Antelope newMate             = null;

            for (int i = -_matingRange; i <= _matingRange; i++)
            {
                for (int j = -_matingRange; j <= _matingRange; j++)
                {
                    if (i == 0 && j == 0)
                    {
                        continue;
                    }

                    var checkedCellAsAntelope = field[Position.X + i, Position.Y + j] as Antelope;
                    if (checkedCellAsAntelope != null && _vectorMath.ToEightWayDistance(i, j) < closestMateDistance)
                    {
                        newMate             = checkedCellAsAntelope;
                        closestMateDistance = _vectorMath.ToEightWayDistance(Position - newMate.Position);
                    }
                }
            }
            return(newMate);
        }
Esempio n. 2
0
        public Antelope FindClosestAntelope(Field <IAnimal> field)
        {
            Antelope targetAntelope = null;

            for (int i = -_visionRange; i <= _visionRange; i++)
            {
                for (int j = -_visionRange; j <= _visionRange; j++)
                {
                    var currentCellAsAntelope = field[Position.X + i, Position.Y + j] as Antelope;

                    var currentIsCloser = targetAntelope == null ||
                                          _vectorMath.ToEightWayDistance(new Vector(i, j)) < _vectorMath.ToEightWayDistance(Position - targetAntelope.Position);

                    if (currentCellAsAntelope != null && currentIsCloser)
                    {
                        targetAntelope = currentCellAsAntelope;
                    }
                }
            }

            return(targetAntelope);
        }