14.2 Final Project


Writing Python without AI

Many of you used AI to create your first Python program, but this is not helping you learn the python language. It’s like using training wheels to ride your bike to school or work every day, or taking a taxi. If you want to learn how to ride a bike, drive a car, or write a Python program, you don’t ask someone else or a machine to write it for you. Your need to train the muscle memory in your brain to be able to communicate your ideas in Python through your fingers on the keyboard. And you need to train the creative part of your brain to learn how to compose correct Python expressions so that your ideas aren’t misinterpretted by a so-called-AI.

I want you to experience the joy of being able to compose a working Python program and create a game world that is all your own. The feeling is like when you sing the first song that you just made up in your head, or when you compose your first poem or story. There’s nothing like it, especially when it gives you the power to make your PC do whatever you want it to. It’s a lot more thrilling than even that feeling of vibe coding with AI when it seems to guess exactly what you want to hear and give you anything you want, whether it’s code, or an image, or a poem. It may feel like you are creating something awesome, but you are not. You are just copy-pasting from other people’s creativity and art and ideas.

How does AI work?

Imagine you are some social media mogul or military intelligence general with an army of administrative assistants. Your internet army can find anything you want, really fast, because you gave them a clean copy of the entire Internet, without any advertisements. And you gave them a clean search engine that can find any n-gram or image you want, without any junk or spam.

Call center of the Georgia National Guard with white men at computers wearing camo fatigues and headsets, one man looking at phone rather than at computer monitor. One soldier, in the middle of the frame has his thumb under his chin and finger on his lip. Source: Georgia National Guard from United States, CC BY 2.0, via Wikimedia Commons

Your team can find memes and images and articles on anything you want. And you’ve trained your team to coordinate with each other, even though they don’t all speak English. They don’t even understand what you are asking them to do. But you came up with a magic algorithm that they can use to copy paste all these bits of text together from the Internet and make it make sense. When you ask your team any question or give them any creative writing task, they just do what the algorithm tells them to do. Each one of them takes a few words from your prompt and finds a few examples on the internet that match it and then copy the words around it and paste it into the words from your prompt. They do this over and over again and share their work with each other, until eventually they create an answer to your prompt. This is called an N-gram language model. It’s a very powerful algorithm for generating good looking text from any prompt or question.

The algorithm and the machine don’t understand anything about what they are doing, but you have given them this awesome n-gram algorithm it it seems to work 95% of the time. And they really want to make you happy, so they always paste text that they think you will like. It always seems to give you exactly what you are asking for. If it was free, you would probably use it for all your assignments and all your online work. But deep down you know that you are cheating yourself. You are slowly losing your ability to think and reason and communicate. You are letting your social media posting team do all your thinking for you. That’s so-called-AI. AI researchers call these systems LLMs - Large Language Models - because that’s all they are, a massive model of language. AI is just a translation algorithm that can translate from a question to an answer.

And being a social media mogul with all this power is not all it’s cracked up to be. You never get to build anything yourself. The things a media mogul creates for a business make a lot of money by manipulating and influencing other. They don’t reflect your values and creativity, just your ambition and desire to make money. Anything created by a machine is just SLOP, sloppy code, sloppy images, sloppy ideas and writing.

Agile process

For your final project I want you to work the way you would work on an Agile team. The Agile process involves incremental development. The ideas is that each time you push a new “feature” or capability up to the shared Python program, you want your teammates to understand what you did. And you want them to be able to run it. So that’s the key to an incremental or iterative development process. It’s almost identical to the REPL (read, evaluate, print, loop) process that you learned about earlier in the course:

  1. Make a small change and save it (commit it) in git
  2. Run the new code and test it until it works
  3. Upload your program to GitLab
  4. Loop back to 1 to make another small change.

I want you to demonstrate your ability to make small improvements to your text adventure program. Imagine you are on a team that needs to see the changes you made. And you are NOT allowed to use AI for any part of this process. You would lose credibility with your teammates if they see you submitting slop code.

And if you don’t want to do a lot of typing, you can delete a lot of the text to make it shorter and easier to follow. You will do yourself a favor if you simplify your game. What I’m looking for is the structure of your code and your program, not how many words it takes to describe the world. It needs to make logical sense and reflect the design that you created with your original text adventure design project. If you want to change the structure of your game, upload a new version of your adventure diagram.

Agile (incremental) programming

