Example #1
0
        public static Coord Closest(this IEnumerable <Coord> coords, Coord closeTo)
        {
            var   score    = double.MaxValue;
            Coord coordOut = null;

            foreach (var coord in coords)
            {
                var newScore = AiBase.DistanceBetween(coord, closeTo);
                if (newScore < score)
                {
                    score    = newScore;
                    coordOut = coord;
                }
            }

            return(coordOut);
        }
Example #2
0
        public override Coord Update(IEnumerable <Coord> trees, IEnumerable <Coord> monsters, Coord witcher, Coord me)
        {
            // Witcher? What witcher?
            if (witcher == null || AiBase.DistanceBetween(me, witcher) > 5)
            {
                return(this.Wander(trees, me));
            }

            // Try to escape Geralt!
            var x = me.X;
            var y = me.Y;

            if (witcher.X < me.X)
            {
                x += 1;
            }

            if (witcher.X > me.X)
            {
                x -= 1;
            }

            if (witcher.Y < me.Y)
            {
                y += 1;
            }

            if (witcher.Y > me.Y)
            {
                y -= 1;
            }

            var newLocation = new Coord(x, y);

            // If we've got our back to a tree, cower. Otherwise, run!
            return(trees.Contains(newLocation) ? me : newLocation);
        }