/// <summary> /// Passes the specified ball to the specified player. Sets the kick vector accordingly. /// </summary> /// <param name="ball">The ball.</param> /// <param name="passTarget">The pass target player.</param> /// <returns>The kick target.</returns> public Vector PassBall(FootballBall ball, FootballPlayer passTarget) { var time = ball.GetTimeToCoverDistance(Vector.GetDistanceBetween(ball.Position, passTarget.Position), MaxKickSpeed); var nextPos = passTarget.PredictPositionInTime(time); KickBall(ball, nextPos); return(nextPos); }
/// <summary> /// Kicks the ball to the specified target with the specified kick speed. Sets the kick vector accordingly. /// </summary> /// <param name="ball">The ball.</param> /// <param name="target">The kick target.</param> /// <param name="kickSpeed">The kick speed.</param> public void KickBall(FootballBall ball, Vector target, double kickSpeed) { if (kickSpeed > MaxKickSpeed) { kickSpeed = MaxKickSpeed; } KickVector = new Vector(ball.Position, target, kickSpeed); }
/// <summary> /// Parses the specified binary representation of the game state. /// </summary> /// <param name="data">The binary representation of the game state.</param> /// <returns> /// The parsed <see cref="GameState"/>. /// </returns> /// <exception cref="ArgumentException">Thrown if an error has occurred while parsing the game state.</exception> public static GameState Parse(byte[] data) { var floatData = new float[92]; var stepData = new int[1]; if (data.Length != floatData.Length * 4 + 4 + 1) { throw new ArgumentException("Invalid game state data."); } Buffer.BlockCopy(data, 0, stepData, 0, 4); Buffer.BlockCopy(data, 5, floatData, 0, (data.Length - 5)); var players = new FootballPlayer[22]; for (var i = 0; i < 22; i++) { players[i] = new FootballPlayer(i); } var ball = new FootballBall() { Position = new Vector(floatData[0], floatData[1]), Movement = new Vector(floatData[2], floatData[3]) }; for (var i = 0; i < 22; i++) { players[i].Position = new Vector(floatData[4 + 4 * i], floatData[4 + 4 * i + 1]); players[i].Movement = new Vector(floatData[4 + 4 * i + 2], floatData[4 + 4 * i + 3]); } return(new GameState() { Ball = ball, FootballPlayers = players, Step = stepData[0], KickOff = data[4] == 1 }); }
/// <summary> /// Kicks the ball to the specified target with the maximum kick speed. Sets the <see cref="KickVector"/> accordingly. /// </summary> /// <param name="ball">The ball.</param> /// <param name="target">The kick target.</param> public void KickBall(FootballBall ball, Vector target) { KickBall(ball, target, MaxKickSpeed); }
/// <summary> /// Determines whether the player can kick the specified ball. /// </summary> /// <param name="ball">The ball.</param> /// <returns> /// <c>true</c> if the player can kick the specified ball; otherwise, <c>false</c>. /// </returns> public bool CanKickBall(FootballBall ball) { return(Vector.GetDistanceBetween(Position, ball.Position) <= FootballBall.MaxDistanceForKick); }