ISF DP Computer Science

Wordle #

In this project, you will experience the IB IA structure and develop the code for a game based on the NYT Wordle.


Syllabus Topics [SL] #

  • B1.1.4 Trace flowcharts for a range of programming algorithms.

Syllabus Topics [HL] #

  • B4.1.1 Explain the core principles of ADTs

[0] Set up #

๐Ÿ’ป Go to your dpcs/unit00_strings folder.

cd ~/desktop/dpcs/unit00_strings/
๐Ÿ’ป Clone your repo. This will copy it onto your computer.
git clone https://github.com/isf-dp-cs/project_wordle_yourGithubUsername

Below you’ll see that the git clone command has a yourGithubUsername.

You need to replace this with your username

e.g. https://github.com/isf-dp-cs/project_wordle_emmaqbrown

๐Ÿ’ป In the Terminal, type the following command to open the lab folder.
cd project_wordle_yourGithubUsername

๐Ÿ’ป Enter the Poetry Shell to start the lab. As a reminder, we will run this command at the start of each lab, but only when we are inside a lab folder.

poetry shell
๐Ÿ‘พ ๐Ÿ’ฌ Exiting the poetry shell

When you want to exit the shell, you can type exit or ^D


[1] Criteria A: Problem Specification #

The Problem Specification is where you outline the description of your problem and how the product will address it.

In this lab we will focus on the Success Criteria. The Success Criteria measuare outcomes of the solution requirement.

โœ… CHECKPOINT:

๐Ÿ‘€ Open the Wordle IA document in your Google Drive and review the Sucess Criteria.


[2] Criteria C: System Overview #

The System Overview should enable another developer to recreate the product. It should include system models, algorithms, and a testing strategy.

Flowchart #

๐Ÿ‘€ First, let’s consider the game logic by looking at the flow chart.

Psuedocode for the color formatting #

You may noticed the logic for the process guess and format color does not include details. This is becuase, sometimes psueodocode is better suited for communicating an algorithm.

โœ… CHECKPOINT:

โœ๏ธ In the Criteria C Pseudocode section World IA document, write psueodocde for processing the guess and formatting the color.


[3] Criteria D: Development #

Development is where you actually create the product. You must justify your Success Criteria and demonstrate your ability to pass the tests outlined in the Testing Strategy.

๐Ÿ‘พ ๐Ÿ’ฌ Choose your own adventure

๐Ÿ’ป Follow along coding each success criteria.

It is your goal to complete as many success claims as you can. Test each one before moving onto the next.

Success Criteria 1: User Input #

Success Criteria: The game allows the user to input guess

Success Criteria 2: Correct User Guess #

Sucess Criteria: The game provides output and the game stops if the user has successfully guessed the word

๐Ÿ’ป Edit the loop so that if the user guesses correctly, it will end early.

Success Criteria 3: Guess Limit #

Right now, the user can guess infinitely. However, if they guess correctly, the loop should end early.

Succes Criteria: The game ends if the user guesses 6 times and outputs the correct word

Success Criteria 4: Random Word #

Success Criteria: The game randomly selects a word from a list of possible words

Success Criteria 5: Color Feedback #

A big part of Wordle is the feedback from the game. After each guess, the user is shown their guess, and each letter is highlighted according to these rules:

  • GRAY backround: guess letters not included in the word
  • YELLOW backround: guess letters in the wrong location
  • GREEN backround: guess letters in the correct location
๐Ÿ’ป Each time the user guesses a word, print the word in the terminal, formatted with background colors.

Here are some ANSI codes for you to use:

String gray = "\u001b[47;1m";
String yellow = "\u001b[43;1m";
String green = "\u001b[42;1m";
String reset = "\u001b[0m";

Success Criteria 6: Error Handling #

Sucess Criteria: The game includes error handling if the user input contains too few or too many letters


Example Completed Game

โšกโœจ Once you complete the lab, be sure to complete these two steps:

โœ๏ธ Go to your Syllabus Content Checklist in your Google Drive and update it accordingly.

๐Ÿ’ป Push your work to Github

  • git status
  • git add -A
  • git status
  • git commit -m "describe your code here"
  • git push
  • git remote


[4] Criteria E: Evaluation #

The evaluatioin of the product must evaluate if the Success Criteria were met and consider future improvements to the product.

โœ… CHECKPOINT:

โœ๏ธ Fill out Criteria E on your document


[5] HL: Abstract Data Types (ADTs) #

Sets #

Wouldn’t it be great if we had a Wordle helper program that could give a list of the possible words every round?

A Set is perfect for this situation.

๐Ÿ’ป In the file word_finder.py, finish the function get_possible_words().

  • inputs: a string of good letters, a string of bad letters, and a list of five letter words
  • output: a list of possible words

It uses sys to access command line arguements to easily run the program from the Terminal. The first arguement represents good letters (letters in the word) and the second arguement represents bad letters (letters not in the word). Here is how to run the file.

$ python word_finder.py rog asefn
['glory', 'gourd', 'groom', 'group', 'grout', 'growl', 'rigor', 'rough']

Consider which Set operations to use. Take a look this resources for how to use a Set in Python.

  • union - join two sets
  • intersection - find common values
  • difference - only items from first set
  • subset - if all of items in first set are in second set
  • superset - if all items of the items in the second set are in the first set

๐Ÿ‘พ Test your word_finder.py with the real Wordle! Consider, how you could rank the possible words in best to worst?

โšกโœจ

๐Ÿ’ป Push your code to GitHub!