Author Topic: Wordle - a new word game  (Read 4597 times)

0 Members and 1 Guest are viewing this topic.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Wordle - a new word game
« on: January 07, 2022, 11:48:47 pm »
Pretty easy to figure out, read title bar for instructions:
Code: QB64: [Select]
  1. _Title "Wordle: 6 guesses to get 5 letter word, enter guess or nothing to quit, yellow is right letter wrong place, green is right letter right place."
  2. Randomize Timer ' b+ 20220107
  3. f& = _LoadFont("arial.ttf", 24, "MONOSPACE")
  4. Screen _NewImage(1024, 600, 32)
  5. _ScreenMove 100, 100
  6. Color _RGB32(200, 200, 200), _RGB32(0, 0, 0)
  7. Do ' again new round
  8.     Cls
  9.     Open "5 Letter Words.txt" For Input As #1 'grab a word, this is fast enough
  10.     nWord = Int(Rnd * 2104) + 1
  11.     For i = 1 To nWord
  12.         Input #1, w$
  13.     Next
  14.     Close #1
  15.     'Locate 20, 60: Print w$ ' for debug or cheat
  16.     printRow = 0
  17.     For i = 1 To 6 ' allowed 6 guesses
  18.         hits = 0 ' how many letters are dead right?
  19.         tryAgain: ' opps too many or few letters in guess
  20.         printRow = printRow + 1 ' track left print line for inputs mostly
  21.         Locate printRow, 1: Print " "; _Trim$(Str$(i)); "# ";
  22.         Input "Enter a 5 letter word for your guess "; guess$
  23.         If guess$ = "" Then System
  24.         If Len(guess$) <> 5 Then Sound 50, 4: printRow = printRow + 1: Print "Try again": GoTo tryAgain
  25.         _Font f&
  26.         For letter = 1 To 5
  27.             Locate i, letter + 30
  28.             If Mid$(w$, letter, 1) = Mid$(guess$, letter, 1) Then
  29.                 hits = hits + 1
  30.                 Color _RGB32(0, 0, 0), _RGB32(0, 128, 0)
  31.             ElseIf InStr(w$, Mid$(guess$, letter, 1)) Then
  32.                 Color _RGB32(0, 0, 0), _RGB32(255, 255, 0)
  33.             Else
  34.                 Color _RGB32(200, 200, 200), _RGB32(0, 0, 0)
  35.             End If
  36.             Print Mid$(guess$, letter, 1)
  37.         Next
  38.         _Font 16
  39.         Color _RGB32(200, 200, 200), _RGB32(0, 0, 0)
  40.         If hits = 5 Then Locate printRow + 1: Print "You got it!": _Delay 3: GoTo skip
  41.     Next
  42.     Sound 50, 4
  43.     printRow = printRow + 2
  44.     Locate printRow, 1: Print "The word was "; w$
  45.     _Delay 3
  46.     skip:
  47.  

The zip contains source, exe for Windows, 2 word files and the code to convert one to "5 Letter Words.txt" file.
 
wordle.PNG
* Wordle 1.zip (Filesize: 2.23 MB, Downloads: 130)

Offline euklides

  • Forum Regular
  • Posts: 128
    • View Profile
Re: Wordle - a new word game
« Reply #1 on: January 08, 2022, 04:29:29 am »
A letter mastermind...
Why not yes ?

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Wordle - a new word game
« Reply #2 on: January 08, 2022, 01:38:21 pm »
A letter mastermind...

Yes, and Bulls and Cows game with digits, but Wordle has the advantage of knowing which and where the dead right letter(s) is(are). On the other hand there are usually less colors than digits more than double, and less digits than letters more than double. On the other, other hand, colors can be doubled up (or more eg, all 4 the same) in Mastermind and they are usually all unique in Bulls and Cows and how I made Wordle.

Offline GronkleNut

  • Newbie
  • Posts: 1
    • View Profile
