QB64.org Forum

Active Forums => Programs => Topic started by: bplus on January 07, 2022, 11:48:47 pm

Title: Wordle - a new word game
Post by: bplus 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.
  [ This attachment cannot be displayed inline in 'Print Page' view ]  
Title: Re: Wordle - a new word game
Post by: euklides on January 08, 2022, 04:29:29 am
A letter mastermind...
Title: Re: Wordle - a new word game
Post by: bplus 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.
Title: Re: Wordle - a new word game
Post by: GronkleNut 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.
Title: Re: Wordle - a new word game
Post by: bplus 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.

  [ This attachment cannot be displayed inline in 'Print Page' view ]  
Title: Re: Wordle - a new word game
Post by: bplus 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. :)
Title: Re: Wordle - a new word game
Post by: Statsman1 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.
Title: Re: Wordle - a new word game
Post by: bplus 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.
Title: Re: Wordle - a new word game
Post by: Statsman1 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.  :)
Title: Re: Wordle - a new word game
Post by: bplus 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.

 
Title: Re: Wordle - a new word game
Post by: Statsman1 on January 11, 2022, 11:41:09 am
Awesome, @bplus!!
Title: Re: Wordle - a new word game
Post by: bplus on January 11, 2022, 01:16:43 pm
Awesome, @bplus!!

Thanks I hope you noticed the example I chose for screen shot :)
Title: Re: Wordle - a new word game
Post by: Statsman1 on January 11, 2022, 02:15:25 pm
I did notice, that is how I know you 100% test your programs!  :)
Title: Re: Wordle - a new word game
Post by: Statsman1 on January 11, 2022, 02:35:35 pm
Of course, now my afternoon productivity is going down the tubes....

Title: Re: Wordle - a new word game
Post by: bplus on January 11, 2022, 04:22:44 pm
Call it the vital service of Beta Testing. :)
Title: Re: Wordle - a new word game
Post by: SMcNeill on January 11, 2022, 11:07:37 pm
Now, for version 4, it needs to have a difficulty screen where you choose words from 3 to 10 letters.

Personally, I imagine a game with 3 letter words would be hard as heck to guess, whereas s 10-letter word would be relatively simple (counter-intuitively).  Three letters, you have less chance to get a letter on a guess, and there's soooo many 3-letter words with minute variance in them!  Bat, but, bot, bit, bet... even if you get the b and t, there's 5 unique choices for the middle letter alone!  10-letter words, on the other hand, have more chances to guess a letter from them, and a much smaller pool of words to try and march from.
Title: Re: Wordle - a new word game
Post by: bplus on January 12, 2022, 05:19:53 am
OK version 4 you chose number of letters / number of guesses for your level, why not :)

For 3 letter words with 3 word guesses: pie, tau, soy
you learn what vowels you have plus 3 common consonants, likely hit with 2 of 3.
Title: Re: Wordle - a new word game
Post by: bplus on January 12, 2022, 08:05:28 am
OK to prepare for Wordle 4, I cleaned out the unixdict.txt of 757 words that had punctuation or digits in them to Clean_Dict.txt. Then in 2nd part of code, Make N Letter Word Files.bas below, I made 10 files according to word length. Included with the code for making those files I have listed the word counts for each file in comments at the end.

