예제 #1
0
        /// <summary>
        /// Moves the paddle.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <returns></returns>
        public PaddleMoveDirection MovePaddle(IPongEnvironmentContext context)
        {
            var ballIsMovingAway = (m_isLeftPaddle ^ (m_lastBallX > context.BallX));

            m_lastBallX = context.BallX;
            int targetY;

            if (ballIsMovingAway)
            {
                targetY = m_centerY;
            }
            else
            {
                targetY = context.BallY;
            }

            if (context.MyPaddleY > targetY)
            {
                return(PaddleMoveDirection.Up);
            }
            else if (context.MyPaddleY < targetY)
            {
                return(PaddleMoveDirection.Down);
            }
            else
            {
                return(PaddleMoveDirection.Stop);
            }
        }
예제 #2
0
 /// <summary>
 /// Moves the paddle.
 /// </summary>
 /// <param name="context">The context.</param>
 /// <returns></returns>
 public PaddleMoveDirection MovePaddle(IPongEnvironmentContext context)
 {
     if (context.MyPaddleY > context.BallY)
     {
         return(PaddleMoveDirection.Up);
     }
     else if (context.MyPaddleY < context.BallY)
     {
         return(PaddleMoveDirection.Down);
     }
     else
     {
         return(PaddleMoveDirection.Stop);
     }
 }