/// <summary> /// Define Ball Y position relative to responding player of current rod and /// re define index of responding rod setting the property Responding Player /// </summary> /// <param name="yBallCoordinate">Current ball Y coordinate</param> /// <param name="currentRod">Current rod</param> /// <param name="playerToResponse">Responding player[out] (index base is 0)</param> /// <returns>Ball Y position relative to responding player</returns> protected eYPositionPlayerRelative BallYPositionToPlayerYCoordinate(int yBallCoordinate, IRod currentRod) { //set default responding player RespondingPlayer = -1; //get array of players and their Y coordinates (player i stored in array index i - 1) int[] currentPlayerYs = _helper.AllCurrentPlayersYCoordinates(currentRod, currentRod.State.DcPosition); //calculate movements for each player to reach the ball (Y Axe only) int[] movements = _helper.CalculateYMovementForAllPlayers(currentPlayerYs, yBallCoordinate); //convert movement to distance on Y Axe (Absolute value) int[] absoluteDistance = movements.Select(x => Math.Abs(x)).ToArray(); //get index of fist minimal distance (movement is here: movements[minIndexFirst]) int minIndexFirst = Array.IndexOf(absoluteDistance, absoluteDistance.Min()); //eliminate the first minimal distance absoluteDistance[minIndexFirst] = TABLE_WIDTH * 100; //get index of second minimal distance (movement is here: movements[minIndexSecond]) int minIndexSecond = Array.IndexOf(absoluteDistance, absoluteDistance.Min()); //chosen movement to perform int movement = 0; //Define actual player to response if (_helper.IsEnoughSpaceToMove(currentRod, currentRod.State.DcPosition, movements[minIndexFirst])) { //as index starts from 0 => first one is 1 RespondingPlayer = minIndexFirst + 1; movement = movements[minIndexFirst]; } else { //as index starts from 0 => first one is 1 RespondingPlayer = minIndexSecond + 1; movement = movements[minIndexSecond]; } //In case we reach the ball - no move needed if (Math.Abs(movement) < PLAYER_WIDTH) { return(eYPositionPlayerRelative.CENTER); } else if (movement > 0) { return(eYPositionPlayerRelative.RIGHT); } else // (movement < 0) { return(eYPositionPlayerRelative.LEFT); } }
public void IsEnoughSpaceToMove_Positive_Move50() { Assert.IsTrue(_testAsset.IsEnoughSpaceToMove(_rodGoalKeaper, 30, 50)); }