Assignment 0: Pong
- 💯 Worth: 2%
- 📅 Due: See due date on Moodle.
- 🚫 Penalty: Late submissions lose 10% per day to a maximum of 3 days. Nothing is accepted after 3 days and a grade of 0% will be given.
🎯 Objectives
- Read and understand all of the Pong notes and source code from Lecture 0.
- Implement a basic AI for either Player 1 or 2.
🔨 Setup
- Fork (do not download as a zip) the starter repository from GitHub. Make sure you use the link from Moodle to fork the proper repository for this assignment.
- Start Live Server in VSC by right-clicking on
index.html
and selecting Open with Live Server. This will open a new tab in your browser with the game running.
🎥 Demo
🔍 Context
Your first assignment in the course will be a fairly easy one, since the dive into game development 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 learned in class and extend it in a small but fun way by giving one of the paddles logic for playing the game so that you don’t always need a buddy to play the game with you. We’ll approach problem sets in the course this way generally, taking the full code bases we’ve used in lecture and extending them so that you’ll get plenty of experience exploring fully implemented games. You can even use these projects as templates for your own games!
Once you’ve cloned the repo, the actual change you’ll be making to the code base is small, but it will require you to understand what many of the pieces do, so be sure to review the lecture notes 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.js
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?
Implement an AI-controlled paddle (either the left or the right will do) such that it will try to hit 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 start thinking about how to implement the AI feature. Once either the left or right paddle tries to hit the ball on their own, you’ve done it! By the way, you don’t have to worry about the AI being beatable.
Lastly, this assignment can technically be done in one line. This will get you most of the points, but if you’re looking to get 100, then I want to see you thinking like a 3rd year CS student. I’ll be looking for how you use advanced programming constructs (ex. functions/classes) in your solution.
🌿 Git
We will be using GitHub and Gradescope to submit in this course. You can use either the Git CLI or you can also use VSC’s built-in Git GUI client.
🖱️ GUI
- In VSC, click on the third icon down in the left navigation bar to see a list of files that have changed and are ready to be staged.
- Hover over where it says Changes (right below the commit textbox) and click
+
to stage all the modified files to be committed. Alternatively, you can add specific files by clicking the+
next to the individual file. - Type a commit message into the textbox and click the checkmark above it to commit all the files that were just staged.
- Click
...
and thenpush
to push the commit(s) up to GitHub.
⌨️ CLI
- Run
git status
to see a list of files that have changed and are ready to be staged. - Run
git add .
to stage all the modified files to be committed. Alternatively, you can add specific files like this:git add src/Paddle.js
. - Run
git commit -m "A descriptive message here."
(including the quotes) to commit all the files that were just staged. - Run
git push
to push the commit(s) up to GitHub.
Regardless of the method you choose, it is very important that you commit frequently because:
- If you end up breaking your code, it is easy to revert back to a previous commit and start over.
- It provides a useful log of your work so that you (and your teammates if/when you’re on a team) can keep track of the work that was done.
📥 Submission
Once you’ve made your final git push
to GitHub, here’s what you have to do to submit:
- Go to Gradescope and click the link for this assignment.
- If you don’t have access to Gradescope, you need to accept the invitation in your JAC email.
- Select the correct GitHub repository and branch from the dropdown menus.
- Click Upload.