Lab01 will have two phases. - Phase 1 will be installing Python, PyCharm, and PyGame. - Phase 2 will be practicing pseudocode

1 Phase 1: Installing

1.1 on Windows

  1. Install Python 3.8.3:

    1. Download the executable x86-64 installer from python.org.

    2. Run the installer.

    3. Choose the “Custom Installation” option.

    4. If asked, check “Add Python to environment variables” and “Install for all users”; leave all other options at their default values.

  2. Install PyCharm Community Edition 2020.1.1:

    1. Download the executable installer from jetbrains.com.

    2. Run the installer.

    3. If asked, check “Create associations” - “.py”; leave all other options at their default values.

  3. Set up PyCharm and PyGame; see the cross-platform information below.

1.2 on Mac

  1. Install Python 3.8.3:

    1. Download the installer from python.org.

    2. Run the installer.

    3. Choose the “Custom Installation” option.

    4. If asked, check “Add Python to environment variables” and “Install for all users”; leave all other options at their default values.

  2. Install PyCharm Community Edition 2020.1.1:

    1. Download the dmg disk image from jetbrains.com.

    2. Drag the icon to the Applications folder.

  3. Install prerequisites for PyGame

    1. Download and install XQuartz - https://dl.bintray.com/xquartz/downloads/XQuartz-2.7.11.dmg.

    2. Open a Terminal window (/ApplicationsUtilitiesTerminal). In the terminal window, paste the following commands in one at a time and run them individually:

      1. xcode-select --install
      2. ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
      3. alias brew=/usr/local/bin/brew
      4. brew install sdl sdl_image sdl_ttf smpeg portmidi libogg libvorbis
      5. brew install sdl_mixer --with-libvorbis
    3. In the Finder, open /ApplicationsPython 3.8.3 and double-click on the icon for Install Certificates.command

  4. Set up PyCharm and PyGame; see the cross-platform information below.

1.3 On Other Systems

If you are using a system other than Windows or Mac (Linux, FreeBSD, Haiku, etc.), first off, good for you! In general, installing Python, PyGame, and PyCharm is pretty straightforward on these systems (download the Linux version of PyCharm even if you are using a BSD or the like), but if you have trouble post what system you are using on Piazza and we’ll help get you set up.

2 Set up PyCharm and PyGame

There’s a fair bit of set-up, but you should only have to do this once.

  1. Run PyCharm

  2. Accept the default options in the various screens that pop up asking you to set up various aspects of PyCharm. These should only appear the first time you run PyCharm.

  3. When you reach the welcome screen,

    PyCharm welcome screen

    set up PyGame and how Pycharm interacts with Python doing the following:

    1. In the “configuration” menu (gear icon), select “Settings”.

    2. Go to the “Project Interpreter” option on the left of the screen.

      Project interpreter options
    3. If the “Project Interpreter” drop-down on the top of the screen has a “Python 3” of some kind, select it and skip the indented steps below; otherwise

      1. Click the gear icon beside the drop-down (top-right corner of the window) and select “Add Local…” from the menu

      2. In the pop-up window, on the left chose “System Interpreter”

      3. In the drop-down, pick python3.8.3 if it is present; if not, click the “…” button and find where you installed Python.

        Project interpreter selection
      4. Click OK

    4. Click the green + either to the top right or bottom left of the list of packages

      Project interpreter options
    5. In the pop-up window, type pygame in the search bar, select “Pygame” in the left-hand list, and click “Install Package”

      PyGame installation
    6. Wait until an “installation successful” message appears

    7. Click “Apply” and “OK” in each window until back in the welcome screen

      Welcome screen
  4. Click “Create New Project”

  5. In the new project window

    1. Set the Location to some place you can find in your OS’s file browser; suggested:

      • Windows: C:\Users\your-user-name-on-your-computer\Desktop\cs1110
      • OS X: /Users/your-user-name-on-your-computer/Desktop/cs1110
    2. Expand the “Project Interpreter” with the little triangle and pick the “Existing Interpreter” option, with Python 3.6 as the interpreter.

      New project setup window
    3. Click the Create button

  6. Create a new Python file by right-clicking (control-click if you only have one button) on the cs1110 folder in the Project pane on the left side of the window, then pick New → Python File

    New file menu
  7. Type setup_test.py in the new file pop-up

    New file pop-up
  8. In the editor window, type or paste the following:

    import pygame
    import urllib.request
    
    pygame.init()
    urllib.request.urlopen('https://cs1110.cs.virginia.edu')
    
    print('Hello, world!')
  9. Right-click in white space in the editor window (not on any text) and select “Run setup_test” from the drop-down menu.

    Run menu
  10. If you see “Hello, world!” in the second line of the bottom of the window, everything is set up correctly!

    Desired run results

    If you see something else, or if something went wrong along the way, ask a TA for help.


