示例#1
0
        protected static IEnumerable <WayPoint> ImportWayPoints(string filePath)
        {
            var list = new List <WayPoint>();

            foreach (var s in new StringReader(hc[filePath]).ReadToEnd().Split(new [] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries))
            {
                var xs = s.Split();
                var wp = new WayPoint {
                    Coordinates = new Point
                    {
                        X = Convert.ToInt32(xs[0]),
                        Y = Convert.ToInt32(xs[1])
                    }
                };

                if (xs.Length == 3)
                {
                    wp.Angle = Math.PI * 2 - Convert.ToDouble(xs[2], CultureInfo.InvariantCulture) + 2 * Math.PI;
                }

                list.Add(wp);
            }

            for (int i = 0; i < list.Count; i++)
            {
                if (list[i].Angle < 2 * Math.PI)
                {
                    list[i].Angle = AngleUtils.GetDirection(list[i].Coordinates, list[(i + 1) % list.Count].Coordinates);
                }
                list[i].Angle = AngleUtils.Normalize(list[i].Angle);
            }
            return(list);
        }
示例#2
0
        public override MoveInfo MakeMove(State state)
        {
            var nearest = state.Enemies[0];
            var me      = state.Fighter.Coordinates;

            foreach (var enem in state.Enemies)
            {
                if (length(me, enem.Coordinates) < length(me, nearest.Coordinates))
                {
                    nearest = enem;
                }
            }

            var toCoordinates = state.Fighter.Coordinates;
            var toAngle       = state.Fighter.Angle;

            if (length(nearest.Coordinates, me) > state.Fighter.Properties.Speed)
            {
                toCoordinates.X = me.X + ((me.X - nearest.Coordinates.X) * state.Fighter.Properties.Speed) / length(nearest.Coordinates, me);
                toCoordinates.Y = me.Y + ((me.Y - nearest.Coordinates.Y) * state.Fighter.Properties.Speed) / length(nearest.Coordinates, me);
            }
            toAngle = AngleUtils.GetDirection(me, nearest.Coordinates);

            return(new MoveInfo(
                       toCoordinates,
                       toAngle)
            {
                FireTarget = nearest.Coordinates,
            });
        }