Code: QB64: [Select]
  1. ' Make "Clean_Dict.txt" pure letters only b+ 2022-01-12
  2. DefLng A-Z
  3. Open "unixdict.txt" For Input As #1
  4. Open "Clean_Dict.txt" For Output As #2
  5.     Input #1, w$
  6.     lw = Len(w$)
  7.     If (lw > 2) And (lw < 13) Then ' word lengths 3 to 12, makes 9 files
  8.         i = 1: OK = -1
  9.         While i <= lw ' check for pure letter words
  10.             If (Asc(w$, i) < 97) Or (Asc(w$, i) > 122) Then OK = 0: Exit While
  11.             i = i + 1
  12.         Wend
  13.         If OK Then Print #2, w$
  14.     End If
  15. Print "Clean_Dict.txt, file ready."
  16.  
  17. ' Note: Clean_Dict.txt has 757 words less than unixdict.txt
  18.  
  19. ' Part 2 make 9 N_Letter_Word.txt files
  20. For N = 3 To 12
  21.     Open _Trim$(Str$(N)) + "_Letter_Words.txt" For Output As #N
  22. Open "Clean_Dict.txt" For Input As #1
  23.     Input #1, w$
  24.     Select Case Len(w$)
  25.         Case 3: Print #3, w$
  26.         Case 4: Print #4, w$
  27.         Case 5: Print #5, w$
  28.         Case 6: Print #6, w$
  29.         Case 7: Print #7, w$
  30.         Case 8: Print #8, w$
  31.         Case 9: Print #9, w$
  32.         Case 10: Print #10, w$
  33.         Case 11: Print #11, w$
  34.         Case 12: Print #12, w$
  35.     End Select
  36. Print "10 N_letter_Words.txt files should be ready."
  37.  
  38. ' N letters - number of words in file
  39. ' 3 - 753
  40. ' 4 - 2176
  41. ' 5 - 3145   the other 5 Letter Words W3.txt had u.s.a that was removed with above code
  42. ' 6 - 3852
  43. ' 7 - 4042
  44. ' 8 - 3608
  45. ' 9 - 3088
  46. ' 10 - 1971
  47. ' 11 - 1120
  48. ' 12 - 592
  49.  
  50.  

Reading through 3_Letter_Words.txt you will find non words like aaa or nne so be glad you can view the dictionary as you play the game! :)

Again I remind that unixdict.txt is in the zip of post at the start of this thread.

OK onto mod Wordle 4...
Title: Re: Wordle - a new word game
Post by: SMcNeill on January 12, 2022, 09:30:02 am
OK version 4 you chose number of letters / number of guesses for your level, why not :)

For 3 letter words with 3 word guesses: pie, tau, soy
you learn what vowels you have plus 3 common consonants, likely hit with 2 of 3.

My point is the difficulty of getting the last letter.

Lets say you guess SOY.  OY is correct and in the proper place -- that's guess #1.

Boy
Coy
Foy
Goy
Hoy
Joy
Roy
Soy
Toy

You have 4 guesses now to determine which of those 8 letters go into the first slot.

You could try RuT to rule out R and T.
HoG.
JiF

But if none of those work, you're still stuck with 2 choices B and C for the last letter, giving you a 50% chance to win, even if you play your cards perfect.

Or: bat, cat, dat, fat, gat, hat,  kat, lat, mat, nat, pat, rat, sat, tat, vat.... 15 choices ending in AT,...  :P


Title: Re: Wordle - a new word game
Post by: Statsman1 on January 12, 2022, 10:21:10 am
Maybe 3 letters in 6 guesses is too hard, due to the shortness of the word, the number of 3-letter words with common letters, and the overall number of combinations?

5 letters AND being forced to use real words to guess is important, I think, to being able to get to the word in 6 guesses.  I admit I got a Wordle on the 2nd guess the other day, but that was remarkably lucky, I usually get there between 3 and 5 guesses. 

Using openers like STARE, CLOUD and MINTY burn up 14 unique letters - all 6 vowels and most popular consonants in 3 guesses - I feel like, by that point, there is no way you cannot get it by 6 guesses.  Logic plays a huge part in it after that.

Using 3 letter words doesn’t get enough letters out there in the first few guesses to hope to arrive, logically, at the word by the end of 6 guesses, as mentioned by @SMcNeill, especially if the word chosen has a ton of first-letters that go with the last two - ?at, ?ar, ?en…there are loads of those.  It becomes a real roll of the dice.

Maybe 5 letters is the sweet spot between “relying on luck” and “reasonable number of guesses required”?
Title: Re: Wordle - a new word game
Post by: bplus on January 12, 2022, 10:33:14 am
Here it is, the answer to all Steve's challenges (so far):

