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:
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!
Be sure to comment your code in the place(s) where you implement the AI functionality. This is true for all implementations, but particularly if you do so in a spot we aren’t expecting you to.
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.
By way of a simple example, for this project that means that if the grading staff visits https://github.com/me50/USERNAME/blob/games50/projects/2025/x/pong/main.lua (where USERNAME is your own GitHub username as provided in the form, below) we should be brought to your main.lua file for Pong. If that’s not how your code is organized when you check (e.g., you get a 404 error or don’t see your edits), reorganize your repository as needed to match this paradigm. Code improperly organized will not be eligible for a passing score.
- 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.
-
Install Git and, optionally, install
submit50. -
Using Git, push your work to
https://github.com/me50/USERNAME.git, whereUSERNAMEis your GitHub username, on a branch calledgames50/projects/2025/x/pongor, if you’ve installedsubmit50, executesubmit50 games50/projects/2025/x/ponginstead.
-
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).
- Submit this form.
You can then go to https://cs50.me/cs502d to view your current progress!