This paper illustrates how a 3 degrees of freedom, Cartesian robot can be given the task of playing ping pong against a human player. We present an algorithm based on particle swarm optimization for the robot to calculate when and how to hit an approaching ball. Simulation results are shown to depict the effectiveness of our approach. Although emphasis is placed on sending the ball to a desired point on the ping pong table, it is shown that our method may be adjusted to meet the requirements of a variety of ball hitting strategies.