Beispiel #1
0
        /**
         * @param numLayer Layer number (from 0).
         * @param x        X coordinate.
         * @param y        Y coordinate.
         * @return All elements around
         * (at left, right, down, up,
         * left-down, left-up, right-down, right-up) position.
         */
        protected List <Element> GetNear(int numLayer, int x, int y)
        {
            List <Element> result = new List <Element>();

            int radius = 1;

            for (int dx = -radius; dx <= radius; dx++)
            {
                for (int dy = -radius; dy <= radius; dy++)
                {
                    Point pt = new Point(x + dx, y + dy);
                    if (pt.IsOutOf(size))
                    {
                        continue;
                    }
                    if (dx == 0 && dy == 0)
                    {
                        continue;
                    }
                    if (WithoutCorners && (dx != 0 && dy != 0))
                    {
                        continue;
                    }
                    result.Add(GetAt(numLayer, x + dx, y + dy));
                }
            }

            return(result);
        }
Beispiel #2
0
 public bool CanGoAt(Point p)
 {
     return((!IsAt(p,
                   Element.BOX,
                   Element.FEMALE_ZOMBIE,
                   Element.MALE_ZOMBIE,
                   Element.LASER_MACHINE_READY_LEFT,
                   Element.LASER_MACHINE_READY_RIGHT,
                   Element.LASER_MACHINE_READY_UP,
                   Element.LASER_MACHINE_READY_DOWN,
                   Element.LASER_MACHINE_CHARGING_LEFT,
                   Element.LASER_MACHINE_CHARGING_RIGHT,
                   Element.LASER_MACHINE_CHARGING_UP,
                   Element.LASER_MACHINE_CHARGING_DOWN,
                   Element.ANGLE_IN_LEFT,
                   Element.WALL_FRONT,
                   Element.ANGLE_IN_RIGHT,
                   Element.WALL_RIGHT,
                   Element.ANGLE_BACK_RIGHT,
                   Element.WALL_BACK,
                   Element.ANGLE_BACK_LEFT,
                   Element.WALL_LEFT,
                   Element.WALL_BACK_ANGLE_LEFT,
                   Element.WALL_BACK_ANGLE_RIGHT,
                   Element.ANGLE_OUT_RIGHT,
                   Element.ANGLE_OUT_LEFT,
                   Element.ZOMBIE_START
                   )) || p.IsOutOf(Size));
 }
Beispiel #3
0
        /**
         * Says if at given position (X, Y) at given layer has given element.
         *
         * @param numLayer Layer number (from 0).
         * @param x        X coordinate.
         * @param y        Y coordinate.
         * @param element  Elements that we try to detect on this point.
         * @return true is element was found.
         */

        protected bool IsAt(int numLayer, int x, int y, Element element)
        {
            Point pt = new Point(x, y);

            if (pt.IsOutOf(size))
            {
                return(false);
            }
            return(GetAt(numLayer, x, y) == element);
        }
Beispiel #4
0
        /**
         * Says if near (at left, right, down, up,
         * left-down, left-up, right-down, right-up)
         * given position (X, Y) at given layer exists given element.
         *
         * @param numLayer Layer number (from 0).
         * @param x        X coordinate.
         * @param y        Y coordinate.
         * @param element  Element that we try to detect on near point.
         * @return true is element was found.
         */
        protected bool IsNear(int numLayer, int x, int y, Element element)
        {
            Point pt = new Point(x, y);

            if (pt.IsOutOf(size))
            {
                return(false);
            }
            return(CountNear(numLayer, x, y, element) > 0);
        }
Beispiel #5
0
        /**
         * @param numLayer Layer number (from 0).
         * @param x        X coordinate.
         * @param y        Y coordinate.
         * @param element  Element that we try to detect on near point.
         * @return Returns count of elements with type specified near
         * (at left, right, down, up,
         * left-down, left-up, right-down, right-up) {x,y} point.
         */
        protected int CountNear(int numLayer, int x, int y, Element element)
        {
            Point pt = new Point(x, y);

            if (pt.IsOutOf(size))
            {
                return(0);
            }
            List <Element> near  = GetNear(numLayer, x, y);
            int            count = 0;

            foreach (Element e in near)
            {
                if (e == element)
                {
                    count++;
                }
            }
            return(count);
        }
Beispiel #6
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);
        }