Wordle 4 with advanced level options:
Code: QB64: [Select]
  1. _Title "Wordle 4" ' b+ 2022-01-12 as Steve suggested add option to choose how many letters, how many guesses
  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. ' 2022-01-12 Worde 4: prep word files by running, Make N Letter Word files.bas, (posted at forum already.)
  14.  
  15. '  All the variables use here
  16. Dim As Long f, NLetters, NGuesses, topWord, printRow, nGuess, hits, letter, p
  17. '  ReDim colorCode(1 To NLetters)
  18. Dim wordFile$, answer$, guess$, k$, blank$
  19.  
  20. f = _LoadFont("arial.ttf", 24, "MONOSPACE") ' a nice font for displaying Game letters with color
  21. Screen _NewImage(600, 400, 32) ' leave room for Editor window next to this QB64 app
  22. _ScreenMove 200, 200
  23. Color _RGB32(200, 200, 200), _RGB32(0, 0, 0) ' not too bright white on black for normal print
  24. '      123456789012345678901234567890123456789012345678901234567890123456789012345
  25. Locate 8, 1
  26. Print "                          The Skinny on Wordle:"
  27. Print "     In Standard Wordle Game, you get 6 tries to guess a 5 letter word.    "
  28. Print "          A letter color coded yellow is right letter wrong place."
  29. Print "          A letter color coded green is right letter right place."
  30. Print "                 ...zzz  means to press a key to continue."
  31. Print "              Press <a> to run an advanced level Wordle Game,"
  32. Print "                  any other to play Standard Wordle Game."
  33. k$ = InKey$
  34. While Len(k$) = 0: k$ = InKey$: Wend
  35. If k$ = "a" Then 'advanced level
  36.     Cls
  37.     lAgain:
  38.     Input "Please enter the number of letters (3-12) of words to play "; NLetters
  39.     If NLetters < 3 Or NLetters > 12 Then GoTo lAgain
  40.     gAgain:
  41.     Input "Please enter the number of guesses (2-10) to allow yourself "; NGuesses
  42.     If NGuesses < 2 Or NGuesses > 10 Then GoTo gAgain
  43.     _Title "Wordle 4 Advanced Options:" + Str$(NLetters) + " Letter Words with" + Str$(NGuesses) + " guesses allowed."
  44.     NLetters = 5: NGuesses = 6
  45. wordFile$ = _Trim$(Str$(NLetters)) + "_Letter_Words.txt"
  46. Dim dict(1 To 10000) As String ' oversized array to load word list
  47. Open wordFile$ For Input As #1 ' W3 version allows repeated letters, allot of 5 letter 1st names in here
  48.     topWord = topWord + 1
  49.     Input #1, dict(topWord)
  50. Shell _DontWait Chr$(34) + wordFile$ + Chr$(34)
  51.  
  52. Do ' again new round
  53.     Cls
  54.     Locate 24, 6: Print "You have to click the QB64 app to get focus back into the app.";
  55.     answer$ = dict(Int(Rnd * topWord) + 1) ' pick new word to guess
  56.     printRow = 0 ' reset for round
  57.     For nGuess = 1 To NGuesses ' allowed 6 guesses (in Standard Game)
  58.         hits = 0 ' how many letters are dead right? reset
  59.         printRow = printRow + 1 ' track left print line for inputs display mostly
  60.         ' here we are to select a word from word list in the Editor we opened and copy it to clipboard
  61.         Locate 23, 3: Print "Select a word from Editor and copy to clipboard, press enter when done."
  62.         k$ = InKey$
  63.         While k$ <> Chr$(13): k$ = InKey$: Wend
  64.         guess$ = _Trim$(_Clipboard$)
  65.         If guess$ = "" Then System
  66.         Locate 23, 1: Print Space$(75);
  67.         Locate printRow + 3, 10: Print nGuess; guess$
  68.         _Font f&
  69.         blank$ = answer$ ' we use blank to remove letters as we assign colors
  70.         ReDim colorCode(1 To NLetters)
  71.         For letter = 1 To NLetters
  72.             If Mid$(answer$, letter, 1) = Mid$(guess$, letter, 1) Then
  73.                 hits = hits + 1
  74.                 Mid$(blank$, letter, 1) = " " ' remove green letters taken by direct hits
  75.                 colorCode(letter) = 3
  76.             End If
  77.         Next
  78.         For letter = 1 To NLetters
  79.             If colorCode(letter) <> 3 Then
  80.                 p = InStr(blank$, Mid$(guess$, letter, 1))
  81.                 If p > 0 Then
  82.                     colorCode(letter) = 2
  83.                     Mid$(blank$, p, 1) = " " ' remove so can't color again
  84.                 End If
  85.             End If
  86.         Next
  87.         For letter = 1 To NLetters ' now to display our colorful feedback about the guess
  88.             Locate nGuess + 1, letter + 13
  89.             If colorCode(letter) = 3 Then
  90.                 Color _RGB32(0, 0, 0), _RGB32(0, 128, 0)
  91.             ElseIf colorCode(letter) = 2 Then
  92.                 Color _RGB32(0, 0, 0), _RGB32(255, 255, 0)
  93.             Else
  94.                 Color _RGB32(200, 200, 200), _RGB32(0, 0, 0)
  95.             End If
  96.             Print Mid$(guess$, letter, 1)
  97.         Next
  98.         _Font 16
  99.         Color _RGB32(200, 200, 200), _RGB32(0, 0, 0)
  100.         If hits = NLetters Then Locate 13, 45: Print "You got it! ...zzz": Sleep: GoTo skip
  101.     Next
  102.     Sound 50, 4
  103.     Locate 16, 38: Print "The word was "; answer$; "  ...zzz"
  104.     Sleep
  105.     skip:
  106.     _Font 16
  107.  

 
 

 


 

