/// <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> /// 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 }); }