WORDLE

Discussions related to graphics (2D and 3D), animation and games programming
KenDown
Posts: 261
Joined: Wed 04 Apr 2018, 06:36

WORDLE

Post by KenDown »

There's a report in the Daily Mail today about some new craze that is "taking the world by storm", a word game called "Wordle" in which you have six attempts to guess a five-letter word. Didn't seem too hard to program. Can anyone do better?

Code: Select all

      OSCLI("FONT Arial,24,B")
      FORi%=0TO5
        FORj%=0TO4
          RECTANGLE100+j%*80,100+i%*80,78,78
        NEXT
      NEXT

      FORi%=1TORND(22):READtarget$:NEXT

      VDU5
      i%=0

      REPEAT
        right%=0
        offset%=0
        FORj%=0TO4
          GCOL0,0
          g$=GET$
          IFINSTR("IJ",g$)>0offset%=12
          IFg$="W"offset%=-8
          k%=INSTR(target$,g$)
          IFk%>0GCOL0,3
          IFMID$(target$,j%+1,1)=g$GCOL0,9:right%+=1
          MOVE116+j%*80+offset%,180+i%*80:PRINTg$
        NEXT
        i%+=1
      UNTILi%=6ORright%=5
      IFi%=6ANDright%<5GCOL0,5:FORj%=0TO4:MOVE116+j%*80+offset%,180+i%*80:PRINTMID$(target$,j%+1,1):NEXT
      END
      :
      DATARIGHT,MIGHT,BANGS,GRIPS,WORMs,TINNY,CREAM,SHEEP,HORSE,JEEPS,MOUSE
      DATAWOMAN,STATE,FLECK,WATER,TRAIN,BRAVE,MILKY,STARS,PENNY,DWELL,RIDER
Linking to a dictionary and selecting 5-letter words would obviously present more of a challenge, both to player and programmer.

DDRM
Posts: 398
Joined: Mon 02 Apr 2018, 18:04

Re: WORDLE

Post by DDRM »

As I understand it (from Wikipedia!) you are meant to get feedback from your guess (green for correct letters in the right position, yellow for letters in the target word but not in that position, and grey for letters that are not in the target word at all)?

Seems a bit like the old "mastermind" peg game?

You could link to the (5 letter section of the) SOWPODS dictionary, which is freely available, if you want (lots!) more words?

Best wishes,

D

KenDown
Posts: 261
Joined: Wed 04 Apr 2018, 06:36

Re: WORDLE

Post by KenDown »

Er - this does give differently coloured letters according to the criteria you mention. I'm not sure about the colours, but I guess that is easily corrected if anyone is bothered.

Thanks for the pointer to SOWPODS, of which I have not previously heard. I'll try and find it.

Yes, it is very much like the peg game, though a little easier in my opinion.

DDRM
Posts: 398
Joined: Mon 02 Apr 2018, 18:04

Re: WORDLE

Post by DDRM »

That's what comes of just running the code without analysing it first! ;-)
I was typing lower case, and you only go for exact matches, so nothing was matching...
I'm getting greeny-yellow for "right letter wrong place" and red for "correct", which is fine.

I note that you don't handle checking the right number of a particular letter (so, for example, if the word contains "S", if you enter SSSSS it will come up with them all yellow except the one in the right place (red).

Unlike the original game (but a valid alternative!) you give feedback as soon as the letter is typed, which makes life a little easier. On the other hand, there's no option for backspace!

I've also done a version, which I'll post in due course. The main issue is filtering the 5 letter words from sowpods manually - there are about 12,000 of them, and most are ridiculously obscure, so I'm trying to filter them to give "common"(ish) words, without foreign loan words (except where they are now everyday English words), alternative spellings, technical words, etc.

Best wishes,

D

DDRM
Posts: 398
Joined: Mon 02 Apr 2018, 18:04

Re: WORDLE

Post by DDRM »

Here's my version. It's a little different from both Kendall's and the original:
a) Like the original, but unlike Kendall's it takes a whole word at a time (you can delete characters until you press enter)
b) Also, it will automatically convert lower case letters to upper case
c) Unlike the original, but like Kendall's, it allows you to supply "non-words" - for example to check which letters are involved
d) Unlike the original, I've tried to select words with unambiguous spellings, though it's possible I've got some "English" (rather than "American") spellings.