Title: Re: Wordle - a new word game
Post by: Dimster on January 12, 2022, 10:48:48 am
This could morph into the new Babble. It would be interesting to guess the English word PIE for the Russian word meaning PIE, or Italian for PIE, or French for PIE etc. Pie is not a good example as the English versions has duplicate meanings, so lets go with WIND .... crap that a duplicate as well ... maybe morphing to the new Babble is a stretch.
Title: Re: Wordle - a new word game
Post by: Statsman1 on January 12, 2022, 11:15:42 am
Love it!  @bplus - for a guy who never played it, you are killing it here!!  :)
Title: Re: Wordle - a new word game
Post by: bplus on January 12, 2022, 11:27:12 am
Thanks @Statsman1

@Dimster I will look into Babble, as possible option or more ideas.

I have a fixed a couple of feedback Locate's to fit on screen with maximun letters 12 and maximum guesses 10 for the advanced levels:
Code: QB64: [Select]
  1. _Title "Wordle 4" ' b+ 2022-01-12 as Steve suggested add option to choose how many letters, how many guesses
  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. ' 2022-01-12 Worde 4: prep word files by running, Make N Letter Word files.bas, (posted at forum already.)
  14. ' fix some feedback Locates rfor maximum guesses and letters
  15.  
  16. '  All the variables use here
  17. Dim As Long f, NLetters, NGuesses, topWord, printRow, nGuess, hits, letter, p
  18. '  ReDim colorCode(1 To NLetters)
  19. Dim wordFile$, answer$, guess$, k$, blank$
  20.  
  21. f = _LoadFont("arial.ttf", 24, "MONOSPACE") ' a nice font for displaying Game letters with color
  22. Screen _NewImage(600, 400, 32) ' leave room for Editor window next to this QB64 app
  23. _ScreenMove 200, 200
  24. Color _RGB32(200, 200, 200), _RGB32(0, 0, 0) ' not too bright white on black for normal print
  25. '      123456789012345678901234567890123456789012345678901234567890123456789012345
  26. Locate 8, 1
  27. Print "                          The Skinny on Wordle:"
  28. Print "     In Standard Wordle Game, you get 6 tries to guess a 5 letter word.    "
  29. Print "          A letter color coded yellow is right letter wrong place."
  30. Print "          A letter color coded green is right letter right place."
  31. Print "                 ...zzz  means to press a key to continue."
  32. Print "              Press <a> to run an advanced level Wordle Game,"
  33. Print "                  any other to play Standard Wordle Game."
  34. k$ = InKey$
  35. While Len(k$) = 0: k$ = InKey$: Wend
  36. If k$ = "a" Then 'advanced level
  37.     Cls
  38.     lAgain:
  39.     Input "Please enter the number of letters (3-12) of words to play "; NLetters
  40.     If NLetters < 3 Or NLetters > 12 Then GoTo lAgain
  41.     gAgain:
  42.     Input "Please enter the number of guesses (2-10) to allow yourself "; NGuesses
  43.     If NGuesses < 2 Or NGuesses > 10 Then GoTo gAgain
  44.     _Title "Wordle 4 Advanced Options:" + Str$(NLetters) + " Letter Words with" + Str$(NGuesses) + " guesses allowed."
  45.     NLetters = 5: NGuesses = 6
  46. wordFile$ = _Trim$(Str$(NLetters)) + "_Letter_Words.txt"
  47. Dim dict(1 To 10000) As String ' oversized array to load word list
  48. Open wordFile$ For Input As #1 ' W3 version allows repeated letters, allot of 5 letter 1st names in here
  49.     topWord = topWord + 1
  50.     Input #1, dict(topWord)
  51. Shell _DontWait Chr$(34) + wordFile$ + Chr$(34)
  52.  
  53. Do ' again new round
  54.     Cls
  55.     Locate 24, 6: Print "You have to click the QB64 app to get focus back into the app.";
  56.     answer$ = dict(Int(Rnd * topWord) + 1) ' pick new word to guess
  57.     printRow = 0 ' reset for round
  58.     For nGuess = 1 To NGuesses ' allowed 6 guesses (in Standard Game)
  59.         hits = 0 ' how many letters are dead right? reset
  60.         printRow = printRow + 1 ' track left print line for inputs display mostly
  61.         ' here we are to select a word from word list in the Editor we opened and copy it to clipboard
  62.         Locate 23, 3: Print "Select a word from Editor and copy to clipboard, press enter when done."
  63.         k$ = InKey$
  64.         While k$ <> Chr$(13): k$ = InKey$: Wend
  65.         guess$ = _Trim$(_Clipboard$)
  66.         If guess$ = "" Then System
  67.         Locate 23, 1: Print Space$(75);
  68.         Locate printRow + 3, 10: Print nGuess; guess$
  69.         _Font f&
  70.         blank$ = answer$ ' we use blank to remove letters as we assign colors
  71.         ReDim colorCode(1 To NLetters)
  72.         For letter = 1 To NLetters
  73.             If Mid$(answer$, letter, 1) = Mid$(guess$, letter, 1) Then
  74.                 hits = hits + 1
  75.                 Mid$(blank$, letter, 1) = " " ' remove green letters taken by direct hits
  76.                 colorCode(letter) = 3
  77.             End If
  78.         Next
  79.         For letter = 1 To NLetters
  80.             If colorCode(letter) <> 3 Then
  81.                 p = InStr(blank$, Mid$(guess$, letter, 1))
  82.                 If p > 0 Then
  83.                     colorCode(letter) = 2
  84.                     Mid$(blank$, p, 1) = " " ' remove so can't color again
  85.                 End If
  86.             End If
  87.         Next
  88.         For letter = 1 To NLetters ' now to display our colorful feedback about the guess
  89.             Locate nGuess + 1, letter + 13
  90.             If colorCode(letter) = 3 Then
  91.                 Color _RGB32(0, 0, 0), _RGB32(0, 128, 0)
  92.             ElseIf colorCode(letter) = 2 Then
  93.                 Color _RGB32(0, 0, 0), _RGB32(255, 255, 0)
  94.             Else
  95.                 Color _RGB32(200, 200, 200), _RGB32(0, 0, 0)
  96.             End If
  97.             Print Mid$(guess$, letter, 1)
  98.         Next
  99.         _Font 16
  100.         Color _RGB32(200, 200, 200), _RGB32(0, 0, 0)
  101.         If hits = NLetters Then Locate 15, 5: Print "You got it! ...zzz": Sleep: GoTo skip
  102.     Next
  103.     Sound 50, 4
  104.     Locate 16, 2: Print "The word was "; answer$; "  ...zzz"
  105.     Sleep
  106.     skip:
  107.     _Font 16
  108.  

