Tenis game logic

Hi
i am not getting the logic as how to hit the ball and adjust the speed of the ball ,
and how the AI will behave accordingly and in which case AI fail to hot the ball

IF any one is having any ALGO for tennis kindly share with me