Exemplo n.º 1
0
Arquivo: Teldra.cs Projeto: cynic/HvZ
        private void Chase(IZombiePlayer player)
        {
            double angle = player.AngleTo(target);

            if (Math.Abs(angle) < 25.0)
            {
                double dist = player.DistanceFrom(target);
                if (dist < 7.0)
                {
                    if (ThinkOutLoud)
                    {
                        Console.WriteLine("Going forward {0} units, hopefully this will get me close enough to bite {1}", dist, target);
                    }
                    player.GoForward(dist);
                }
                else
                {
                    if (ThinkOutLoud)
                    {
                        Console.WriteLine("Going forward {0} units (aiming for {1}), then I'll reevaluate my strategy.", dist, target);
                    }
                    player.GoForward(dist / 4);
                }
            }
            else
            {
                if (ThinkOutLoud)
                {
                    Console.WriteLine("Turning {0} degrees to face {1}", angle, target);
                }
                player.Turn(angle);
            }
        }
Exemplo n.º 2
0
Arquivo: Teldra.cs Projeto: cynic/HvZ
        public void DoSomething(IZombiePlayer player, List <IWalker> zombies, List <IWalker> humans, List <ITakeSpace> obstacles, List <ResupplyPoint> resupply)
        {
            if (humans.Count == 0)
            {
                if (ThinkOutLoud)
                {
                    Console.WriteLine("Yay, I've caught 'em all!  Suck on that, Ash Ketchum.");
                }
                return; // no humans? Then I have nothing to do.
            }
            // opportunity knocks but once: if I'm in-range of any humans -- whether they're my target or not -- bite 'em!
            foreach (IWalker h in humans)
            {
                if (!player.IsCloseEnoughToInteractWith(h))
                {
                    continue;
                }
                if (ThinkOutLoud)
                {
                    Console.WriteLine("Opportunity knocks!  Biting {0}", h);
                }
                player.Bite(h);
                return;
            }
            bool targetStillExists = false;

            if (target != null)
            {
                foreach (IWalker h in humans)
                {
                    if (h.Id == target.Id)
                    {
                        targetStillExists = true;
                        break;
                    }
                }
            }
            if (target == null || !targetStillExists)
            { // find a new target.
                target = GetNewTarget(player, humans);
            }
            // change targets if anyone comes quite close to me.
            IWalker possibleNewTarget = GetNewTarget(player, humans);

            if (possibleNewTarget != null && possibleNewTarget.Id != target.Id && player.DistanceFrom(possibleNewTarget) < player.DistanceFrom(target) / 2)
            {
                if (ThinkOutLoud)
                {
                    Console.WriteLine("Switching target from {0} to {1}", target, possibleNewTarget);
                }
                target = possibleNewTarget;
                Chase(player);
                return;
            }
            if (player.Movement == MoveState.Moving)
            {
                return;                                      // punt! until we stop moving.
            }
            if (collided)
            {
                double dist = rand.Next(4, (int)Math.Max(6.0, Math.Min(player.MapWidth, player.MapHeight) / 6));
                if (ThinkOutLoud)
                {
                    Console.WriteLine("Recovering from collision; going forward {0} units.", dist);
                }
                player.GoForward(dist);
                collided = false;
                return;
            }
            // now: chase!
            Chase(player);
        }