/// <summary>Creates a player path.</summary>
        public static PlayerPath Create(Position player, Velocity velocity, IPoint target, int fallenTimer, int maxLength, Distance tolerance)
        {
            var path = new PlayerPath();

            for (var fallen = fallenTimer; fallen < 0; fallen++)
            {
                path.Add(player);
            }

            var pos = player;
            var vel = velocity;

            for (var turn = -fallenTimer; turn < maxLength; turn++)
            {
                if (Distance.Between(pos, target) < tolerance)
                {
                    path.ReachedTarget = true;
                    break;
                }
                path.Add(pos);
                pos += vel;
                vel  = NewVelocity(vel, pos, target);
            }
            return(path);
        }
Example #2
0
        /// <summary>Gets the catch ups for the path.</summary>
        public static IEnumerable <CatchUp> GetCatchUps(List <Position> path, int pickUpTimer, IEnumerable <PlayerInfo> players)
        {
            var queue = new Queue <PlayerInfo>(players);

            for (var turn = pickUpTimer; turn < path.Count; turn++)
            {
                if (queue.Count == 0)
                {
                    break;
                }
                for (var p = 0; p < queue.Count; p++)
                {
                    var player = queue.Dequeue();
                    // the player can not run yet.
                    if (-player.FallenTimer > turn)
                    {
                        queue.Enqueue(player); continue;
                    }

                    var distanceToBall = Distance.Between(path[turn], player.Position);
                    var speed          = PlayerPath.GetInitialSpeed(player, path[turn]);
                    var playerReach    = PlayerPath.GetDistance(speed, turn + player.FallenTimer, 40);

                    if (distanceToBall <= playerReach)
                    {
                        yield return(new CatchUp()
                        {
                            Turn = turn,
                            Player = player,
                            Position = path[turn],
                        });
                    }
                    else
                    {
                        queue.Enqueue(player);
                    }
                }
            }
        }