Wordle

Calvin (Deutschbein)

W5Mon: 23 Sep


Announcements

  • By 11:59 PM: "Problem Set 3: Strings" assignment. def spaces_to_underscores(s:str) -> str: new = "" for index in range(len(s)): if s[index] in " ": new += "_" else: new += s[index] return new
  • By next Monday 11:59 PM: "Project 1: Wordle"
    • By Tue: Display a word
    • By Wed: Check a guess
    • By Thr: Color letters
    • By Fri: Random word
    • By Sat: Change rows
    • By Sun: Color keys.

Today

  • Introducing Wordle
    • By Tue: Display a word
    • By Wed: Check a guess
    • By Thr: Color letters
    • By Fri: Random word
    • By Sat: Change rows
    • By Sun: Color keys.

Wordle

  • Project 1: Wordle is due Monday.
  • 5 milestones, each roughly equivalent to a problem or part of a problem on a problem set.
  • Distinct from problem sets, each of the problems works together to create one, single, more expansive assignment.
  • Uses "WordleGraphics" heavily.
  • Demo

Wordle.py

    • As a rule, you will write code inside 'enter_action' or in functions at the same indentation level as 'enter_action' from WordleGraphics import * # WordleGWindow, N_ROWS, ... from english import * # ENGLISH_WORDS, is_english_word import random def wordle(): # The main function to play the Wordle game. def enter_action(): # What should happen when RETURN/ENTER is pressed. gw.show_message("You need to implement this method") gw = WordleGWindow() gw.add_enter_listener(enter_action) # Startup boilerplate if __name__ == "__main__": wordle()

WordleGraphics

  • We provide "WordleGraphics" which includes the following:
    Function Description
    gw.set_square_letter(row, col, l) Sets the letter in the specified row and col
    gw.get_square_letter(row, col) Returns letter in the specified row and col
    gw.add_enter_listener(func) Specifies function run when enter pressed
    gw.show_message(msg) Shows a message below the squares
    gw.set_square_color(row, col, c) Sets the color of the specified square
    gw.set_current_row(row_idx) Sets row where typed characters appear
    gw.get_current_row() Returns the current row index
    gw.set_key_color(letter, color) Sets the color of the specified key letter
    gw.get_key_color(letter) Returns the color of the specified key letter

Milestones

  • Aim to complete at least one milestone per day.
  • Submit your code on Github after every milestone.
    • If your computer explodes, you lose nothing.
  • Milestones in general should be equal-to or less-than problem set problems.
  • But they build on each other (can't skip around).

Milestone 0

  • By Tuesday 11:59 PM
  • Display a word
  • I wrote:
    • word_to_row(word:str, row:int)
    • word_from_row(row:int) -> str
  • I used: gw.set_square_letter

Hint

  • Here is where I put them: def wordle(): # The main function to play the Wordle game. def enter_action(): # What should happen when RETURN/ENTER is pressed. gw.show_message("To do: enter_action") def word_to_row(word:str, row:int): gw.show_message("To do: word_to_row") def word_from_row(row:int) -> str: gw.show_message("To do: row_to_word") return "" # placeholder

Hint

  • Look out for capitalization. # to see if a word is in ENGLISH_WORDS, make it lower case. guess_str = "Hello" guess_low = guess_str.lower() guess_cap = guess_str.upper() print(guess_str, guess_str in ENGLISH_WORDS) # Hello False print(guess_low, guess_low in ENGLISH_WORDS) # hello True print(guess_cap, guess_cap in ENGLISH_WORDS) # HELLO False # places 'H' in the upper left gw.set_square_letter(0,0,guess_cap[0]
  • Here's one trick: Guess = "Hello" # use a mixed capital name for unknown guess = Guess.lower() # use lower if you've made lower GUESS = Guess.upper() # use upper if you've made upper

Milestone 1

  • By Wednesday 11:59 PM
  • Check a guess
  • Something like... def wordle(): def enter_action(): if # your code here gw.show_message("That's a 5 letter English word") else: gw.show_message("Not in word list")
  • I used my "row_to_word" from Milestone 0
  • I used "in" and "ENGLISH_WORDS", like PS3.2

Milestone 2

  • By Thursday 11:59 PM
  • Color the letters.
  • I wrote color_row(row:int, answer:str)
    • Find and color the correct (green) letters first
      • Avoid coloring a letter yellow if it is in the correct position.
      • Track if there's double letters - maintain a string of remaining letters, perhaps.
    • Find and color the present (yellow) letters next.
      • Track if there's double letters - maintain a string of remaining letters, perhaps.
    • Color remaining letters gray.
    • Test your code rigorously:
      • Use the "Sassy" guess with "Glass" answer

Milestone 2

  • By Thursday 11:59 PM
  • Color the letters.
  • We provide the following colors via from WordleGraphics import *
    Color Description
    CORRECT_COLOR A shade of green
    PRESENT_COLOR A shade of brownish yellow
    MISSING_COLOR A shade of gray
    UNKNOWN_COLOR Initial white color

Milestone 3

  • By Friday 11:59 PM
  • Random word
    • Generate a random 5-letter word.
      • import random # we'll discuss further - don't worry
    • Hold this word in a variable
    • Evaluate a guess against this answer.
    • Test your code more than once to ensure the word changes.
      • You may wish to share the answer via a gw.show_message()
  • This code randomizes the order of `ENGLISH_WORDS` random.shuffle(ENGLISH_WORDS) # de-alphabetizes for word in ENGLISH_WORDS: print(word) # prints words in a random order

Milestone 4

  • By Saturday 11:59 PM
  • Change Rows
    • After a guess, move to the next row.
      • Use 'gw.set_current_row(row_idx)' and 'gw.get_current_row()'.
    • If the guess is equal to the answer:
      • gw.show_message("something nice not literally this")
      • gw.set_current_row(N_ROWS) # stop reading
    • If the current row number is equal to 'N_ROWS' without a successful guess...
      • gw.show_message("reveal the answer")

Milestone 5 + Extensions

  • By Monday
  • Finish up the last milestone and any extensions.
  • Get this turned in comfortably ahead of time in case there's a disaster:
    • Influenza
    • Computer crash
    • Zamboni rampage
    • Cool new TV show comes out
  • Let's all get A's on this please.

Announcements

  • By 11:59 PM: "Problem Set 3: Strings" assignment. def spaces_to_underscores(s:str) -> str: new = "" for index in range(len(s)): if s[index] in " ": new += "_" else: new += s[index] return new
  • By next Monday 11:59 PM: "Project 1: Wordle"
    • By Tue: Display a word
    • By Wed: Check a guess
    • By Thr: Color letters
    • By Fri: Random word
    • By Sat: Change rows
    • By Sun: Color keys.