Example #1
0
        private static void placeResupply(ResupplyPoint item, Canvas c)
        {
            var e = new Ellipse()
            {
                Width = item.Radius * 2, Height = item.Radius * 2
            };

            e.Fill            = (ImageBrush)Application.Current.Resources["supply"];
            e.Stroke          = Brushes.Black;
            e.StrokeThickness = 0.1;
            var translate = new TranslateTransform(item.Position.X - item.Radius, item.Position.Y - item.Radius);

            e.RenderTransform = translate;
            c.Children.Add(e);
        }
Example #2
0
        public void DoSomething(IHumanPlayer player, List <IWalker> zombies, List <IWalker> humans, List <ITakeSpace> obstacles, List <ResupplyPoint> resupply)
        {
            // am I almost dead??  If so, eat something!
            if (player.Lifespan == 1)
            {
                //Console.WriteLine("Almost dead -- eating something!");
                player.Eat();
                return;
            }
            // am I already moving?  If so, don't update my movement.
            if (player.Movement == MoveState.Moving)
            {
                return;
            }
            // I collided last turn, but I've finished my turning to avoid that now.  Go forward instead.
            if (hasCollidedLastTurn)
            {
                //Console.WriteLine("Collided last turn.  Finished turning, so going forward a bit.");
                player.GoForward(rand.Next(4, 35));
                hasCollidedLastTurn = false;
                return;
            }
            // find the closest resupply point.
            if (visited.Count == resupply.Count)
            {
                visited.Clear(); // start again!
            }
            if (resupply.Count == 0)
            {
                //Console.WriteLine("No resupply points?  There's nothing for a greedy human to do, then :-(.  Will just sit and starve here...");
                return; // do nothing!
            }
            ResupplyPoint supplyPoint = null;

            foreach (ResupplyPoint r in resupply)
            {
                if ((supplyPoint == null || player.DistanceFrom(supplyPoint) > player.DistanceFrom(r)) && !visited.Contains(r.Id))
                {
                    supplyPoint = r;
                }
            }
            // am I there already?
            if (supplyPoint.Intersects(player) && supplyPoint.Available.Length > 0)
            {
                if (supplyPoint.Available.Contains(SupplyItem.Food))
                {
                    //Console.WriteLine("Taking some food.");
                    player.TakeFoodFrom(supplyPoint);
                }
                else
                {
                    //Console.WriteLine("Taking some socks.");
                    player.TakeSocksFrom(supplyPoint);
                }
                visited.Add(supplyPoint.Id);
            }
            else
            {
                // I still need to go there...
                double angleTo = player.AngleTo(supplyPoint);
                if (Math.Abs(angleTo) >= 10.0)
                {
                    //Console.WriteLine("Turning {0} degrees to face my food, yum!");
                    player.Turn(angleTo);
                }
                else
                {
                    //Console.WriteLine("Going to my food.");
                    player.GoForward(player.DistanceFrom(supplyPoint));
                }
            }
        }