Пример #1
0
        public bool IsDangerAt(Point pos, Direction direction)
        {
            var dangerElements = new[] {
                Element.ROBO_OTHER_LASER,
                Element.ROBO_LASER,
                Element.FEMALE_ZOMBIE,
                Element.MALE_ZOMBIE
            };

            switch (direction)
            {
            case Direction.Left:
                return(IsAt(pos, dangerElements.Concat(new[] { Element.LASER_RIGHT }).ToArray()) ||
                       IsAt(pos.ShiftLeft(), dangerElements.Concat(new[] { Element.LASER_RIGHT, Element.LASER_MACHINE_READY_RIGHT }).ToArray()) ||
                       IsAt(pos.ShiftBottom(), dangerElements.Concat(new[] { Element.LASER_UP, Element.LASER_MACHINE_READY_UP }).ToArray()) ||
                       IsAt(pos.ShiftTop(), dangerElements.Concat(new[] { Element.LASER_DOWN, Element.LASER_MACHINE_READY_DOWN }).ToArray()));

            case Direction.Right:
                return(IsAt(pos, dangerElements.Concat(new[] { Element.LASER_LEFT }).ToArray()) ||
                       IsAt(pos.ShiftRight(), dangerElements.Concat(new[] { Element.LASER_LEFT, Element.LASER_MACHINE_READY_LEFT }).ToArray()) ||
                       IsAt(pos.ShiftBottom(), dangerElements.Concat(new[] { Element.LASER_UP, Element.LASER_MACHINE_READY_UP }).ToArray()) ||
                       IsAt(pos.ShiftTop(), dangerElements.Concat(new[] { Element.LASER_DOWN, Element.LASER_MACHINE_READY_DOWN }).ToArray()));

            case Direction.Down:
                return(IsAt(pos, dangerElements.Concat(new[] { Element.LASER_UP }).ToArray()) ||
                       IsAt(pos.ShiftBottom(), dangerElements.Concat(new[] { Element.LASER_UP, Element.LASER_MACHINE_READY_UP }).ToArray()) ||
                       IsAt(pos.ShiftRight(), dangerElements.Concat(new[] { Element.LASER_LEFT, Element.LASER_MACHINE_READY_LEFT }).ToArray()) ||
                       IsAt(pos.ShiftLeft(), dangerElements.Concat(new[] { Element.LASER_RIGHT, Element.LASER_MACHINE_READY_RIGHT }).ToArray()));

            case Direction.Up:
                return(IsAt(pos, dangerElements.Concat(new[] { Element.LASER_DOWN }).ToArray()) ||
                       IsAt(pos.ShiftTop(), dangerElements.Concat(new[] { Element.LASER_DOWN, Element.LASER_MACHINE_READY_DOWN }).ToArray()) ||
                       IsAt(pos.ShiftRight(), dangerElements.Concat(new[] { Element.LASER_LEFT, Element.LASER_MACHINE_READY_LEFT }).ToArray()) ||
                       IsAt(pos.ShiftLeft(), dangerElements.Concat(new[] { Element.LASER_RIGHT, Element.LASER_MACHINE_READY_RIGHT }).ToArray()));

            default:
                return(false);
            }
        }
Пример #2
0
        /// <param name="from">Source point.</param>
        /// <param name="direction">Direction to fire.</param>
        /// <returns></returns>
        public int GetNearestEnemyDistanceByDirection(Point from, Direction direction)
        {
            var otherRobot = new[] {
                Element.ROBO_OTHER,
                Element.ROBO_OTHER_FALLING,
                Element.FEMALE_ZOMBIE,
                Element.MALE_ZOMBIE
            };
            var myPos = GetMe();

            if (from.IsOutOf(Size) || !myPos.HasValue)
            {
                return(0);
            }
            switch (direction)
            {
            case Direction.Down:
                var target = from.ShiftBottom();
                if (!CanGoAt(target))
                {
                    break;
                }
                if (IsAt(target, otherRobot))
                {
                    return(GetLinearDistance(myPos.Value, target));
                }
                return(GetNearestEnemyDistanceByDirection(target, direction));

            case Direction.Up:
                target = from.ShiftTop();
                if (!CanGoAt(target))
                {
                    break;
                }
                if (IsAt(target, otherRobot))
                {
                    return(GetLinearDistance(myPos.Value, target));
                }
                return(GetNearestEnemyDistanceByDirection(target, direction));

            case Direction.Left:
                target = from.ShiftLeft();
                if (!CanGoAt(target))
                {
                    break;
                }
                if (IsAt(target, otherRobot))
                {
                    return(GetLinearDistance(myPos.Value, target));
                }
                return(GetNearestEnemyDistanceByDirection(target, direction));

            case Direction.Right:
                target = from.ShiftRight();
                if (!CanGoAt(target))
                {
                    break;
                }
                if (IsAt(target, otherRobot))
                {
                    return(GetLinearDistance(myPos.Value, target));
                }
                return(GetNearestEnemyDistanceByDirection(target, direction));
            }
            return(0);
        }