Re: Wordle - a new word game
« Reply #3 on: January 10, 2022, 05:23:24 pm »
Fun, although I think the rules are slightly different to those you've implemented, you can't just put in random letters for your guess you have to put in a valid 5 letter word - hopefully easy to check the user entered guess word is in the word list before evaluating/highlighting the guess.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Wordle - a new word game
« Reply #4 on: January 10, 2022, 05:38:12 pm »
So someone finally gets around to posting some code for Wordle at LB, tsh73 of course!

He brought up some interesting things:
1. Using console (no color coding) he Capitalized the right letters in the wrong place and he [boxed] the letters in the right place.
2. He demands the word guesses be in the dictionary he is using! That is a really hard to do twist compared to my strategy of going in sets of abcde, fghij, klmno,... and getting all the letters in at most 5.
OK I confess being dumbfounded if I had to use real word guesses, unless....

Here is my Wordle 2, your guesses must be a word in the dictionary but you get the dictionary list to select the Word from!!! Further I tried my select item from array code and it sucked without a speedy scroll bar to jump from A to Z fast!

So WTH I loaded the list into yours and mine designated or default .txt Editor from a Shell command.

Now to get the word you select from the list into the Game app you Copy the word into the Clipboard and then Click the Game app to get the focus back to that and hit Enter. The app reads the word from Clipboard as your next guess.

So the code for Wordle 2 isn't much more than Wordle 1:
Code: QB64: [Select]
  1. _Title "Wordle 2: 6 guesses to get 5 letter word, enter guess or nothing to quit, yellow is right letter wrong place, green is right letter right place."
  2.  
  3. ' b+ 2022-01-09 Wordle 2: this version you have to select words from word list for your guess
  4. '2022-01-10 working but selecting words from wordlist is really slow, need to allow letters to jump up and down the list faster!
  5. ' Today we will select word from opened text editor
  6. ' 1) copy word to clipboard
  7. ' 2) signal this program you've got the new word loaded in clipboard
  8. ' Get rid of the ' words in "5 Letter Words.txt" file, too unexpected. So rewrite the file builder from unixdict.txt OK 9 words removed.
  9.  
  10. Dim As Long f, topWord, printRow, nGuess, hits, letter
  11. Dim answer$, guess$, k$
  12.  
  13. f = _LoadFont("arial.ttf", 24, "MONOSPACE") ' a nice font for displaying Game letters with color
  14. Screen _NewImage(600, 400, 32) ' leave room for Editor window next to this QB64 app
  15. _ScreenMove 200, 200
  16. Color _RGB32(200, 200, 200), _RGB32(0, 0, 0) ' not too bright white on black for normal print
  17.  
  18. Dim dict(1 To 10000) As String ' oversized array to load word list
  19. Open "5 Letter Words.txt" For Input As #1 ' this file uses 5 unique letters, allot of 5 letter 1st names in here
  20.     topWord = topWord + 1
  21.     Input #1, dict(topWord)
  22. Shell _DontWait Chr$(34) + "5 Letter Words.txt" + Chr$(34)
  23.  
  24. Do ' again new round
  25.     Cls
  26.     Locate 24, 6: Print "You have to click the QB64 app to get focus back into the app.";
  27.     answer$ = dict(Int(Rnd * topWord) + 1) ' pick new word to guess
  28.     printRow = 0 ' reset for round
  29.     For nGuess = 1 To 6 ' allowed 6 guesses
  30.         hits = 0 ' how many letters are dead right? reset
  31.         printRow = printRow + 1 ' track left print line for inputs display mostly
  32.  
  33.         ' here we are to select a word from word list in the Editor we opened and copy it to clipboard
  34.         ' you have to click the QB64 app to get focus back into the app.
  35.         Locate 23, 3: Print "Select a word from Editor and copy to clipboard, press enter when done."
  36.         k$ = InKey$
  37.         While k$ <> Chr$(13): k$ = InKey$: Wend
  38.         guess$ = _Trim$(_Clipboard$)
  39.         If guess$ = "" Then System
  40.         Locate 23, 1: Print Space$(75);
  41.         Locate printRow, 1: Print nGuess; guess$
  42.  
  43.         _Font f&
  44.         For letter = 1 To 5
  45.             Locate nGuess + 1, letter + 16
  46.             If Mid$(answer$, letter, 1) = Mid$(guess$, letter, 1) Then
  47.                 hits = hits + 1
  48.                 Color _RGB32(0, 0, 0), _RGB32(0, 128, 0)
  49.             ElseIf InStr(answer$, Mid$(guess$, letter, 1)) Then
  50.                 Color _RGB32(0, 0, 0), _RGB32(255, 255, 0)
  51.             Else
  52.                 Color _RGB32(200, 200, 200), _RGB32(0, 0, 0)
  53.             End If
  54.             Print Mid$(guess$, letter, 1)
  55.         Next
  56.         _Font 16
  57.         Color _RGB32(200, 200, 200), _RGB32(0, 0, 0)
  58.         If hits = 5 Then Locate 13, 45: Print "You got it! ...zzz": Sleep: GoTo skip
  59.     Next
  60.     Sound 50, 4
  61.     Locate 16, 38: Print "The word was "; answer$; "  ...zzz"
  62.     Sleep
  63.     skip:
  64.     _Font 16
  65.  