3 Phase 2: Pseudocode - Counting Squares

4 Pairing

For this and all subsequent labs you will work in pairs. You will need your computer, etc, for the paired part of lab. For this lab, we will assign you a partner. You and your partner will be placed in a Breakout Room together. We will use a model called “pair programming” in this class. There are a few things to know about successful pairing under this model:

  • 2 minds, 1 focus. If at any point the two of you are doing distinct things, such as each typing on your own computer or each looking at your own piece of paper, then you are not pairing properly.

  • Driver and Navigator. At any given point in time, one partner will be the “driver”, sharing their screen. The other will be the “navigator,” observing and commenting on the driver’s actions.

  • Equality and Communication. Driver and navigator are equal partners; the ideas of both are equally important, and both should talk, both should listen when the other speaks, and both should treat the other’s ideas with respect.

  • Switch Roles. Which partner is driving should change at least every 15-20 minutes, if not more often.

Pairing in this model has many advantages both from a productivity and learning standpoint. One of these is generally an increase the intensity of focus, which can get tiring. Feel free to take breaks every now and then, but try not to distract other pairs during your breaks.

For more hints on successful pairing, you might want to watch this 10-minute video on your own time: http://youtu.be/rG_U12uqRhE

5 Grid of doors

Picture of door space

For this phase of the lab we will be programming a robot that has been dropped into a grid of square rooms. Each wall of each room has been painted a different color: the North wall is Neon, the East wall is Eggplant, the South wall is Sandy, and the West wall is Wallnut. Walls between rooms have doors in them, but walls on the edge do not. All of the doors are closed initially.

The robot knows how to

  • Check N (or Check E, or S, or W) to see if there is a door on that wall of its current room;
  • Go N (or E or S or W) to move one room over; and
  • Do basic math and remember numbers

If you ask it to Go through a wall that does not have a door, it isn’t smart enough to know it can’t so it will walk into the wall and damage itself.

We won’t be super formal in this lab, but to the degree you can we’d like to see you practice pseudocode, as discussed in class.

5.1 Simple Square

Suppose the robot is dropped into a square grid of rooms and starts in the north-west corner of the grid. Come up with an algorithm that the robot can use to figure out how many rooms are in the grid.

Is there any size grid for which your algorithm does not work? How about on a 1-by-1, or a 1000-by-1000?

In a 3-by-3 grid, how many times will the robot have to move through a door to run your algorithm? How about a 4-by-4? An n-by-n?

Assume that we want to save on robot fuel. Can you make an algorithm that uses fewer moves for the same size grid?

Once you have an algorithm you think is general (works for all size squares) and efficient (uses few moves), type it up and save it in a text file. You’ll submit all your algorithms at the end. Include a simple statement about how many moves it takes, “on an n-by-n grid the robot moves through 2n+5 doors” or something like that.

5.2 Simple Rectangular

Suppose the robot is dropped into a rectangular (not necessarily square) grid of rooms and starts in the north-west corner of the grid. Come up with an algorithm that the robot can use to figure out how many rooms are in the grid.

Type it up and save it on the same text file as before, including a description of the number of moves needed for an n-by-m grid. If your square algorithm still works, you are welcome to submit it again for rectangles.

5.3 General Rectangular

Suppose the robot is dropped into a rectangular (not necessarily square) grid of rooms and might start in any arbitrary room in the grid. Come up with an algorithm that the robot can use to figure out how many rooms are in the grid.

Type it up and save it in the same text file as before, including a description of the number of number of moves your robot will make for an n-by-m grid. Since this will probably depend on the starting location of the robot, just tell us the biggest number you could see (assuming the robot started in the worst possible room).

If one of your previous two algorithms still works, you are welcome to submit it again for general rectangular.

5.4 Stranger Grids

See how general you can make your algorithm. Can you get it to work on diamond-shaped grids of rooms? Grids with more complicated outlines? Grids where some rooms are missing in the middle? Grids where some walls between two rooms that do exist don’t have doors? Arbitrary mazes of rooms?

Type it up and save it in the same text file as before. At the beginning of the submission, include a description of the kinds of grids you think it can handle.

We are not looking for any particular functionality in this step; if you end up with just rectangles, that’s fine, just submit a note to that effect in the form.

Once you have all 4 algorithms done, submit them to the following google page: https://docs.google.com/forms/d/e/1FAIpQLSeJ-vUyx85DcjHdTXfLUaI30jbH8KmoehKEI5-sszLG5pk7Cw/viewform?usp=sf_link