Unless Beta testers find more things, I will post whole package in one zip for Best Answer a little later.
Title: Re: Wordle - a new word game
Post by: bplus on January 12, 2022, 03:16:26 pm
This could morph into the new Babble. It would be interesting to guess the English word PIE for the Russian word meaning PIE, or Italian for PIE, or French for PIE etc. Pie is not a good example as the English versions has duplicate meanings, so lets go with WIND .... crap that a duplicate as well ... maybe morphing to the new Babble is a stretch.

@Dimster did you babble the word game Boggle?
Title: Re: Wordle - a new word game
Post by: Dimster on January 13, 2022, 10:30:33 am
Boggle? Had to look that one up....1972....pre digital era. Can't say I ever played it but I do recall a square plastic filled with chicklets with numbers on them. The idea was to get the numbers in order. A 2d version of the 3d rubric cube filled with colors.
Title: Re: Wordle - a new word game
Post by: bplus on January 13, 2022, 11:48:10 am
Boggle? Had to look that one up....1972....pre digital era. Can't say I ever played it but I do recall a square plastic filled with chicklets with numbers on them. The idea was to get the numbers in order. A 2d version of the 3d rubric cube filled with colors.

The "chicklets" are die with Letters in Boggle:
https://qb64forum.alephc.xyz/index.php?topic=4570.0