You can use the old "5 Letter Words.txt", I found it contained words with an ' so I modified the "Make 5 Letter Word file.bas to this:
Code: QB64: [Select]
  1. Open "unixdict.txt" For Input As #1
  2. Open "5 Letter Words.txt" For Output As #2
  3.     Input #1, w$
  4.     If InStr(w$, "'") Then 'skip
  5.     Else
  6.         good = 1
  7.         If Len(w$) = 5 Then
  8.             For i = 1 To 4
  9.                 If InStr(i + 1, w$, Mid$(w$, i, 1)) Then good = 0: Exit For
  10.             Next
  11.             If good Then Print #2, w$
  12.         End If
  13.     End If
  14. Print "5 Letter Words.txt, file ready."
  15.  
It removes 9 words from file. The unixdict.txt is still in zip of the first post.

 
Wordle 2.PNG


Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Wordle - a new word game
« Reply #5 on: January 10, 2022, 05:39:55 pm »
Fun, although I think the rules are slightly different to those you've implemented, you can't just put in random letters for your guess you have to put in a valid 5 letter word - hopefully easy to check the user entered guess word is in the word list before evaluating/highlighting the guess.

Hi @GronkleNut

Yeah just posted Wordle 2 with rule of using real words, thanks. :)

Offline Statsman1

  • Newbie
  • Posts: 36
  • I'm just a jerk, but a hero is what I want to be.
    • View Profile
Re: Wordle - a new word game
« Reply #6 on: January 10, 2022, 06:45:06 pm »
Looks great, I love this game, but as an avid Wordle player, I must add that duplicate letters ARE permitted in Wordle.  I looked at the dictionary file supplied, and words like ANNEX, COCOA and BUDDY are legitimate Wordle entries, but are not in the dictionary file.
Good decisions come from experience.
Experience comes from bad decisions.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Wordle - a new word game
« Reply #7 on: January 10, 2022, 06:56:50 pm »
Looks great, I love this game, but as an avid Wordle player, I must add that duplicate letters ARE permitted in Wordle.  I looked at the dictionary file supplied, and words like ANNEX, COCOA and BUDDY are legitimate Wordle entries, but are not in the dictionary file.

Sorry, never heard of let alone played it. I thought unique letter set would be easier to code.

Well there is always my Wordle 3 or yours? @Statsman1 ;-)) BTW always been fascinated by symbol in your avatar, curious about the real origin.

Offline Statsman1

  • Newbie
  • Posts: 36
  • I'm just a jerk, but a hero is what I want to be.
    • View Profile
Re: Wordle - a new word game
« Reply #8 on: January 10, 2022, 07:06:57 pm »
Hey @bplus -

No problem, your Wordle is excellent.  I am not sure I could code anything to allow for the duplicate of letters anytime soon, though I imagine it would simply be a little more recursive comparing (to wit - instead of stopping when you find the character in the word, you have to check each character in a guess to see if it matches each letter in the solution, cannot just stop the search after finding the first instance of E in ELECT if the guess is TRADE).

