Hacker News new | ask | show | jobs
by klyrs 2253 days ago
My first game was a homework assignment: write a 1-player pong game (like arkanoid without the bricks). I juiced it up a bit by adding a second "AI" player with a very rudimentary ball-following algorithm.

  if (ai.x - pad > ball.x)
     move_ai(-max_speed);
  else if (ai.x + pad < ball.x)
     move_ai(max_speed);
... or something like that, with some bounds checking and some logic for smaller moves. Bottom line, "just an if/then statement" can be sufficient to make a playable game with a challenging (or even unbeatable) computer player. Tic tac toe is another example of this.