@Dimster maybe you can find a good link of what you are talking about?
Title: Re: Wordle - a new word game
Post by: SMcNeill on January 13, 2022, 02:06:18 pm
From my memory of Boggle, the game pieces were made like scrabble, but with the bottom hollowed out, making them look more like the keys on a keyboard, if you've ever pulled those out from the board.

The purpose was to allow for words to build over another...

A vertical word might be:

C
H
E
A
T

For the next turn, the other person might want to spell the word PEON....  A valid way to do that was to:

C
H
E
A
PEON

The hollow bottom P would stack on top of the T and overwrite it, leaving both words "Cheap" and "Peon" to score off from...

Similar to Scrabble, but with that one main word-building difference.
Title: Re: Wordle - a new word game
Post by: STxAxTIC on January 13, 2022, 02:09:57 pm
This game was called UpWords. Boggle was different.

  [ This attachment cannot be displayed inline in 'Print Page' view ]  
Title: Re: Wordle - a new word game
Post by: Statsman1 on January 13, 2022, 02:16:38 pm
Boggle was 16 6-sided cubes (each side had a letter) that were scrambled (shaken up) and then settled into a 4x4 grid.  (Or, later, 5x5) The idea was to make as many unique words out of the cubes that were touching each other, using each cube once, before the timer expired.  Longer word = more points.

Unique because if you found it and your opponent did too, nobody got credit for it.
Title: Re: Wordle - a new word game
Post by: Dimster on January 13, 2022, 03:30:04 pm
https://begin.babbel.com/ (https://begin.babbel.com/) - I believe this title is based on the biblical Tower of Babble. I was thinking your Wordle game could add the "game" aspect to the Babble educationally/utility bent program.
Title: Re: Wordle - a new word game
Post by: bplus on January 13, 2022, 06:12:04 pm
https://begin.babbel.com/ (https://begin.babbel.com/) - I believe this title is based on the biblical Tower of Babble. I was thinking your Wordle game could add the "game" aspect to the Babble educationally/utility bent program.

Oh man that's for teaching foreign languages. LOL