Ejemplo n.º 1
0
        public void DoSomething(IHumanPlayer player, List <IWalker> zombies, List <IWalker> humans, List <ITakeSpace> obstacles, List <ResupplyPoint> resupply)
        {
            if (player.Movement == MoveState.Moving)
            {
                return;
            }
            switch (rng.Next(2))
            {
            case 0: player.Turn((rng.NextDouble() > 0.5 ? -1 : 1) * rng.NextDouble() * 300.0); break;

            case 1: player.GoForward(rng.NextDouble() * 20.0); break;
            }
        }
Ejemplo n.º 2
0
        public void DoSomething(IHumanPlayer player, List <IWalker> zombies, List <IWalker> humans, List <ITakeSpace> obstacles, List <ResupplyPoint> resupply)
        {
            if (player.Movement == MoveState.Moving)
            {
                return;
            }
            switch (state)
            {
            case 0:
                player.Turn(player.AngleToHeading(45));
                state++;
                break;

            case 1:
            case 3:
            case 5:
            case 7:
            case 9:
            case 11:
            case 13:
            case 15:
                player.GoForward(5.0);
                state++;
                break;

            case 2:
                player.Turn(player.AngleToHeading(90));
                state++;
                break;

            case 4:
                player.Turn(player.AngleToHeading(90 + 45));
                state++;
                break;

            case 6:
                player.Turn(player.AngleToHeading(180));
                state++;
                break;

            case 8:
                player.Turn(player.AngleToHeading(180 + 45));
                state++;
                break;

            case 10:
                player.Turn(player.AngleToHeading(270));
                state++;
                break;

            case 12:
                player.Turn(player.AngleToHeading(270 + 45));
                state++;
                break;

            case 14:
                player.Turn(player.AngleToHeading(0));
                state++;
                break;

            case 16:
                player.Turn(rng.NextDouble() * 300.0);
                state = 0;
                break;
            }
        }
Ejemplo n.º 3
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));
                }
            }
        }
