Pong

Objectives

  • Implement a basic AI for either Player 1 or 2 (or both!).

Your First Game

Download the distribution code for your game from cdn.cs50.net/2d/2025/x/projects/0/pong.zip and unzip pong.zip, which should yield a directory called pong.

Then, in a terminal window (located in /Applications/Utilities on Mac or by typing cmd in the Windows task bar), move to the directory where you extracted pong (recall that the cd command can change your current directory), and run

cd pong

It’s Game Time

Your first assignment in the course will be a fairly easy one, since the dive into game programming can be deep enough as it is without having to implement an entire code base from scratch! Instead, we’ll take the Pong example we covered in class and extend it in a small but fun way by giving one of the paddles (or perhaps both) logic for playing the game so that you don’t always need a buddy to play! We’ll approach problem sets in the course this way generally, taking the full codebases we’ve used in lecture and extending them so that you’ll get plenty of experience interacting with fully implemented games. You can even use these projects as templates and jumping boards for your own games!

Of course, the code won’t run if you don’t have LÖVE installed, so we’ll have to tackle that in addition to grabbing the code, so please choose the appropriate distribution of that version for your system here:

https://love2d.org

For further information on how to actually run games, do just visit the following page:

https://love2d.org/wiki/Getting_Started

Once the code and LÖVE have been downloaded and installed, the actual change you’ll be making to the codebase is small, but it will require you to understand what many of the pieces do, so be sure to watch Lecture 0 and read through the code so you have a firm understanding of how it works before diving in! In particular, take note of how paddle movement works, reading both the Paddle class as well as the code in main.lua that actually drives the movement, located in the update function (currently done using keyboard input for each). If our agent’s goal is just to deflect the ball back toward the player, what needs to drive its movement?

Specification

  • Implement an AI-controlled paddle (either the left or the right will do) such that it will try to deflect the ball at all times. Since the paddle can move on only one axis (the Y axis), you will need to determine how to keep the paddle moving in relation to the ball. Currently, each paddle has its own chunk of code where input is detected by the keyboard; this feels like an excellent place to put the code we need! Once either the left or right paddle (or both, if desired) try to deflect the paddle on their own, you’ve done it!

Errata

NONE

How to Submit

When you submit your project, the contents of your branch must match the file structure of the unzipped distribution code exactly as originally received. That is to say, your files should not be nested inside of any other directories of your own creation or otherwise deviate from the file structure we gave you. Your branch should also not contain any code from any other projects, only this one. Failure to adhere to this file structure will result in your submission being rejected.

  1. Visit this link, log in with your GitHub account, and click Authorize cs50. Then, check the box indicating that you’d like to grant course staff access to your submissions, and click Join course.
  2. Install Git and, optionally, install submit50.
  3. Using Git, push your work to https://github.com/me50/USERNAME.git, where USERNAME is your GitHub username, on a branch called games50/projects/2025/x/pong or, if you’ve installed submit50, execute

    submit50 games50/projects/2025/x/pong
    

    instead.

  4. Record a screencast, not to exceed 5 minutes in length in which you demonstrate your game’s functionality. Upload that video to YouTube (as unlisted or public, but not private). This video’s requirements are:
    • It is not a YouTube “short”.
    • The video begins with a slide or text overlay containing both your edX and GitHub usernames.
    • It must show your game live and in action. Do not use this video to walk us through any code.
    • It demonstrates that all item of the specification (here, 1 requirement) has been implemented.
    • The video description has been timestamped at the (first) point where your video demonstrates the above-referenced implementations.
    • The video has been uploaded less than one month from the time of your submission of the form for this project (the final step below).
  5. Submit this form.

You can then go to https://cs50.me/cs502d to view your current progress!