As for the symbol - well, it is an ankh, an Egyptian symbol that means life.  You see this in hieroglyphics and all sorts of ancient Egyptian symbolism.  How it became MY talisman is a little less exotic - Ultima IV for the Apple II is my favorite video game of all time.  I adopted the ankh, when I bought the original game back in 1985, as my good-luck charm, and have carried it all through my life.  I have the very same one that came with the game, back in ‘85, on a chain that I wear from time to time, and I have a couple of other metal ankhs here and there around the house.

Kinda silly, I know, but Ultima IV, and the ankh, have meant a lot to me in 35 years.  :)
Good decisions come from experience.
Experience comes from bad decisions.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Wordle - a new word game
« Reply #9 on: January 11, 2022, 01:05:18 am »
OK Wordle 3 handles repeated letters, it was a little tricky when more than 1 letter in guess matches a letter in the answer to match. A little better instructions screen at start too.
Code: QB64: [Select]
  1. _Title "Wordle 3" ' b+ 2022-01-10 allow repeated letters in Word Game
  2.  
  3. ' b+ 2022-01-09 Wordle 2: this version you have to select words from word list for your guess
  4. '2022-01-10 working but selecting words from wordlist is really slow, need to allow letters to jump up and down the list faster!
  5. ' Today we will select word from opened text editor
  6. ' 1) copy word to clipboard
  7. ' 2) signal this program you've got the new word loaded in clipboard
  8. ' Get rid of the ' words in "5 Letter Words.txt" file, too unexpected. So rewrite the file builder from unixdict.txt OK 9 words removed.
  9.  
  10. ' 2022-01-10 Wordle 3: allow repeated letters (make it even harder! to play and code?)
  11. ' Revise "Make 5 Letter Words W3.bas" code to rebuild "5 Letter Words W3.txt" with words with repeating letters.
  12.  
  13. Dim As Long f, topWord, printRow, nGuess, hits, letter, p, colorCode(1 To 5)
  14. Dim answer$, guess$, k$, blank$
  15.  
  16. f = _LoadFont("arial.ttf", 24, "MONOSPACE") ' a nice font for displaying Game letters with color
  17. Screen _NewImage(600, 400, 32) ' leave room for Editor window next to this QB64 app
  18. _ScreenMove 200, 200
  19. Color _RGB32(200, 200, 200), _RGB32(0, 0, 0) ' not too bright white on black for normal print
  20. '      123456789012345678901234567890123456789012345678901234567890123456789012345
  21. Locate 8, 1
  22. Print "                          The Skinny on Wordle:"
  23. Print "                You get 6 tries to guess a 5 letter word."
  24. Print "          A letter color coded yellow is right letter wrong place."
  25. Print "          A letter color coded green is right letter right place."
  26. Print "            ...zzz  means to press a key to continue ...zzz"
  27.  
  28. Dim dict(1 To 10000) As String ' oversized array to load word list
  29. Open "5 Letter Words W3.txt" For Input As #1 ' W3 version allows repeated letters, allot of 5 letter 1st names in here
  30.     topWord = topWord + 1
  31.     Input #1, dict(topWord)
  32. Shell _DontWait Chr$(34) + "5 Letter Words W3.txt" + Chr$(34)
  33.  
  34. Do ' again new round
  35.     Cls
  36.     Locate 24, 6: Print "You have to click the QB64 app to get focus back into the app.";
  37.     answer$ = dict(Int(Rnd * topWord) + 1) ' pick new word to guess
  38.     printRow = 0 ' reset for round
  39.     For nGuess = 1 To 6 ' allowed 6 guesses
  40.         hits = 0 ' how many letters are dead right? reset
  41.         printRow = printRow + 1 ' track left print line for inputs display mostly
  42.         ' here we are to select a word from word list in the Editor we opened and copy it to clipboard
  43.         Locate 23, 3: Print "Select a word from Editor and copy to clipboard, press enter when done."
  44.         k$ = InKey$
  45.         While k$ <> Chr$(13): k$ = InKey$: Wend
  46.         guess$ = _Trim$(_Clipboard$)
  47.         If guess$ = "" Then System
  48.         Locate 23, 1: Print Space$(75);
  49.         Locate printRow + 3, 10: Print nGuess; guess$
  50.         _Font f&
  51.         blank$ = answer$ ' we use blank to remove letters as we assign colors
  52.         Erase colorCode
  53.         For letter = 1 To 5
  54.             If Mid$(answer$, letter, 1) = Mid$(guess$, letter, 1) Then
  55.                 hits = hits + 1
  56.                 Mid$(blank$, letter, 1) = " " ' remove green letters taken by direct hits
  57.                 colorCode(letter) = 3
  58.             End If
  59.         Next
  60.         For letter = 1 To 5
  61.             If colorCode(letter) <> 3 Then
  62.                 p = InStr(blank$, Mid$(guess$, letter, 1))
  63.                 If p > 0 Then
  64.                     colorCode(letter) = 2
  65.                     Mid$(blank$, p, 1) = " " ' remove so can't color again
  66.                 End If
  67.             End If
  68.         Next
  69.         For letter = 1 To 5 ' now to display our colorful feedback about the guess
  70.             Locate nGuess + 1, letter + 16
  71.             If colorCode(letter) = 3 Then
  72.                 Color _RGB32(0, 0, 0), _RGB32(0, 128, 0)
  73.             ElseIf colorCode(letter) = 2 Then
  74.                 Color _RGB32(0, 0, 0), _RGB32(255, 255, 0)
  75.             Else
  76.                 Color _RGB32(200, 200, 200), _RGB32(0, 0, 0)
  77.             End If
  78.             Print Mid$(guess$, letter, 1)
  79.         Next
  80.         _Font 16
  81.         Color _RGB32(200, 200, 200), _RGB32(0, 0, 0)
  82.         If hits = 5 Then Locate 13, 45: Print "You got it! ...zzz": Sleep: GoTo skip
  83.     Next
  84.     Sound 50, 4
  85.     Locate 16, 38: Print "The word was "; answer$; "  ...zzz"
  86.     Sleep
  87.     skip:
  88.     _Font 16
  89.  