Ejemplo n.º 4
0
        public void DoSomething(IHumanPlayer player, List <IWalker> zombies, List <IWalker> humans, List <ITakeSpace> obstacles, List <ResupplyPoint> resupply)
        {
            gameTime++;
            if (player.Lifespan == 1)
            {
                player.Eat();
            }
            //if (zombies.Count == 0) return; // nothing to do!
            var closestZ =
                zombies
                .OrderBy(x => x.DistanceFrom(player))
                .Where(x => !x.IsStunned)
                .Where(x => !targeted.ContainsKey(x.Id) || (gameTime - targeted[x.Id] > 8))
                .FirstOrDefault();

            if (closestZ != null && player.IsInSockRange(closestZ) && player.Inventory.Contains(SupplyItem.Sock))
            {
                // screw it, throw a sock!
                player.Throw(player.Heading + player.AngleTo(closestZ));
                targeted[closestZ.Id] = gameTime;
                return;
            }
            if (player.Lifespan < player.MaximumLifespan / 2 && !player.Inventory.Contains(SupplyItem.Food) && gameTime % 20 == 0)
            {
                s = State.FindFood;
            }
            else if (!player.Inventory.Contains(SupplyItem.Sock) && gameTime % 50 == 0)
            {
                s = State.FindAmmo;
            }
            if (player.Movement == MoveState.Moving)
            {
                return;
            }
            Console.WriteLine("State: {0}", s);
            switch (s)
            {
            case State.Undecided: {
                if (zombies.Count == 0)
                {
                    s = State.AllDone;
                    //s = State.RunAway;
                    return;
                }
                if (!player.Inventory.Contains(SupplyItem.Sock))
                {
                    s = State.FindAmmo;
                }
                else if (!player.Inventory.Contains(SupplyItem.Food))
                {
                    s = State.FindFood;
                }
                else
                {
                    go_to = (RunState)(((int)++go_to) % 4);
                    s     = State.RunAway;
                }
                break;
            }

            case State.FindFood:
            case State.FindAmmo: {
                var r = GetClosestResupplyWith(player, resupply, s == State.FindFood ? SupplyItem.Food : SupplyItem.Sock);
                if (r == null)
                {
                    return;                // ... aaand wait?
                }
                if (player.IsCloseEnoughToInteractWith(r))
                {
                    s = s == State.FindFood ? State.GetFood : State.GetAmmo;
                    return;
                }
                var angle = player.AngleTo(r);
                if (Math.Abs(angle) < 1.0)
                {
                    player.GoForward(player.DistanceFrom(r));
                }
                else
                {
                    player.Turn(angle);
                }
                break;
            }

            case State.GetFood: {
                var r = GetClosestResupplyWith(player, resupply, SupplyItem.Food);
                if (r == null)
                {
                    s = State.Undecided;
                    return;
                }
                if (!player.IsCloseEnoughToInteractWith(r))
                {
                    s = State.FindFood;
                    return;
                }
                Console.WriteLine("Available here: {0}", String.Join(", ", r.Available));
                if (r.Available.Contains(SupplyItem.Food))
                {
                    player.TakeFoodFrom(r);
                    s = State.Undecided;
                }
                break;
            }

            case State.GetAmmo: {
                var r = GetClosestResupplyWith(player, resupply, SupplyItem.Sock);
                if (r == null)
                {
                    s = State.Undecided;
                    return;
                }
                if (!player.IsCloseEnoughToInteractWith(r))
                {
                    s = State.FindAmmo;
                    return;
                }
                Console.WriteLine("Available here: {0}", String.Join(", ", r.Available));
                if (r.Available.Contains(SupplyItem.Sock) && player.InventorySlotsLeft > 1)
                {
                    player.TakeSocksFrom(r);
                    return;
                }
                s = State.Undecided;
                break;
            }

            case State.RunAway: {
                // shift along the state, if we need to.
                switch (go_to)
                {
                case RunState.TopLeft: if (player.Position.X <= player.MapWidth * 0.15 && player.Position.Y <= player.MapHeight * 0.15)
                    {
                        go_to = RunState.TopRight;
                    }
                    break;

                case RunState.TopRight: if (player.Position.X >= player.MapWidth * 0.85 && player.Position.Y <= player.MapHeight * 0.15)
                    {
                        go_to = RunState.BottomLeft;
                    }
                    break;

                case RunState.BottomLeft: if (player.Position.X <= player.MapWidth * 0.15 && player.Position.Y >= player.MapHeight * 0.85)
                    {
                        go_to = RunState.BottomRight;
                    }
                    break;

                case RunState.BottomRight: if (player.Position.X >= player.MapWidth * 0.85 && player.Position.Y >= player.MapHeight * 0.85)
                    {
                        go_to = RunState.TopLeft;
                    }
                    break;
                }
                // check if we're angled correctly.
                double angle = 0;
                switch (go_to)
                {
                case RunState.TopLeft: angle = player.AngleToCoordinates(player.MapWidth * 0.1, player.MapHeight * 0.1); break;

                case RunState.TopRight: angle = player.AngleToCoordinates(player.MapWidth * 0.9, player.MapHeight * 0.1); break;

                case RunState.BottomLeft: angle = player.AngleToCoordinates(player.MapWidth * 0.1, player.MapHeight * 0.9); break;

                case RunState.BottomRight: angle = player.AngleToCoordinates(player.MapWidth * 0.9, player.MapHeight * 0.9); break;
                }
                double dist = 0;
                switch (go_to)
                {
                case RunState.TopLeft: dist = player.DistanceFrom(player.MapWidth * 0.1, player.MapHeight * 0.1); break;

                case RunState.TopRight: dist = player.DistanceFrom(player.MapWidth * 0.9, player.MapHeight * 0.1); break;

                case RunState.BottomLeft: dist = player.DistanceFrom(player.MapWidth * 0.1, player.MapHeight * 0.9); break;

                case RunState.BottomRight: dist = player.DistanceFrom(player.MapWidth * 0.9, player.MapHeight * 0.9); break;
                }
                if (Math.Abs(angle) < 5.0)
                {
                    player.GoForward(dist);
                }
                else
                {
                    player.Turn(angle);
                }
                break;
            }

            case State.Collided: {
                player.GoForward(rand.Next(1, 6));
                s = State.Undecided;
                break;
            }

            case State.AllDone: {
                s = State.Dance0;
                break;
            }

            case State.Dance0: player.Turn(20); s = State.Dance1; break;

            case State.Dance1: player.GoForward(6.0); s = State.Dance0; break;
            }
        }