Ejemplo n.º 1
0
        public override bool TryMove(Field <IAnimal> field, out Vector nextMove)
        {
            nextMove = new Vector(0, 0);
            if (!TryDecreaseHealth())
            {
                return(false);
            }

            _targetAntelope = FindClosestAntelope(field);

            if (_targetAntelope == null)
            {
                nextMove = _randomMoveCalculator.GetFreePositionsAndCalculate(Position, field);
            }
            else
            {
                nextMove = CalculateMoveToFollowTarget(field);
                var nextPos = Position + nextMove;
                if (field[nextPos.X, nextPos.Y] == _targetAntelope)
                {
                    _health += _healthForAntelope;
                    _targetAntelope.Die(EventArgs.Empty);
                    _targetAntelope = null;
                }
            }
            return(true);
        }
Ejemplo n.º 2
0
        public override bool TryMove(Field <IAnimal> field, out Vector nextMove)
        {
            if (!TryDecreaseHealth())
            {
                nextMove = new Vector();
                return(false);
            }

            PerformMating(field);

            var vectorsLionToAntelope = CollectVectorsFromNearbyLions(field);

            if (vectorsLionToAntelope.Count > 0)
            {
                nextMove = _borderChecker.FitVectorIntoBorders(field.Size, Position, CalculateMoveByNearbyLions(vectorsLionToAntelope));
            }
            else
            {
                nextMove = _randomMoveCalculator.GetFreePositionsAndCalculate(Position, field);
            }

            var p = Position + nextMove;

            return(field[p.X, p.Y] == null);
        }