You will also need the new Make file to assemble the 5 Letter Words W3 List that allow repeated letters, saved under a modified name so as a different file is made so the old list works with older version of game.
Code: QB64: [Select]
  1. Open "unixdict.txt" For Input As #1
  2. Open "5 Letter Words W3.txt" For Output As #2
  3.     Input #1, w$
  4.     If InStr(w$, "'") Then 'skip
  5.     Else
  6.         If Len(w$) = 5 Then Print #2, w$
  7.     End If
  8. Print "5 Letter Words W3.txt, file ready."
  9.  
Again the unixdict.txt file is in the zip in first post of this thread.

 
Wordle 3.PNG
« Last Edit: January 11, 2022, 04:39:15 pm by bplus »

Offline Statsman1

  • Newbie
  • Posts: 36
  • I'm just a jerk, but a hero is what I want to be.
    • View Profile
Re: Wordle - a new word game
« Reply #10 on: January 11, 2022, 11:41:09 am »
Awesome, @bplus!!
Good decisions come from experience.
Experience comes from bad decisions.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Wordle - a new word game
« Reply #11 on: January 11, 2022, 01:16:43 pm »
Awesome, @bplus!!

Thanks I hope you noticed the example I chose for screen shot :)

Offline Statsman1

  • Newbie
  • Posts: 36
  • I'm just a jerk, but a hero is what I want to be.
    • View Profile
Re: Wordle - a new word game
« Reply #12 on: January 11, 2022, 02:15:25 pm »
I did notice, that is how I know you 100% test your programs!  :)
Good decisions come from experience.
Experience comes from bad decisions.

Offline Statsman1

  • Newbie
  • Posts: 36
  • I'm just a jerk, but a hero is what I want to be.
    • View Profile
Re: Wordle - a new word game
« Reply #13 on: January 11, 2022, 02:35:35 pm »
Of course, now my afternoon productivity is going down the tubes....

Good decisions come from experience.
Experience comes from bad decisions.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Wordle - a new word game
« Reply #14 on: January 11, 2022, 04:22:44 pm »
Call it the vital service of Beta Testing. :)