/// <summary>
        /// Determines whether the shot on goal from the specified position is possible.
        /// </summary>
        /// <param name="position">The position.</param>
        /// <returns>
        ///   <c>true</c> if a shot on goal from the specified position is possible; otherwise, <c>false</c>.
        /// </returns>
        private bool IsShotOnGoalPossible(Vector position)
        {
            // we expect the lowest possible max kicking power of the player

            var artificialPlayer = new FootballPlayer(0)
            {
                Position = position
            };
            var artificialBall = new FootballBall()
            {
                Position = position
            };

            Vector shotTarget;

            return(AI.MyTeam.TryGetShotOnGoal(artificialPlayer, out shotTarget, artificialBall));
        }
        /// <summary>
        /// Tries to get the shot on goal with the specified ball. The shot must be safe from opponent.
        /// </summary>
        /// <param name="player">The player.</param>
        /// <param name="shotTarget">The shot target.</param>
        /// <param name="ball">The ball.</param>
        /// <returns>
        ///   <c>true</c> if <paramref name="shotTarget"/> was set; otherwise, <c>false</c>.
        /// </returns>
        public bool TryGetShotOnGoal(FootballPlayer player, out Vector shotTarget, FootballBall ball)
        {
            for (int i = 0; i < Parameters.NumberOfGeneratedShotTargets; i++)
            {
                var target =
                    new Vector(0, GameClient.FieldHeight / 2.0 + (FsmAI.Random.NextDouble() - 0.5) * 7.32 / 2);
                if (IsOnLeft)
                {
                    target.X = GameClient.FieldWidth;
                }

                if (IsPassPossible(player, target, ball) && IsPassSafe(player, target))
                {
                    shotTarget = target;
                    return(true);
                }
            }

            shotTarget = null;
            return(false);
        }
Exemple #3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Ball"/> class.
 /// </summary>
 /// <param name="ball">The football ball.</param>
 public Ball(FootballBall ball)
 {
     Position = ball.Position;
     Movement = ball.Movement;
 }
 /// <summary>
 /// Determines whether the pass from the specified player to the specified target is possible.
 /// </summary>
 /// <param name="player">The player.</param>
 /// <param name="target">The target.</param>
 /// <param name="ball">The ball.</param>
 /// <returns>
 /// <c>true</c> if the pass from the specified player to the specified target is possible; otherwise, <c>false</c>.
 /// </returns>
 public bool IsPassPossible(FootballPlayer player, Vector target, FootballBall ball)
 {
     return(!double.IsInfinity(
                ball.GetTimeToCoverDistance(Vector.GetDistanceBetween(ball.Position, target), player.MaxKickSpeed)));
 }