Pong
Objectives
- Read and understand all of the Pong source code from Lecture 0.
- 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/project0.zip and unzip project0.zip, which should yield a directory called project0.
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 project0 (recall that the cd command can change your current directory), and run
cd project0
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!
Errata
NONE
How to Submit
- Download a ZIP file containing your implementation of this project.
- Go to CSCI E-23a’s Gradescope page.
- Click Pong.
- Drag and drop your downloaded file to the area that says “Drag & Drop”.
- Click Upload.
You should see a message that your project was submitted successfully. Contact your teaching fellow if not!