This worksheet focuses on version control and the Python debugger (pdb
).
These things might be helpful while working on the problems. Remember that for worksheets, we don't strictly limit what resources you can consult, so these are only suggestions.
git
¶Check to see if you have git
already by opening a terminal and entering the command git --version
. One of three things will happen:
git
)git version 2.34.1
(meaning you do have git
)git
. (Please do so, then run the test again.)If after this test you conclude that git is not installed, check one of these sets of instructions and attempt to install it:
Ask your TA if you run into trouble. At the end of the process, you should run the terminal test again and confirm that git
starts and shows its version number.
Recall that we have a simple pygame
game in the course sample code repo. Depending on when your lab is held (Tuesday or Thursday), various additional features may have been added to the game. For this activity, your goals are:
To get started, open a terminal and cd
to a directory (folder) where you want to work. The repository will end up in a new subfolder. Now run one of these commands:
git clone https://github.com/emilydumas/pygame-example-mcs275-spring2024-12pm.git
git clone https://github.com/emilydumas/pygame-example-mcs275-spring2024-1pm.git
Now you should have a subfolder with a rather long name, and it should contain everything from the pygame example (images, code, etc.). Change directory into that one and run git log
to see the log of commits. It should show a bunch of commits and their descriptions.
Now, add something fun and new, then commit your work with git add FILE1 FILE2 FILE3 etc
followed by git commit
.
When you're done, git log
should show your latest commit at the top (with a nice description you wrote after git commit
).
Now it's time to add a new feature. You can check the PyGame home page for some ideas. I am leaving this open-ended so you can explore whatever interests you for the time you are given in lab. Looking at what the pygame examples do and thinking about how features seen there could be adapted to our game is one way to approach this. Here are some other ideas to consider:
w
should warp the player to a random location. Or maybe there should be several player avatars/skins (different PNG images) and pressing /
cycles between them.Most tasks will involve creating some new image assets. I suggest making them with a pixel art editor. Here's a free online one I recommend:
(Use the "export" option to download your work as a PNG file.)
I've added a second demo script to the project 3 solution folder. Download the bstore.py
module and the new bstoredemo2.py
script, and save them to some directory where you'll work:
Run bstoredemo2.py
. It should just print a bunch of lines of text, showing that it adds 5000 integers to a tree of BlockNode
objects. The integers added and their positions are not random; the same sequence of integers and indices are used every time.
Now, open the script in VS Code and add a conditional that detects when the integer 498 is about to be added and prints a message like
Hey, I'm about to add 498 to the tree!
just before that integer is actually inserted. (It should then continue as usual.)
Now, open the program in pdb
using a command like
python3 -m pdb bstore.py
and set a breakpoint on the line that prints the message about 16 being added. Then, continue running the program until the breakpoint is reached.
Once that happens, use a combination of single-stepping and pretty-printing to walk through the insert
function and watch it find a place to put 498
. As you do so, construct a picture of the path it takes through the tree (either on a piece of paper or by taking notes in a text file). Determine the answers to these questions:
idx
) when 498
is added for the first time?insert
function is called? Is the node full?insert
need to split any nodes when inserting 498
for the first time?498
when the insert
function is done (e.g. "left, right, right, left, now it's in .content[2]
")Remember to complete your course evaluations! Your feedback is helpful to us.
If you haven't already done so, you can complete your evaluation in lab today. Ask your TA when they will set aside a time for you and others attending today's lab to do that.