Week 10 Lab: Programming with AI
Git Repository: https://classroom50.org/lis875/lis-875-f26/assignments/ai/accept
For this week ONLY, you are welcome, encouraged, and required to use AI tools (ChatGPT, Gemini, Copilot, Claude, etc.) to help you with your coding.
Today we are going to try out a couple of different ways of using AI to help us with our python programming. I am not here to tell you what to do or not do; instead, I am going to help you figure out a couple of different ways to use AI and let you think about for yourself what the best way to us it is.
Before getting set up, be sure to clone today’s git repository onto your computer first.
For today’s exercises, we are going to use GitHub Copilot as our AI backend, which the university subscribes to. There are 2 different ways to use it: You can either use it via VS Code (it appears as a chat interface on the right side of Code), or you can use it on the command line as a stand-alone tool.
Installing the Standalone Copilot tool
If you want to use it on the terminal / command line, then you will need the standalone copilot tool. This can be installed using a simple command line; copy-and-paste this onto your command line:
Windows:
winget install GitHub.Copilot
Mac OS:
curl -fsSL https://gh.io/copilot-install | bash
Once you’ve run this, you should have copilot installed. Copilot is very sensitive to what directory it is in when it is run. Be sure you first cd into the directory that contains your cloned git repository. Once it is installed, run it with the command:
copilot
When you first run it, it will ask some questions. Answer them the best you can.
It should open an interface on the terminal where you can interact with the chatbot. Start by logging in:
/login
It should ask you a questino or two, then open a web page for you to log into github and approve permissions for it.
Installing Copilot on VS Code
If you use VS Code, copilot integration comes built-in to the editor. By default, when you use VS Code, copilot is turned on. However, you may have previously turned it off.
To turn Copilot back on, look for the copilot icon in the bottom right hand corner of VS Code. It looks like a weird face. Click it. Make sure “ghost text suggestions” and “ghost text suggestions for python” are enabled.
Once it is enabled, it is important to give it a context – a folder to work in. So go to “File” –> “Open Folder” (or choose the “Open Folder” button) and then choose the folder that you just created when you cloned your git repository. This way, copilot knows where to work and what code to work on.
Using AI as an employee (aka Vibe Coding)
First, we are going to use AI to do some vibe coding. We are going to ask AI to do ALL of the programming work. We will give it a very vague prompt – similar to how I give you a vague prompt for a studio – and let copilot make all of the decisions.
Exercise 1: Simple Tic-Tac-Toe
We are going to try to get Copilot to create a simple tic-tac-toe program, much like we did in a previous studio. To do this, we have to ask copilot to create a new python file, tell it to use turtle, and tell is the program we want to create. Here is the prompt I used; try this:
Create a new file called ttt.py that implements a basic tic-tac-toe program using turtle.
It should draw a grid, ask the user which square, draw an X in that square, ask the user
which square, draw an O in that square, and repeat until all 9 squares are filled in.
Let copilot run until it says it is done. Then open up the file it creates (called ttt.py) in your editor. Look through the code. Can you read the code? Does it look reasonable? Does it look like the code you wrote a couple of weeks ago for the studio?
Next, let’s run the program. Either press play (VS Code) or go to the command line and run the newly created ttt.py file. Does it work? Can you play tic-tac-toe?
You may get something different than I did, but most likely copilot was able to actually produce some code that works and runs, and it even looks like tic-tac-toe!
Exercise 2: Better Tic-Tac-Toe Drawings
Let’s try asking Copilot to make a change: instead of using the standard X’s and O’s, let’s use smiley faces and frowny faces. Let’s try to ask copilot and see if can make this change.
You can write your own prompt if you like, but here is the one I used:
Rather than X and O, can you make it into a smiley face and a frowny face?
As before, let’s start by looking at the code. Can you read the code and understand what it is doing?
Then, let’s run the program. Does it run? Does it draw faces instead of X’s and O’s? Is this a reasonable tic-tac-toe program?
Exercise 3: Creative Tic-Tac-Toe
Next, let’s see if copilot can be more creative. In the original studio, I recommended that you use something more interesting than X’s and O’s for your tic-tac-toe program. You thought about it and came up with something – that is, you were creative and decided something interesting but easy to implement. Let’s see what happens if we ask copilot to be creative. Let’s give copilot the instructions that I gave you – ask it to come up with something creative but don’t tell it what.
Here is the prompt I used:
OK, I need something more interesting than X's and O's, or faces.
Choose a more creative thing to use and implement that.
What happened? Is what it did particularly creative? If you were grading this on creativity, what kind of grade would you give it?
When I did it, it gave me rockets and aliens, using simple drawings of each. This is OK; yes, it is more interesting than X’s and O’s. But it isn’t really creative: it uses a simple trope that is common among kids, but doesn’t take into account any larger context in the class or in the world; it uses a science fiction trope that is popular among programmers but less popular in the general public; it is very simple and not really able to hold my interest at all. For a class, I’d give it a C – not a failing grade, but uninspired. If I were making a game that I wanted to sell in the real world, it would never sell and would deserve an F.
What kind of grade would you give yours?
Exercise 4: Winning Tic-Tac-Toe
In the studio, I instructed you that trying to write code to detect when someone had won the game was more complicated (and you didn’t have to do it). Do you think AI could do this? Let’s find out. Write a prompt asking Copilot to add a check to the game to see when someone has won. You can write this prompt on your own. Give it to Copilot and check on what it produces. Look at the code, and run the program. Does it work?
Reflection 1: Vibe Coding
You have successfully vibe coded a tic-tac-toe program. Now I want you to reflect on this experience. How did it go?
I specifically want you to open up a file – either a plain text file or a google doc / word doc – and write down your answers to a couple of questions.
- Did the program you produced work? Did you have to do anything special to get the AI to produce working code?
- Can you read and understand the code that was written? Do you know what everything does and why it is there, or is the code confusing and unclear?
- Was the AI creative? Was the AI able to take your prompts and make them more interesting than you had hoped?
- Did you feel like you were acting like a centaur, or a reverse centaur? That is, would you be OK being responsible for the programs the AI wrote (and being fired if the programs aren’t good / have too many bugs)?
Using AI auto-complete
Let’s create the same program, but using auto-complete. This way, we can make changes, monitor what the AI is doing, and read the code to make sure we understand it.
With auto-complete, you are the one writing the program. You decide what file to create, what functions to write, what to name things, and what order to do them in. Copilot watches what you type and suggests what might come next, shown as gray “ghost text.” Nothing goes into your program unless you accept it.
VS Code
Auto-complete only works inside VS Code. The standalone command-line tool can’t do this, so if you used the command line for the first part, open VS Code now.
A few keys you will use a lot:
| Key | What it does |
|---|---|
Tab | Accept the whole suggestion |
Esc | Reject the suggestion |
Ctrl + → (Mac: Cmd + →) | Accept just the next word |
Alt + ] (Mac: Option + ]) | Show a different suggestion |
| Just keep typing | Ignore the suggestion |
One important warning: Copilot reads the other files you have open to decide what to suggest. If ttt.py from the first part is still open, Copilot will probably just copy it back to you. Close ttt.py before you start. (If you want to see this for yourself, try it once with the file open and once with it closed.)
Command-line
I recommend trying to use VS Code for this. If you really want to use the command line, you can, but you’ll need to open up Copilot on the command line, manually edit your file (save it!), and then explicitly ask copilot to make a suggestion for the imcomplete function.
Exercise 5: Comments First
Create a new file called ttt_auto.py. Instead of writing code right away, start by writing a comment that says what you want the next few lines to do, then press Enter and wait a moment.
Start with this:
from turtle import *
# set turtle speed to the fastest setting
Copilot should suggest a line or two. Before you press Tab, read the suggestion. Is it what you would have written? If so, accept it. If not, press Esc and write it yourself, or use Alt+] to see a different suggestion.
As you go, keep a simple tally on a piece of paper or in a text file:
- Accepted: you took the suggestion as it was
- Edited: you took it but then changed something
- Rejected: you threw it away
You will use this tally in the reflection.
Exercise 6: You Design, AI Fills In
When we wrote tic-tac-toe in the studio, we broke the problem into functions. Let’s do that again. This time you write the first line and a docstring for each function, and let Copilot suggest the body.
Type this in.
def draw_grid(size):
"""Draw a 3x3 tic-tac-toe grid centered on the screen.
Each square is size pixels wide."""
Once you’ve typed it in, let Copilot suggest the body. Look at its suggestion. Does it look reasonable?
Next, run your program to test that function before you move on to the next one. Let’s see if the draw_grid() function works correctly and looks OK.
Exercise 7: Use Comments as Prompts
You can also use comments and prompts. In the draw_grid() function you just created, let’s try to change whether it draws a border around the grid. For example, if the AI produced a draw_grid() function that does NOT include a border around the grid, you can try to have it ask one. At the end of the code, add a comment (starting with a # symbol) that describes how you want to have a border:
# Put a border around the grid
Then use the auto-complete features to see what code it writes. Notice how you can use comments basically as prompts for the AI autocomplete. If you change the comment, how does it change the code it tries to write / autocomplete?
Exercise 8: More Tic-Tac-Toe Functions
Let’s see if we can get autocomplete to write a couple more functions:
def square_to_xy(square, size):
"""Convert a square number (1-9, numbered left to right, top to bottom)
into the (x, y) location of the center of that square."""
def draw_x(x, y, size):
"""Draw an X centered at (x, y)."""
def draw_o(x, y, size):
"""Draw an O centered at (x, y)."""
Do each of these one at a time. Enter the name and description of each function, and then see if the code the AI writes makes sense.
After writing each function, you will want to try it out and see if it works. For example, after creating the draw_x() function, add a line near the end of the program that calls it. Then run the program and see if it draws an X properly.
Exercise 9: Complete Tic-Tac-Toe
Then write the main loop that asks the user for a square and draws an X or an O there. You can write a comment for the loop and see what Copilot suggests, or write it yourself.
Remember that you can use # comments to prompt it to help you write code. Use that for writing the main loop of the program.
Exercise 10: Your Own Creative Idea
Earlier, we asked Copilot to be creative and replace the X’s and O’s with something more interesting. And it wasn’t very creative. Now let’s switch roles: you supply the creativity, and Copilot helps with the typing.
Think back to what you used instead of X’s and O’s in your studio (or come up with something new). Write a function for each of your two shapes. Before you write any code, write out in comments the steps to draw your shape, for example:
def draw_cat(t, x, y, size):
"""Draw a simple cat face centered at (x, y)."""
# draw a circle for the head
# draw two triangles for the ears
# draw two small dots for the eyes
# draw three lines on each side for the whiskers
Then go through it one step at a time, letting Copilot fill in under each comment. Swap your new shapes in for draw_x and draw_o.
How does your game compare to the one Copilot made on its own in Exercise 3? Whose idea was it? Who did the work?
Reflection 2: AI Auto-complete
Go back to the file where you wrote your answers to the first reflection, and answer the same four questions again, this time about using AI auto-complete:
- Did the program you produced work? Did you have to do anything special to get the AI to produce working code?
- Can you read and understand the code that was written? Do you know what everything does and why it is there?
- Was the program creative? Where did the creativity come from?
- Did you feel like you were acting like a centaur, or a reverse centaur? Would you be OK being responsible for this program?
Then answer a few new questions:
- Look at your tally. About how many suggestions did you accept, edit, and reject? What kinds of suggestions did you usually accept? What kinds did you usually reject?
- Was there ever a time you pressed
Tabon something you didn’t fully understand? What happened? - Did auto-complete change what you would have written? Did it ever talk you into doing something a different way?
- Was this faster or slower than vibe coding? Faster or slower than writing it all yourself? Is speed the right thing to care about?
Using AI as a Navigator
In all of the above exercises, we used AI primarily as a way to write code. But AI can do more than write – it can read code also! And, it can provide advice. That is, it is entirely reasonable to use the AI as a navigator, and not just a driver, to help you think through your program and write code.
To do that, start by thinking about what kinds of things you do when you are a navigator, and what kinds of help you get from your navigator when you are driving. What kinds of work do navigators do?
Let’s try to see if we can add some code that will detect when one player wins the game. What would you need to add to the program to do this? For these exercises, do NOT let the AI write any code. YOU are the driver and you will write the code. But, you can use the AI to get help and thoughts and assistance.
Exercise 11: Develop a Plan to Detect When Someone Wins
When working with your partner as a navigator, one thing that you often do is talk through a plan – what needs to be done? Let’s try doing that with your AI assistant.
Start by asking Copilot what you would need to do. It is fine to add your own thoughts along the way, but then ask Copilot for additional thoughts and ideas. For example, you could prompt it:
I would like to add the ability to figure out when someone has won. I know I need to keep track of moves.
Without writing any code, what would I need to do?
Go back and forth with Copilot and see if you can develop a plan. What pieces of code will you need to add? Are there functions that you’ll need to add? Are there places you will need to add lines of code, but not a separate function?
Your goal for this exercise is not to actually write any code; it is just to make a plan and figure out what code you will need to write.
Remember, you don’t need the AI to come up with the answer. The important part is that you have a list of all the things that you need to write. The AI is just there to help. Just like working with your partner as navigator. And just like working with a partner, it is a good idea to share your own thinking with the AI, so it knows what you are thinking.
Reflection: How to use AI?
Go back to the file where you wrote your answers to the previous reflections, and answer the same four questions again, this time about using AI as navigator:
- Did the program you produced work? Did you have to do anything special to get the AI to be helpful?
- Can you read and understand the code that was written? Do you know what everything does and why it is there?
- Was the program creative? Where did the creativity come from?
- Did you feel like you were acting like a centaur, or a reverse centaur? Would you be OK being responsible for this program?
Then answer a few new questions:
- Was this faster or slower than vibe coding? Faster or slower than writing it all yourself? Is speed the right thing to care about?
- What kinds of navigator questions was the AI most helpful with? What kinds of navigator questions did the AI get wrong, or was not helpful with?
Finally, answer one final question:
We tried to use AI in 3 different ways – vibe-coding, AI as auto-complete, and AI as navigator. If you were writing a tic-tac-toe program professionally, in the real world – one where bugs would cause you to lose money and/or get fired, but you are also paid by your productivity and how fast you get the code written – which strategy would you use?
Optional Challenge: Names Matter
Copilot only knows what you want from the words you type. Let’s see how much the names you choose matter.
At the bottom of your file, type this and see what Copilot suggests:
def f(a, b, c):
Now delete it and type this instead:
def draw_smiley(x, y, size):
"""Draw a smiley face centered at (x, y), size pixels across."""
How different are the two suggestions? What does that tell you about who is actually making the decisions when you use auto-complete?