I've supplied a dictionary of ~4500 words, drawn from the ~12000 five letter words in sowpods. I've tried to choose the words so that they will be fairly well known (I've removed what I consider "technical", "foreign", and "obscure" words) - though of course my definition and yours may differ! Please feel free to amend the file as you wish.

Best wishes,

D

PS Edited to correct the flaw mentioned below...
...and the other one...

Code: Select all

      REM   Whirdle - a word game that may seem not terribly unfamiliar to players of Wordle!
      DIM words$(4250)
      f%=OPENIN("FiveletterWords.txt")

      count%=0
      WHILE NOT EOF#f%
        INPUT#f%,t$
        IF LEFT$(t$,1)=CHR$(10) THEN t$=MID$(t$,2)
        IF LEN(t$)=5 THEN
          words$(count%)=t$
          count%+=1
        ENDIF
      ENDWHILE
      CLOSE#f%
      done%= FALSE
      score%=0
      MODE 21
      VDU 5
      WHILE NOT done%
        wordn%=RND(count%)-1
        word$=FNUpper(words$(wordn%))
        CLS
        MOVE 0,1100
        PRINT "Enter a five letter word, and then press 'enter'"
        PROCDrawGrid
        go%=1
        correct%=FALSE
        WHILE go%<7 AND NOT correct%
          guess$=""
          REPEAT
            t%=GET
            IF t% = 8 OR t% = 135 THEN
              REM Backspace/delete
              IF LEN(guess$)>0 THEN
                guess$=LEFT$(guess$)
                GCOL 0
                RECTANGLE FILL 102+ LEN(guess$)*100,1098 - go% * 100,96,-96
                GCOL 15
              ENDIF
            ENDIF
      
            IF t% > 96 AND t% < 123 THEN t% -= 32   :REM convert lower case to upper case
            IF t% > 64 AND t% < 91 AND LEN(guess$) < 6 THEN
              REM Add letter to string and display
              REM GCOL 15
              t$=CHR$(t%)
              guess$ = guess$ + t$
              MOVE 40 + LEN(guess$)*100,1060 - 100 * go%
              PRINT t$
            ENDIF
          UNTIL t% = 13 AND LEN(guess$) = 5
          REM OK, now we need to mark the homework!
          t$ = word$
          IF word$=guess$ THEN correct% = TRUE
          REM First check the correct letters
          FOR x% = 1 TO 5
            IF MID$(guess$,x%,1) = MID$(word$,x%,1) THEN
              REM Right letter, right place!
              GCOL 2
              RECTANGLE FILL 2+ x%*100,1098 - go% * 100,96,-96
              GCOL 15
              MOVE 40 + x%*100,1060 - 100 * go%
              PRINT MID$(guess$,x%,1)
              word$=LEFT$(word$,x%-1)+" "+MID$(word$,x%+1)
            ENDIF
          NEXT x%
          REM Now check for out of place letters
          FOR x% = 1 TO 5
            t% = INSTR(word$,MID$(guess$,x%,1))
            IF  t%>0 AND MID$(word$,x%,1) <> " " THEN
              REM Right letter, wrong place!
              GCOL 7
              RECTANGLE FILL 2+ x%*100,1098 - go% * 100,96,-96
              GCOL 15
              MOVE 40 + x%*100,1060 - 100 * go%
              PRINT MID$(guess$,x%,1)
              word$=LEFT$(word$,t%-1)+"*"+MID$(word$,t%+1)
            ENDIF
          NEXT x%
          word$=t$
          go% += 1
        ENDWHILE
        MOVE 0,200
        IF correct% THEN PRINT "Well done! ";
        PRINT "The correct answer was ";word$
        PRINT "Press any key to play again, or Q to quit"
        q$=GET$
        IF q$ = "q" OR q$ = "Q" THEN done% = TRUE
      ENDWHILE
      END
      :
      DEFPROCDrawGrid
      LOCAL x%,y%
      FOR x% = 0 TO 5
        LINE 100 + 100 * x%,400, 100 + 100 * x%,1000
        LINE 100 ,400 + 100 * x%, 600, 100 * x%+400
      NEXT x%
      LINE 100 ,1000, 600, 1000
      ENDPROC
      :
      DEFFNUpper(w$)
      LOCAL x%,t%,t$
      FOR x%=1 TO 5
        t%=ASC(MID$(w$,x%,1))
        IF t% > 96 AND t% < 123 THEN t% -= 32
        t$ += CHR$(t%)
      NEXT x%
      =t$

You do not have the required permissions to view the files attached to this post.

DDRM
Posts: 398
Joined: Mon 02 Apr 2018, 18:04

Re: WORDLE

Post by DDRM »

Hmm. It seems there's still a bug in it where a letter occurs twice: it is shown grey instead of green even if it is in the right place when only one is given. I thought I'd fixed it, but apparently not...

Edit: OK, found and corrected it...

Edited again: Hmm. Found another one! Edited again again: found and corrected...

KenDown
Posts: 261
Joined: Wed 04 Apr 2018, 06:36

Re: WORDLE

Post by KenDown »

I'm afraid that I prefer my version, where you get feedback as you type. On the other hand, I can see the advantage of being allowed to delete and correct before entry.

Thanks for the dictionary of words.

DDRM
Posts: 398
Joined: Mon 02 Apr 2018, 18:04

Re: WORDLE

Post by DDRM »

Don't be afraid! You wrote it the way you wanted it - there's no point in producing a simple clone of the original!

:-)

D

KenDown
Posts: 261
Joined: Wed 04 Apr 2018, 06:36

Re: WORDLE

Post by KenDown »

From the Daily Mail: "SCORE! Brooklyn-based British engineer who created WORDLE sells five-letter brain teaser that has taken world by storm to the New York Times for seven-figure sum."

Where did we go wrong?

Ric
Posts: 99
Joined: Tue 17 Apr 2018, 21:03

Re: WORDLE

Post by Ric »

I still play the lottery😜😜