A document from MCS 275 Spring 2024, instructor Emily Dumas. You can also get the notebook file.

MCS 275 Spring 2024 Worksheet 15

  • Course instructor: Emily Dumas

Topics

This worksheet focuses on version control and the Python debugger (pdb).

Resources

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.

1. Install 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:

  1. You'll get an error message (meaning you do not have git)
  2. You'll get a one-line message like git version 2.34.1 (meaning you do have git)
  3. You have a Mac and it opens a window asking if you'd like to install something that includes 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:

  1. From the git home page
  2. Guide from GitHub

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.

2. Clone and modify the sample game

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:

  • make a local clone of the git repository
  • add at least one feature to the game (testing it, of course)
  • commit your changes
  • view the log of commits

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:

  • Students in 12pm lecture
    git clone https://github.com/emilydumas/pygame-example-mcs275-spring2024-12pm.git
    
  • Students in 1pm lecture
    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).

Feature ideas

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:

  • New keyboard controls: Perhaps 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.
  • Walls: Make a black and white PNG image of the same size as the game window. Arrange it so the image is loaded at the start and drawn on the display surface during each game loop. Make it so that the player can only move to a location if the background is white at that position. Thus, black areas effectively become walls.
  • Buddy drone: Make a small flying robot that orbits the player slowly. That means the flying robot is represented by a small sprite and it moves in a circular pattern centered at the player's position (which, you must remember, changes!)

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.)

3. Debugging practice

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:

  • What is the index (value of idx) when 498 is added for the first time?
  • What integers are already stored in the node that contains that data index when the insert function is called? Is the node full?
  • Does insert need to split any nodes when inserting 498 for the first time?
  • Describe the path from the root to the node containing 498 when the insert function is done (e.g. "left, right, right, left, now it's in .content[2]")

Complete your course evaluations

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.

Revision history

  • 2024-04-21 Initial release