Here are some examples of incremental small improvements I would like you to do for your final project. Please upload them, one by one to GitLab.com, so I can verify you understand the concepts. You muse have at least 3 small, working versions of your program uploaded to GitLab for you to get full credit on your final project For each step, you should test that your program still works before uploading. Your committed versions of your program don’t have to work perfectly, but should at least run. I want to see at least 5 commits to the same file on GitLab for you to get full credit.

  1. Rename the functions with names that reflect what they do and are easier for you to remember than numbers.
  2. In one function, create a variable for the string literals:
  • 2.1. Combine the strings in the print() statements from a function using multiline string literal (quoted with tripple quotes like ''')
  • 2.2. In another function create the print string literal variable with the same variable name inside the function (e.g. description or text)
  1. Global variable to gather up strings
  • 3.1. Pull out all the multiline print strings from a function into a global dictionary with a key for the function name
  • 3.1. Pull out the print statement strings into another key-value pair in your global dictionary (function_name: """text string literal""")
  1. Create an argument to each function, naming it something like description or text.
  2. Parameterize the input() function strings the same way you parameterized the print() function strings for your two functions.
  • 5.1. Create a second argument to each function, calling something like “prompt” or “input_text” or “question”
  • 5.2. put these input() strings somewhere in your global dictionary, associated with the key for that room, e.g. big_sur_prompt
  • 5.3. create subdictionaries for each room that contain those input strings, something like: dict(big_sur=dict(description=… , prompt=…))
  • 5.4. create another argument to your functions for the possible commands that a player may type in that room
  • 5.5. your list of player commands should be stored in a list of 2-tuples or a dict to associate commands with destination rooms
  • 5.6. make sure your “commands” function argument is somewhere in your global dictionary data structure
  1. combine room1() and room2 into a single room() function into one
  • 6.1. use a string lookup in the global dictionary as an input to your e.g. room2() function call
  • 6.2. always return a valid room name from your room() function, no matter what your user chooses
  • 6.3. for an “invalid choice” prompt or game instructions text, create a separate global constant variable
  • 6.4. NOTE: it is best to name global constants in ALLCAPS so you know they are global and should not ever change
  1. make sure your room() function only needs a single room name argument to work.
  • 7.1. combine as many rooms as possible so that they all use the same function room(name=...)
  • 7.1. your room function may call itself “recursively” when you play your game
  1. create a while loop to call your room() function and only quit the game when the player has reached one of the “end” rooms. See Runestone Module 14, Question 17 at the bottom of this page: https://runestone.academy/assignment/student/doAssignment?assignment_id=221050
  2. write a separate program that defines the same global dictionary variable (you will not submit this program to GitLab)
  3. in your separate program save the global dictionary to a file using the json package or any text file format you dream up
  4. in your game program, delete the global dictionary and replace it with an open(filename).read() or something similar
  • 11.1. If you don’t know how to use the json package, try this import json ; help(json) like you learned at the beginning of the course.
  • 11.2. NOTE: if you read in your data file as text using open().read() (rather than using json) it will be a single huge string
  • 11.3. NOTE: to create a dictionary of dictionaries from a string you will need to “parse” the string:
  • 11.4. NOTE: “parsing a string” is when you split a long string into a bunch of smaller strings that you store in a data structure. It’s difficult to do with the str.split() so you probably want to learn how to use the json package. """

Final Project Program Requirements

Here are the requirements for your final project and this week’s incremental programming assignment. You do not necessarily have to create the data file this week, but if your program does require it to run, make sure you upload it BEFORE you .py file. I will only check out the py-file and it will only have access to the files that were committed before you committed the py-file.

If this sounds complicated, set up an office hours Zoom with me so I can explain.

Requirements

  1. Exactly 3 files for your program - all file names must be in snake_case:
  • 1.1. src/cisc179/data_driven/yourmesausername.json (or .tsv, .csv, .txt) - the data required to run your program
  • 1.2. src/cisc179/data_driven/yourmesausername.py - your Python program
  • 1.3. docs/designs/yourmesausername.png (or .jpeg, .drawio.png) - a tree or graph diagram of your program states
  1. At least 3 incremental changes to your program as commits to GitLab, all to the same py-file. Overwrite the old file with the new one.
  2. No advanced features or data structures that you did not learn how to create on your own, from your textbook or from this course.
  3. No AI or copy/paste code or text that you did not dream up and type yourself, on your own.

I will check out and run each of the 3+ versions of your code. This is a lot of work for me. So make sure your program works before you upload it each time. You can upload more than three versions of your program and data files, if you are worried that some of your commits won’t meet the requirements of this assignment. I will give you credit for any working versions that you commit to the repository.

If I cannot find your py file or data file under your Mesa username I won’t be able to give you credit for this assignment. I was forgiving on the midterm project, but I do not have the time to try to be forgiving during the last days of this course. It is unfair for me to spend time on hunting for your program files in the git repository history because that detracts from the time I spend reviewing other correctly-submitted programs.

If you have any doubts about whether you have submitted your work correctly, upload it early and send me an Inbox message with a link to the file that you uploaded. I will tell you if it is correct. If you wait until the due date, I will not be able to help you correct your submission.

Your first 2 commits for of your py-file file are due at the end of this week — Week 15, Sat, May 17 @ 11:59 PM. Your final data file and py-file commits are due at the end of Week 16, Sat, May 24 @ 11:59 PM.