Author Topic: Boggle play against AI - WIP  (Read 9322 times)

0 Members and 1 Guest are viewing this topic.

This topic contains a post which is marked as Best Answer. Press here if you would like to see it.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Boggle play against AI - WIP
« on: January 13, 2022, 11:46:33 am »
https://en.wikipedia.org/wiki/Boggle

The AI is going to be handicapped starting with only 1 point words (3 or 4 letters words from Scrabble Dictionary that don't use Q (that is 2 points)) and maybe a shorter time limit too.

Just got started last night from trying to figure out Dimster's "Babble" Game, I thought he might mean Boggle?

Any way got a board working:
Code: QB64: [Select]
  1. _Title "Boggle 1" ' b+ start 2022-01-12
  2. ' Scabble Word List and Dictionary
  3. ' ref dictionary: https://boardgames.stackexchange.com/questions/38366/latest-collins-scrabble-words-list-in-text-file
  4. ' Die configurations
  5. ' https://boardgames.stackexchange.com/questions/29264/boggle-what-is-the-dice-configuration-for-boggle-in-various-languages
  6. ' Thank you!
  7.  
  8. Dim Shared Board$(3, 3)
  9. Dim Shared As Long f48, f30, dx(7), dy(7)
  10. Screen _NewImage(800, 600, 32)
  11. _ScreenMove 200, 100
  12.     Cls
  13.     NewBoard
  14.     ' display timer and allow input of words from user for 3 minutes
  15.     ' meanwhile AI will calc all the 1 point words it can from board
  16.  
  17.     Sleep
  18.  
  19. Sub NewBoard
  20.     Static BeenHere, Di$(), Numbers()
  21.     Dim As Long i, r, c, row, col
  22.     If BeenHere = 0 Then 'load and initialize
  23.         f48 = _LoadFont("Arial.ttf", 48, "MONOSPACE")
  24.         f30 = _LoadFont("Arial.ttf", 30, "MONOSPACE")
  25.         If f48 <= 0 Then Print "Sub NewBoard: Font did not load, goodbye.": End
  26.         dx(0) = -1: dy(0) = -1 ' this is for AI to find words
  27.         dx(1) = 0: dy(1) = -1
  28.         dx(2) = 1: dy(2) = -1
  29.         dx(3) = -1: dy(3) = 0
  30.         dx(4) = 1: dy(4) = 0
  31.         dx(5) = -1: dy(5) = 1
  32.         dx(6) = 0: dy(6) = 1
  33.         dx(7) = 1: dy(7) = 1
  34.         Dim Di$(0 To 15) ' this for 16 di, 6 letters per
  35.         Di$(1) = "RIFOBX"
  36.         Di$(2) = "IFEHEY"
  37.         Di$(3) = "DENOWS"
  38.         Di$(4) = "UTOKND"
  39.         Di$(5) = "HMSRAO"
  40.         Di$(6) = "LUPETS"
  41.         Di$(7) = "ACITOA"
  42.         Di$(8) = "YLGKUE"
  43.         Di$(9) = "QBMJOA"
  44.         Di$(10) = "EHISPN"
  45.         Di$(11) = "VETIGN"
  46.         Di$(12) = "BALIYT"
  47.         Di$(13) = "EZAVND"
  48.         Di$(14) = "RALESC"
  49.         Di$(15) = "UWILRG"
  50.         Di$(0) = "PACEMD"
  51.         Dim Numbers(0 To 15) ' for shuffling die order
  52.         For i = 0 To 15
  53.             Numbers(i) = i
  54.         Next
  55.         BeenHere = -1
  56.     End If
  57.     For i = 15 To 1 Step -1 'shuffle die
  58.         Swap Numbers(i), Numbers(Int(Rnd * (i + 1)))
  59.     Next
  60.     'For i = 1 To 16: Print Numbers(i);: Next: Print   ' check the shuffle
  61.     For i = 0 To 15 'choosing random face of die = 1 Letter
  62.         Index2ColRow i, c, r
  63.         Board$(c, r) = Mid$(Di$(Numbers(i)), Int(Rnd * 6) + 1, 1)
  64.     Next
  65.     _Font f48
  66.     For row = 0 To 3 '  display the board
  67.         For col = 0 To 3
  68.             Line ((col + 1) * 60 - 5, (row + 1) * 60 - 5)-Step(54, 54), &HFF2020FF, BF 'face color or die
  69.             If Board$(col, row) = "Q" Then 'If face has a Q it is supposed to be "Qu"
  70.                 _Font f30
  71.                 Color &HFF661111 'shade
  72.                 _PrintString ((col + 1) * 60 - 4, (row + 1) * 60 + 11), "Q"
  73.                 _PrintString ((col + 1) * 60 + 24, (row + 1) * 60 + 11), "U"
  74.                 Color &HFFBBBBBB 'letter
  75.                 _PrintString ((col + 1) * 60 - 7, (row + 1) * 60 + 9), "Q"
  76.                 _PrintString ((col + 1) * 60 + 22, (row + 1) * 60 + 9), "U"
  77.                 _Font f48
  78.             Else
  79.                 Color &HFF661111 'shade
  80.                 _PrintString ((col + 1) * 60 + 2, (row + 1) * 60 + 2), Board$(col, row)
  81.                 Color &HFFBBBBBB 'letter
  82.                 _PrintString ((col + 1) * 60, (row + 1) * 60), Board$(col, row)
  83.             End If
  84.         Next
  85.     Next
  86.     _Font 16
  87.  
  88. Function ColRow2Index& (row As Long, col As Long) ' convert a board letter to index (not needed yet?)
  89.     ColRow2Index& = row * 4 + col
  90. Sub Index2ColRow (indexIn As Long, rowOut As Long, colOut As Long) 'convert die index to board col, row
  91.     colOut = indexIn Mod 4: rowOut = indexIn \ 4
  92.  

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Boggle play against AI - WIP
« Reply #1 on: January 13, 2022, 06:14:12 pm »
Dang the Collins Dictionary is too big to load, QB64 keeps bugging out, no error message, just quits.
279,496 words

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Boggle play against AI - WIP
« Reply #2 on: January 14, 2022, 08:15:13 am »
The amount of words I could store and not in terrible time was about 260,000 before QB64 (on my Windows 10 laptop system) bugged out without so much as error message, at least it didn't crash the whole system. Tried Open For Input and Open For Binary, one gulp method. OK it's 2.96 MB according to properties Window.

I have already worked a fairly practical workaround by limiting the words by number of letters, another maybe not to load the dictionary at all and just search for words in the hard disk by turning it into a Random access file or something.

But I wonder if there is another way to get the dictionary loaded into program whole. Is about 1 MB the limit for variable length string memory?
« Last Edit: January 14, 2022, 08:30:03 am by bplus »

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Boggle play against AI - WIP
« Reply #3 on: January 14, 2022, 08:42:07 am »
Oh boy! Just got the trickiest Function working :)

It's the one that confirms a word can or can not be legally built from a given board. Interestingly it uses a recursive function to seek out the rest of the word from a given letter location once the first letter has been matched from the game board. I am a bit shocked, it's like magic :)

 (Of course the shock would have been worse had it worked right off.)

Update: OK same logic bug happened in the recursive helper function, more subtle, I think I have them exterminated now.
« Last Edit: January 14, 2022, 10:23:09 am by bplus »

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Boggle play against AI - WIP
« Reply #4 on: January 14, 2022, 12:37:46 pm »
That AI looks like it will need more handicap, here is what it came up with in 30 secs. Looks like that was enough time to test the whole dang OnePointList$(). I've still got to work out dealing with special case Q amongst checking player redundant words, scoring and handicapping.

The first test of AI play:
 
Boggle 1 WIP.PNG


WIP:
Code: QB64: [Select]
  1. _Title "Boggle 1" ' b+ start 2022-01-12
  2. ' Scabble Word List and Dictionary
  3. ' ref dictionary: https://boardgames.stackexchange.com/questions/38366/latest-collins-scrabble-words-list-in-text-file
  4. ' Die configurations
  5. ' https://boardgames.stackexchange.com/questions/29264/boggle-what-is-the-dice-configuration-for-boggle-in-various-languages
  6. ' Thank you!
  7.  
  8. ' 2022-01-14 status have the board display separated out from New Board and Game initialization
  9. ' have timer system and display working next to board display
  10. ' have player input system working
  11. '   1. check word in dictionary working
  12. '   2. check that word can legally be built from board is funky! sometimes works sometimes not 50/50 for legit builds yuck
  13. '     How to debug? Todays task is get this abolutely critical function working so the AI would be fairly easy to do.
  14. ' Oh I had to modify the Collins Word list to get a size that would fit into a variable length string array, 279496 words
  15. ' kept crashing QB64 without error messages when reached about 260,000 words so now I have a list for words with lengths of
  16. ' between 3 and 10, still 199,651 words!
  17. ' 2202-01-14 Hurray! Function wordBuildOK& is fixed, a very simple logic bug. I continued to check for builds of word after
  18. ' I got confirmation one of the builds was possible. It kept checking if there was more than one place the first letter of word
  19. ' appeared. The function is crucial for AI testing if words are buildable. I can get started on that today now that bug is
  20. ' fixed. Man! I had this fixed almost immediately, I had to exit the Function when the recursive function findCell& called from
  21. ' it found a positive result. AI is working.
  22.  
  23. Const TimeLimit = 180 ' actual game time is 3 minutes = 180 secs
  24. Dim Shared Board$(3, 3), WordList$(1 To 199651), OnePointList$(1 To 6955)
  25. Dim Shared As Long f48, f30, dx(7), dy(7)
  26. Dim Shared As Double BoggleTime, elapsed
  27. Dim w$, k$, player$, AI$
  28. Dim As Long printLine
  29. Screen _NewImage(800, 600, 32)
  30. _ScreenMove 200, 100
  31.     NewBoard
  32.     DisplayBoard
  33.     elapsed = 0
  34.     'Do ' display timer and allow input of words from user for 3 minutes
  35.     printLine = 20
  36.     player$ = "": w$ = ""
  37.     While elapsed < TimeLimit ' do stuff   <<<<<<<<<<<<<<<<<<<<<< off while debug wordBuildOK
  38.         Cls
  39.         DisplayBoard
  40.         elapsed = Timer(.01) - BoggleTime
  41.         If elapsed < 0 Then elapsed = 24 * 60 * 60 + Timer(.01) - BoggleTime ' midnight problem add aday of seconds to timer and subtr boogle
  42.         _Font f48
  43.         Line (300, 240)-Step(180, 60), &HFF000000, BF ' blackout last time
  44.         Color &HFFFFFF00
  45.         _PrintString (300, 240), _Trim$(Str$(TimeLimit - Int(elapsed)))
  46.  
  47.         _Font 16
  48.         Color _RGB32(200, 200, 255)
  49.         k$ = UCase$(InKey$)
  50.         If Len(k$) Then 'handle 1 and 2 char key presses, maybe replace with _keyhit later
  51.             Select Case Len(k$)
  52.                 Case 1
  53.                     Select Case Asc(k$)
  54.                         Case 3 'Ctrl + C   another way to clear?
  55.                             w$ = ""
  56.                         Case 8 ' backspace          more to do
  57.                             If Len(w$) Then w$ = Left$(w$, Len(w$) - 1)
  58.                         Case 13
  59.                             If wordBuildOK&(w$) Then
  60.                                 If Find&(WordList$(), w$) Then ' check words before add to player$
  61.                                     If player$ = "" Then player$ = w$ Else player$ = player$ + " " + w$
  62.                                 End If
  63.                             End If
  64.                             w$ = ""
  65.                         Case 27 'esc
  66.                             w$ = "" ': exit ?
  67.                         Case Else
  68.                             If 63 < Asc(k$) And Asc(k$) < 91 Then w$ = w$ + k$
  69.                     End Select
  70.             End Select
  71.         End If
  72.         Locate printLine, 1: Print w$
  73.         Locate printLine + 2, 1: Print player$
  74.  
  75.         _Display
  76.         _Limit 60
  77.     Wend
  78.     _PrintString (400, 240), "Times up!"
  79.  
  80.     'lets see what the AI comes up with
  81.     AI$ = AIwords$(30) ' try 30 secs for starters
  82.     Locate printLine + 6, 1
  83.     Print "AI: "; AI$
  84.  
  85.     Sleep
  86.  
  87. Sub NewBoard
  88.     Static BeenHere, Di$(), Numbers()
  89.     Dim As Long i, r, c
  90.  
  91.     If BeenHere = 0 Then 'load and initialize all the one time stuff
  92.         ' load fonts
  93.         f48 = _LoadFont("Arial.ttf", 48, "MONOSPACE")
  94.         f30 = _LoadFont("Arial.ttf", 30, "MONOSPACE")
  95.         If f48 <= 0 Then Print "Sub NewBoard: Font did not load, goodbye.": End
  96.  
  97.         'load abrev Dictionary ======================================== comment out while debug wordBuildOK
  98.         Open "3 to 10 Letter Words.txt" For Input As #1
  99.         Print "Loading Dictionary..."
  100.         While Not EOF(1)
  101.             i = i + 1
  102.             Input #1, WordList$(i)
  103.             'Cls: Locate 2, 1: Print i
  104.         Wend
  105.         Close #1
  106.  
  107.         ' test load of file, find last 10 items
  108.         'For i = 199651 - 10 To 199651
  109.         '    Print WordList$(i)
  110.         'Next
  111.         'Sleep    OK loading
  112.  
  113.         Open "Boggle 1 Point Words.txt" For Input As #1
  114.         Print "Loading Boggle 1 Point Words.txt for AI..."
  115.         i = 0
  116.         While Not EOF(1)
  117.             i = i + 1
  118.             Input #1, OnePointList$(i)
  119.         Wend
  120.         Close #1
  121.  
  122.         ' load dx(), dy() for testing the legality of words built from board
  123.         dx(0) = -1: dy(0) = -1 ' this is for AI to find words
  124.         dx(1) = 0: dy(1) = -1
  125.         dx(2) = 1: dy(2) = -1
  126.         dx(3) = -1: dy(3) = 0
  127.         dx(4) = 1: dy(4) = 0
  128.         dx(5) = -1: dy(5) = 1
  129.         dx(6) = 0: dy(6) = 1
  130.         dx(7) = 1: dy(7) = 1
  131.  
  132.         ' These are the 16 Dice with 6 Faces of a Letter need for Boggle
  133.         Dim Di$(0 To 15) ' this for 16 di, 6 letters per
  134.         Di$(1) = "RIFOBX"
  135.         Di$(2) = "IFEHEY"
  136.         Di$(3) = "DENOWS"
  137.         Di$(4) = "UTOKND"
  138.         Di$(5) = "HMSRAO"
  139.         Di$(6) = "LUPETS"
  140.         Di$(7) = "ACITOA"
  141.         Di$(8) = "YLGKUE"
  142.         Di$(9) = "QBMJOA"
  143.         Di$(10) = "EHISPN"
  144.         Di$(11) = "VETIGN"
  145.         Di$(12) = "BALIYT"
  146.         Di$(13) = "EZAVND"
  147.         Di$(14) = "RALESC"
  148.         Di$(15) = "UWILRG"
  149.         Di$(0) = "PACEMD"
  150.  
  151.         Dim Numbers(0 To 15) ' load numbers for shuffling die order
  152.         For i = 0 To 15
  153.             Numbers(i) = i
  154.         Next
  155.         BeenHere = -1
  156.     End If
  157.  
  158.     'now get the game going
  159.     For i = 15 To 1 Step -1 'shuffle die
  160.         Swap Numbers(i), Numbers(Int(Rnd * (i + 1)))
  161.     Next
  162.     'For i = 1 To 16: Print Numbers(i);: Next: Print   ' check the shuffle
  163.     For i = 0 To 15 'choosing random face of die = 1 Letter
  164.         Index2ColRow i, c, r
  165.         Board$(c, r) = Mid$(Di$(Numbers(i)), Int(Rnd * 6) + 1, 1)
  166.     Next
  167.     ' now set timer + 180
  168.     BoggleTime = Timer(.01)
  169.     _Font 16
  170.  
  171. Sub DisplayBoard
  172.     Dim row, col
  173.     _Font f48
  174.     For row = 0 To 3 '  display the board
  175.         For col = 0 To 3
  176.             Line ((col + 1) * 60 - 5, (row + 1) * 60 - 5)-Step(54, 54), &HFF2020FF, BF 'face color or die
  177.             If Board$(col, row) = "Q" Then 'If face has a Q it is supposed to be "Qu"
  178.                 _Font f30
  179.                 Color &HFF661111 'shade
  180.                 _PrintString ((col + 1) * 60 - 4, (row + 1) * 60 + 11), "Q"
  181.                 _PrintString ((col + 1) * 60 + 24, (row + 1) * 60 + 11), "U"
  182.                 Color &HFFBBBBBB 'letter
  183.                 _PrintString ((col + 1) * 60 - 7, (row + 1) * 60 + 9), "Q"
  184.                 _PrintString ((col + 1) * 60 + 22, (row + 1) * 60 + 9), "U"
  185.                 _Font f48
  186.             Else
  187.                 Color &HFF661111 'shade
  188.                 _PrintString ((col + 1) * 60 + 2, (row + 1) * 60 + 2), Board$(col, row)
  189.                 Color &HFFBBBBBB 'letter
  190.                 _PrintString ((col + 1) * 60, (row + 1) * 60), Board$(col, row)
  191.             End If
  192.         Next
  193.     Next
  194.  
  195. Function ColRow2Index& (row As Long, col As Long) ' convert a board letter to index (not needed yet?)
  196.     ColRow2Index& = row * 4 + col
  197. Sub Index2ColRow (indexIn As Long, rowOut As Long, colOut As Long) 'convert die index to board col, row
  198.     colOut = indexIn Mod 4: rowOut = indexIn \ 4
  199.  
  200. Sub Split (SplitMeString As String, delim As String, loadMeArray() As String)
  201.     Dim curpos As Long, arrpos As Long, LD As Long, dpos As Long 'fix use the Lbound the array already has
  202.     curpos = 1: arrpos = LBound(loadMeArray): LD = Len(delim)
  203.     dpos = InStr(curpos, SplitMeString, delim)
  204.     Do Until dpos = 0
  205.         loadMeArray(arrpos) = Mid$(SplitMeString, curpos, dpos - curpos)
  206.         arrpos = arrpos + 1
  207.         If arrpos > UBound(loadMeArray) Then ReDim _Preserve loadMeArray(LBound(loadMeArray) To UBound(loadMeArray) + 1000) As String
  208.         curpos = dpos + LD
  209.         dpos = InStr(curpos, SplitMeString, delim)
  210.     Loop
  211.     loadMeArray(arrpos) = Mid$(SplitMeString, curpos)
  212.     ReDim _Preserve loadMeArray(LBound(loadMeArray) To arrpos) As String 'get the ubound correct
  213.  
  214. Function Find& (SortedArr$(), x$) ' if I am using this only to find words in dictionary, I can mod to optimize
  215.     Dim As Long low, hi, test
  216.     low = LBound(SortedArr$): hi = UBound(SortedArr$)
  217.     While low <= hi
  218.         test = Int((low + hi) / 2)
  219.         If SortedArr$(test) = x$ Then
  220.             Find& = test: Exit Function
  221.         Else
  222.             If SortedArr$(test) < x$ Then low = test + 1 Else hi = test - 1
  223.         End If
  224.     Wend
  225.  
  226. Function wordBuildOK& (w$) ' this function checks to see that the was constructed (or is constructable with the given board).
  227.     Dim As Long r, c, test
  228.     Dim copy$(-1 To 4, -1 To 4), first$
  229.     For r = 0 To 3
  230.         For c = 0 To 3
  231.             copy$(c, r) = Board$(c, r)
  232.         Next
  233.     Next
  234.  
  235.     first$ = Mid$(w$, 1, 1)
  236.     For r = 0 To 3
  237.         For c = 0 To 3
  238.             If copy$(c, r) = first$ Then 'cell letter matches first letter in word
  239.                 test = findCell&(c, r, w$, 2, copy$())
  240.                 If test Then wordBuildOK& = -1: Exit Function ' ah ha! maybe it keeps trying when we are supposed to be done, fix?
  241.             End If
  242.         Next
  243.     Next
  244.  
  245. 'recursively called starting from wordBuildOK&
  246. Function findCell& (startX As Long, startY As Long, word$, index As Long, Arr$()) ' want to setup recursive searcher
  247.     Dim As Long d, x, y, i, r, c, test
  248.     Dim w$
  249.     'make own set of variables for this function  (attempt to debug but did not fix anything)
  250.     Dim a$(-1 To 4, -1 To 4)
  251.     For r = 0 To 3
  252.         For c = 0 To 3
  253.             a$(c, r) = Arr$(c, r)
  254.         Next
  255.     Next
  256.     i = index: w$ = word$: y = startY: x = startX
  257.     If i > Len(w$) Then findCell = -1: Exit Function
  258.     a$(x, y) = "" 'so wont be used again
  259.     For d = 0 To 7
  260.         If a$(x + dx(d), y + dy(d)) = Mid$(w$, i, 1) Then
  261.             test = findCell&(x + dx(d), y + dy(d), w$, i + 1, a$())
  262.             If test Then findCell& = -1: Exit Function
  263.         End If
  264.     Next
  265.  
  266. Function AIwords$ (timeLimit As Long) 'returns a space delimiter string of 1 point words that can be constructed from board in limited time
  267.     Dim As Double startTime, checkTime
  268.     Dim As Long i, r, c, OK, dp, l, ub
  269.     Dim l$, letters$, b$
  270.     startTime = Timer(.01)
  271.     ub = UBound(OnePointList$)
  272.     ' get a non redundant list of letters from board
  273.     For r = 0 To 3
  274.         For c = 0 To 3
  275.             l$ = Board$(c, r)
  276.             If (r = 0) And (c = 0) Then
  277.                 letters$ = l$
  278.             Else
  279.                 If InStr(letters$, l$) <= 0 Then '  insrt letter
  280.                     OK = 0
  281.                     For i = 1 To Len(letters$)
  282.                         If Asc(l$) < Asc(letters$, i) Then ' insert spotted
  283.                             If i = 1 Then
  284.                                 letters$ = l$ + letters$: OK = -1: Exit For
  285.                             Else
  286.                                 letters$ = Mid$(letters$, 1, i - 1) + l$ + Mid$(letters$, i)
  287.                                 OK = -1: Exit For
  288.                             End If
  289.                         End If
  290.                     Next
  291.                     If OK = 0 Then letters$ = letters$ + l$
  292.                 End If
  293.             End If
  294.         Next
  295.     Next
  296.     'check if this is OK so far  OK finally!  This is 3rd time I needed to exit when found
  297.     ' AIwords$ = letters$
  298.     'now letters of board are in alpha order
  299.     dp = 1 'place in dict
  300.     For l = 1 To Len(letters$) ' advance place in list$ by one until the word > letter
  301.         While Asc(OnePointList$(dp), 1) < Asc(letters$, l)
  302.             dp = dp + 1
  303.             If dp > ub Then GoTo fini
  304.             If Timer(.01) - startTime < 0 Then checkTime = Timer(.01) + 24 * 60 * 60 Else checkTime = Timer(.01)
  305.             If checkTime - startTime > timeLimit Then GoTo fini
  306.         Wend
  307.         'now start testing words
  308.         While Asc(OnePointList$(dp), 1) = Asc(letters$, l)
  309.             If wordBuildOK&(OnePointList$(dp)) Then
  310.                 If b$ = "" Then b$ = OnePointList$(dp) Else b$ = b$ + " " + OnePointList$(dp)
  311.             End If
  312.             dp = dp + 1
  313.             If dp > ub Then GoTo fini
  314.             If Timer(.01) - startTime < 0 Then checkTime = Timer(.01) + 24 * 60 * 60 Else checkTime = Timer(.01)
  315.             If checkTime - startTime > timeLimit Then GoTo fini
  316.         Wend
  317.     Next
  318.  
  319.     fini:
  320.     AIwords$ = b$

Offline Statsman1

  • Newbie
  • Posts: 36
  • I'm just a jerk, but a hero is what I want to be.
    • View Profile
Re: Boggle play against AI - WIP
« Reply #5 on: January 14, 2022, 01:05:31 pm »
@bplus - Dude, you are on FIRE.  Fantastic stuff so quickly!
Good decisions come from experience.
Experience comes from bad decisions.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Boggle play against AI - WIP
« Reply #6 on: January 14, 2022, 03:15:20 pm »
@bplus - Dude, you are on FIRE.  Fantastic stuff so quickly!

Gotta say, @Statsman1 you are helping fan the fire, thanks for your enthusiastic interest.

Offline Statsman1

  • Newbie
  • Posts: 36
  • I'm just a jerk, but a hero is what I want to be.
    • View Profile
Re: Boggle play against AI - WIP
« Reply #7 on: January 14, 2022, 03:39:49 pm »
Gotta say, @Statsman1 you are helping fan the fire, thanks for your enthusiastic interest.

I love word games, so this is just great stuff.  I really appreciate that you would do all of this.
Good decisions come from experience.
Experience comes from bad decisions.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Boggle play against AI - WIP
« Reply #8 on: January 14, 2022, 03:51:41 pm »
I love word games, so this is just great stuff.  I really appreciate that you would do all of this.

Ah word games, checkout @Qwerkey plus crosswords and another about snaking word around a grid maybe like Boggle? It was from a newspaper puzzle and it was awhile ago and I may have author confused with someone else?

Bplus also did WordSearch had a pretty good package for Rosetta Code Challenge but interacting with Richard Frost and his work of getting all the elements of periodic table to fit in a grid really improved my game. I think I got to point of building word searches for your own list of items.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Boggle play against AI - WIP
« Reply #9 on: January 15, 2022, 12:13:53 pm »
OK I have basic game roughed out. Now I am handling the Q(u) Letter better still needs more testing. I need a qu? word that is 3 letters with u, to see if you type 2 letters the first a q and enter q? the word will be added to your list. BTW the 1 Point List that the AI uses doesn't have any Q words because originally I thought Q words were 2 points. No Q words contain the hidden letter U which could potentially make the word a letter longer that the one you type and points are awarded by number of letters. All the goofiness in coding could have been simplified by having 1 die with Q and maybe a couple extra u's and other vowels. That may be a mod down the line from here 17 dice, the 17th with aeiouu. This game is boring if have a whole bunch of constanents (sp? for not-a-vowel).

Now there is a Sleep between seeing your list and AI's before matching words are removed from both lists and final score calculated and shown. Yours will likely be 0 unless you come up with 5 or more letter words but at lest all your 3-4 letter word will negate the AI's.

Code: QB64: [Select]
  1. _Title "Boggle 1" ' b+ start 2022-01-12
  2. ' Scabble Word List and Dictionary
  3. ' ref dictionary: https://boardgames.stackexchange.com/questions/38366/latest-collins-scrabble-words-list-in-text-file
  4. ' Die configurations
  5. ' https://boardgames.stackexchange.com/questions/29264/boggle-what-is-the-dice-configuration-for-boggle-in-various-languages
  6. ' Thank you!
  7.  
  8. ' 2022-01-14 status have the board display separated out from New Board and Game initialization
  9. ' have timer system and display working next to board display
  10. ' have player input system working
  11. '   1. check word in dictionary working
  12. '   2. check that word can legally be built from board is funky! sometimes works sometimes not 50/50 for legit builds yuck
  13. '     How to debug? Todays task is get this abolutely critical function working so the AI would be fairly easy to do.
  14. ' Oh I had to modify the Collins Word list to get a size that would fit into a variable length string array, 279496 words
  15. ' kept crashing QB64 without error messages when reached about 260,000 words so now I have a list for words with lengths of
  16. ' between 3 and 10, still 199,651 words!
  17. ' 2202-01-14 Hurray! Function wordBuildOK& is fixed, a very simple logic bug. I continued to check for builds of word after
  18. ' I got confirmation one of the builds was possible. It kept checking if there was more than one place the first letter of word
  19. ' appeared. The function is crucial for AI testing if words are buildable. I can get started on that today now that bug is
  20. ' fixed. Man! I had this fixed almost immediately, I had to exit the Function when the recursive function findCell& called from
  21. ' it found a positive result.
  22.  
  23. ' 2022-01-15 qw$() function to handle the Q letter, function to handle scoring, main removes matching words on the 2 lists.
  24. ' you should be able to type 2 letters with (qu) square and get a 3 letter word.
  25.  
  26. Const TimeLimit = 180 ' actual game time is 3 minutes = 180 secs
  27. Dim Shared Board$(3, 3), WordList$(1 To 199651), OnePointList$(1 To 6955)
  28. Dim Shared As Long f48, f30, dx(7), dy(7)
  29. Dim Shared As Double BoggleTime, elapsed
  30. Dim w$, k$, player$, AI$
  31. Dim As Long printLine, pScore, aiScore, uba, ubp, i, j
  32. Screen _NewImage(800, 600, 32)
  33. _ScreenMove 200, 100
  34.     NewBoard
  35.     DisplayBoard
  36.     elapsed = 0
  37.     'Do ' display timer and allow input of words from user for 3 minutes
  38.     printLine = 20
  39.     player$ = "": w$ = ""
  40.     While elapsed < TimeLimit ' do stuff   <<<<<<<<<<<<<<<<<<<<<< off while debug wordBuildOK
  41.         Cls
  42.         DisplayBoard
  43.         elapsed = Timer(.01) - BoggleTime
  44.         If elapsed < 0 Then elapsed = 24 * 60 * 60 + Timer(.01) - BoggleTime ' midnight problem add aday of seconds to timer and subtr boogle
  45.         _Font f48
  46.         Line (300, 240)-Step(180, 60), &HFF000000, BF ' blackout last time
  47.         Color &HFFFFFF00
  48.         _PrintString (300, 240), _Trim$(Str$(TimeLimit - Int(elapsed)))
  49.  
  50.         _Font 16
  51.         Color _RGB32(200, 200, 255)
  52.         k$ = UCase$(InKey$)
  53.         If Len(k$) Then 'handle 1 and 2 char key presses, maybe replace with _keyhit later
  54.             Select Case Len(k$)
  55.                 Case 1
  56.                     Select Case Asc(k$)
  57.                         Case 3 'Ctrl + C   another way to clear?
  58.                             w$ = ""
  59.                         Case 8 ' backspace          more to do
  60.                             If Len(w$) Then w$ = Left$(w$, Len(w$) - 1)
  61.                         Case 13
  62.                             If wordBuildOK&(w$) Then
  63.                                 If Find&(WordList$(), qw$(w$)) Then ' check words before add to player$
  64.                                     If player$ = "" Then player$ = qw$(w$) Else player$ = player$ + " " + qw$(w$)
  65.                                 End If
  66.                             End If
  67.                             w$ = ""
  68.                         Case 27 'esc
  69.                             w$ = "" ': exit ?
  70.                         Case Else
  71.                             If 63 < Asc(k$) And Asc(k$) < 91 Then w$ = w$ + k$
  72.                     End Select
  73.             End Select
  74.         End If
  75.         Locate printLine, 1: Print w$
  76.         Locate printLine + 2, 1: Print player$
  77.  
  78.         _Display
  79.         _Limit 60
  80.     Wend
  81.     _PrintString (400, 240), "Times up!"
  82.  
  83.     'lets see what the AI comes up with
  84.     AI$ = AIwords$(.07) ' try 30 secs for starters, 5 still gets a complete list, try 1 sec  OK that doesn't quite finish
  85.     Locate printLine + 6, 1: Print "AI: "; AI$
  86.     Print
  87.     Print "          zzz... Press any for the time of reconning,"
  88.     Print "   matching words on 2 lists will be removed and the round scored."
  89.     Sleep
  90.     ' evalaute results (remove matching words in lists) and score
  91.     Cls
  92.     DisplayBoard
  93.     _Font 16
  94.     player$ = removeRepeats$(player$)
  95.     ReDim p(1 To 1) As String
  96.     Split player$, " ", p()
  97.     ubp = UBound(p)
  98.     ReDim a(1 To 1) As String
  99.     Split AI$, " ", a()
  100.     uba = UBound(a)
  101.     For i = 1 To uba
  102.         For j = 1 To ubp
  103.             If a(i) = p(j) Then a(i) = "": p(j) = ""
  104.         Next
  105.     Next
  106.     pScore = score&(p())
  107.     aiScore = score&(a())
  108.     AI$ = ""
  109.     player$ = ""
  110.     For i = 1 To uba
  111.         If a(i) <> "" Then AI$ = AI$ + " " + a(i)
  112.     Next
  113.     For i = 1 To ubp
  114.         If p(i) <> "" Then player$ = player$ + " " + p(i)
  115.     Next
  116.     Locate printLine + 1, 1: Print "Player:"; player$
  117.     Print " Score:"; pScore
  118.     Locate printLine + 6, 1: Print "AI:"; AI$
  119.     Print " Score:"; aiScore
  120.     Sleep
  121.  
  122. Sub NewBoard
  123.     Static BeenHere, Di$(), Numbers()
  124.     Dim As Long i, r, c
  125.  
  126.     If BeenHere = 0 Then 'load and initialize all the one time stuff
  127.         ' load fonts
  128.         f48 = _LoadFont("Arial.ttf", 48, "MONOSPACE")
  129.         f30 = _LoadFont("Arial.ttf", 30, "MONOSPACE")
  130.         If f48 <= 0 Then Print "Sub NewBoard: Font did not load, goodbye.": End
  131.  
  132.         'load abrev Dictionary ======================================== comment out while debug wordBuildOK
  133.         Open "3 to 10 Letter Words.txt" For Input As #1
  134.         Print "Loading Dictionary..."
  135.         While Not EOF(1)
  136.             i = i + 1
  137.             Input #1, WordList$(i)
  138.             'Cls: Locate 2, 1: Print i
  139.         Wend
  140.         Close #1
  141.  
  142.         ' test load of file, find last 10 items
  143.         'For i = 199651 - 10 To 199651
  144.         '    Print WordList$(i)
  145.         'Next
  146.         'Sleep    OK loading
  147.  
  148.         Open "Boggle 1 Point Words.txt" For Input As #1
  149.         Print "Loading Boggle 1 Point Words.txt for AI..."
  150.         i = 0
  151.         While Not EOF(1)
  152.             i = i + 1
  153.             Input #1, OnePointList$(i)
  154.         Wend
  155.         Close #1
  156.  
  157.         ' load dx(), dy() for testing the legality of words built from board
  158.         dx(0) = -1: dy(0) = -1 ' this is for AI to find words
  159.         dx(1) = 0: dy(1) = -1
  160.         dx(2) = 1: dy(2) = -1
  161.         dx(3) = -1: dy(3) = 0
  162.         dx(4) = 1: dy(4) = 0
  163.         dx(5) = -1: dy(5) = 1
  164.         dx(6) = 0: dy(6) = 1
  165.         dx(7) = 1: dy(7) = 1
  166.  
  167.         ' These are the 16 Dice with 6 Faces of a Letter need for Boggle
  168.         Dim Di$(0 To 15) ' this for 16 di, 6 letters per
  169.         Di$(1) = "RIFOBX"
  170.         Di$(2) = "IFEHEY"
  171.         Di$(3) = "DENOWS"
  172.         Di$(4) = "UTOKND"
  173.         Di$(5) = "HMSRAO"
  174.         Di$(6) = "LUPETS"
  175.         Di$(7) = "ACITOA"
  176.         Di$(8) = "YLGKUE"
  177.         Di$(9) = "QBMJOA"
  178.         Di$(10) = "EHISPN"
  179.         Di$(11) = "VETIGN"
  180.         Di$(12) = "BALIYT"
  181.         Di$(13) = "EZAVND"
  182.         Di$(14) = "RALESC"
  183.         Di$(15) = "UWILRG"
  184.         Di$(0) = "PACEMD"
  185.  
  186.         Dim Numbers(0 To 15) ' load numbers for shuffling die order
  187.         For i = 0 To 15
  188.             Numbers(i) = i
  189.         Next
  190.         BeenHere = -1
  191.     End If
  192.  
  193.     'now get the game going
  194.     For i = 15 To 1 Step -1 'shuffle die
  195.         Swap Numbers(i), Numbers(Int(Rnd * (i + 1)))
  196.     Next
  197.     'For i = 1 To 16: Print Numbers(i);: Next: Print   ' check the shuffle
  198.     For i = 0 To 15 'choosing random face of die = 1 Letter
  199.         Index2ColRow i, c, r
  200.         Board$(c, r) = Mid$(Di$(Numbers(i)), Int(Rnd * 6) + 1, 1)
  201.     Next
  202.     ' now set timer + 180
  203.     BoggleTime = Timer(.01)
  204.     _Font 16
  205.  
  206. Sub DisplayBoard
  207.     Dim row, col
  208.     _Font f48
  209.     For row = 0 To 3 '  display the board
  210.         For col = 0 To 3
  211.             Line ((col + 1) * 60 - 5, (row + 1) * 60 - 5)-Step(54, 54), &HFF2020FF, BF 'face color or die
  212.             If Board$(col, row) = "Q" Then 'If face has a Q it is supposed to be "Qu"
  213.                 _Font f30
  214.                 Color &HFF661111 'shade
  215.                 _PrintString ((col + 1) * 60 - 4, (row + 1) * 60 + 11), "Q"
  216.                 _PrintString ((col + 1) * 60 + 24, (row + 1) * 60 + 11), "U"
  217.                 Color &HFFBBBBBB 'letter
  218.                 _PrintString ((col + 1) * 60 - 7, (row + 1) * 60 + 9), "Q"
  219.                 _PrintString ((col + 1) * 60 + 22, (row + 1) * 60 + 9), "U"
  220.                 _Font f48
  221.             Else
  222.                 Color &HFF661111 'shade
  223.                 _PrintString ((col + 1) * 60 + 2, (row + 1) * 60 + 2), Board$(col, row)
  224.                 Color &HFFBBBBBB 'letter
  225.                 _PrintString ((col + 1) * 60, (row + 1) * 60), Board$(col, row)
  226.             End If
  227.         Next
  228.     Next
  229.  
  230. Function ColRow2Index& (row As Long, col As Long) ' convert a board letter to index (not needed yet?)
  231.     ColRow2Index& = row * 4 + col
  232. Sub Index2ColRow (indexIn As Long, rowOut As Long, colOut As Long) 'convert die index to board col, row
  233.     colOut = indexIn Mod 4: rowOut = indexIn \ 4
  234.  
  235. Sub Split (SplitMeString As String, delim As String, loadMeArray() As String)
  236.     Dim curpos As Long, arrpos As Long, LD As Long, dpos As Long 'fix use the Lbound the array already has
  237.     curpos = 1: arrpos = LBound(loadMeArray): LD = Len(delim)
  238.     dpos = InStr(curpos, SplitMeString, delim)
  239.     Do Until dpos = 0
  240.         loadMeArray(arrpos) = Mid$(SplitMeString, curpos, dpos - curpos)
  241.         arrpos = arrpos + 1
  242.         If arrpos > UBound(loadMeArray) Then ReDim _Preserve loadMeArray(LBound(loadMeArray) To UBound(loadMeArray) + 1000) As String
  243.         curpos = dpos + LD
  244.         dpos = InStr(curpos, SplitMeString, delim)
  245.     Loop
  246.     loadMeArray(arrpos) = Mid$(SplitMeString, curpos)
  247.     ReDim _Preserve loadMeArray(LBound(loadMeArray) To arrpos) As String 'get the ubound correct
  248.  
  249. Function Find& (SortedArr$(), x$) ' if I am using this only to find words in dictionary, I can mod to optimize
  250.     Dim As Long low, hi, test
  251.     low = LBound(SortedArr$): hi = UBound(SortedArr$)
  252.     While low <= hi
  253.         test = Int((low + hi) / 2)
  254.         If SortedArr$(test) = x$ Then
  255.             Find& = test: Exit Function
  256.         Else
  257.             If SortedArr$(test) < x$ Then low = test + 1 Else hi = test - 1
  258.         End If
  259.     Wend
  260.  
  261. Function wordBuildOK& (w$) ' this function checks to see that the was constructed (or is constructable with the given board).
  262.     Dim As Long r, c, test
  263.     Dim copy$(-1 To 4, -1 To 4), first$
  264.     For r = 0 To 3
  265.         For c = 0 To 3
  266.             copy$(c, r) = Board$(c, r)
  267.         Next
  268.     Next
  269.  
  270.     first$ = Mid$(w$, 1, 1)
  271.     For r = 0 To 3
  272.         For c = 0 To 3
  273.             If copy$(c, r) = first$ Then 'cell letter matches first letter in word
  274.                 test = findCell&(c, r, w$, 2, copy$())
  275.                 If test Then wordBuildOK& = -1: Exit Function ' ah ha! maybe it keeps trying when we are supposed to be done, fix?
  276.             End If
  277.         Next
  278.     Next
  279.  
  280. 'recursively called starting from wordBuildOK&
  281. Function findCell& (startX As Long, startY As Long, word$, index As Long, Arr$()) ' want to setup recursive searcher
  282.     Dim As Long d, x, y, i, r, c, test
  283.     Dim w$
  284.     'make own set of variables for this function  (attempt to debug but did not fix anything)
  285.     Dim a$(-1 To 4, -1 To 4)
  286.     For r = 0 To 3
  287.         For c = 0 To 3
  288.             a$(c, r) = Arr$(c, r)
  289.         Next
  290.     Next
  291.     i = index: w$ = word$: y = startY: x = startX
  292.     If i > Len(w$) Then findCell = -1: Exit Function
  293.     a$(x, y) = "" 'so wont be used again
  294.     For d = 0 To 7
  295.         If a$(x + dx(d), y + dy(d)) = Mid$(w$, i, 1) Then
  296.             test = findCell&(x + dx(d), y + dy(d), w$, i + 1, a$())
  297.             If test Then findCell& = -1: Exit Function
  298.         End If
  299.     Next
  300.  
  301. Function AIwords$ (timeLimit As Double) 'returns a space delimiter string of 1 point words that can be constructed from board in limited time
  302.     Dim As Double startTime, checkTime
  303.     Dim As Long i, r, c, OK, dp, l, ub
  304.     Dim l$, letters$, b$
  305.     startTime = Timer(.01)
  306.     ub = UBound(OnePointList$)
  307.     ' get a non redundant list of letters from board
  308.     For r = 0 To 3
  309.         For c = 0 To 3
  310.             l$ = Board$(c, r)
  311.             If (r = 0) And (c = 0) Then
  312.                 letters$ = l$
  313.             Else
  314.                 If InStr(letters$, l$) <= 0 Then '  insrt letter
  315.                     OK = 0
  316.                     For i = 1 To Len(letters$)
  317.                         If Asc(l$) < Asc(letters$, i) Then ' insert spotted
  318.                             If i = 1 Then
  319.                                 letters$ = l$ + letters$: OK = -1: Exit For
  320.                             Else
  321.                                 letters$ = Mid$(letters$, 1, i - 1) + l$ + Mid$(letters$, i)
  322.                                 OK = -1: Exit For
  323.                             End If
  324.                         End If
  325.                     Next
  326.                     If OK = 0 Then letters$ = letters$ + l$
  327.                 End If
  328.             End If
  329.         Next
  330.     Next
  331.     'check if this is OK so far  OK finally!  This is 3rd time I needed to exit when found
  332.     ' AIwords$ = letters$
  333.     'now letters of board are in alpha order
  334.     dp = 1 'place in dict
  335.     For l = 1 To Len(letters$) ' advance place in list$ by one until the word > letter
  336.         While Asc(OnePointList$(dp), 1) < Asc(letters$, l)
  337.             dp = dp + 1
  338.             If dp > ub Then GoTo fini
  339.             If Timer(.01) - startTime < 0 Then checkTime = Timer(.01) + 24 * 60 * 60 Else checkTime = Timer(.01)
  340.             If checkTime - startTime > timeLimit Then GoTo fini
  341.         Wend
  342.         'now start testing words
  343.         While Asc(OnePointList$(dp), 1) = Asc(letters$, l)
  344.             If wordBuildOK&(OnePointList$(dp)) Then
  345.                 If b$ = "" Then b$ = OnePointList$(dp) Else b$ = b$ + " " + OnePointList$(dp)
  346.             End If
  347.             dp = dp + 1
  348.             If dp > ub Then GoTo fini
  349.             If Timer(.01) - startTime < 0 Then checkTime = Timer(.01) + 24 * 60 * 60 Else checkTime = Timer(.01)
  350.             If checkTime - startTime > timeLimit Then GoTo fini
  351.         Wend
  352.     Next
  353.  
  354.     fini:
  355.     AIwords$ = b$
  356.  
  357. Function qw$ (w$) 'insert the u into a q letter word
  358.     Dim As Long p
  359.     p = InStr(w$, "Q")
  360.     If p Then qw$ = Mid$(w$, 1, p) + "U" + Mid$(w$, p + 1) Else qw$ = w$
  361.  
  362. Function removeRepeats$ (s$) ' s$ is space delimited word list
  363.     ReDim t$(1 To 1), b$
  364.     Dim As Long ub, i, j, ok
  365.     Split s$, " ", t$()
  366.     ub = UBound(t$)
  367.     For i = 1 To ub
  368.         ok = -1
  369.         For j = 1 To i - 1
  370.             If t$(i) = t$(j) Then ok = 0: Exit For
  371.         Next
  372.         If ok Then
  373.             If b$ = "" Then b$ = t$(i) Else b$ = b$ + " " + t$(i)
  374.         End If
  375.     Next
  376.     removeRepeats$ = b$
  377.  
  378. Function score& (a() As String)
  379.     Dim As Long i, s
  380.     For i = 1 To UBound(a)
  381.         Select Case Len(a(i))
  382.             Case 3, 4: s = s + 1
  383.             Case 5: s = s + 2
  384.             Case 6: s = s + 3
  385.             Case 7: s = s + 5
  386.             Case Is > 7: s = s + 11
  387.         End Select
  388.     Next
  389.     score& = s
  390.  

 
Boggle 1 2022-01-15 s1.PNG


 
Boggle 1 2022-01-15 s2.PNG


Dang, I missed god.


Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Boggle play against AI - WIP
« Reply #10 on: January 15, 2022, 01:08:04 pm »
Why doesn't the AI find PEAT and DIE and TAP?

It's overlooking a lot of easy words.
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Boggle play against AI - WIP
« Reply #11 on: January 15, 2022, 01:56:51 pm »
Why doesn't the AI find PEAT and DIE and TAP?

It's overlooking a lot of easy words.

They were on my list ("a lot of easy words"), at time of reckoning matching words are eliminated and then words remaining are scored.

You see those words on the screen shot before the last (when I had words in my list). The AI of course found every 3-4 letter word I did (wiping out my list) plus a couple more, it gets to keep the couple more :)

I will add a label about typing in the words while the timer is going, but I have bigger fish to fry. I want that 17th die to eliminate special handling of Qwords that really threw a monkey wrench in coding this game and AI's list will have access to ALL 3 and 4 letter words. There many q words that don't use u after the q, why should we shun them?

We play games but we also expand vocabulary, spelling and data processing skills ie keep our minds active and growing.
« Last Edit: January 15, 2022, 02:03:44 pm by bplus »

Offline jack

  • Seasoned Forum Regular
  • Posts: 408
    • View Profile
Re: Boggle play against AI - WIP
« Reply #12 on: January 15, 2022, 02:46:59 pm »
Hi bplus
about the program simply vanishing while reading the dictionary, try Dim WordList$(1 To 300000) even though the number of words is only 279499
but where can I find "Boggle 1 Point Words.txt" ?

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Boggle play against AI - WIP
« Reply #13 on: January 15, 2022, 03:22:33 pm »
Hi bplus
about the program simply vanishing while reading the dictionary, try Dim WordList$(1 To 300000) even though the number of words is only 279499
but where can I find "Boggle 1 Point Words.txt" ?

Apologies to all, I forgot you guys need the files to play, dang sorry.

Use the link for the giant Collins Scrabble Word (2019).txt files, I would get the dictionary with the word list to learn what some of these crazy 3-4 letter words are!? You can find the link right under the Boggle Title line at the start of the bas source of Boggle 1.

And here is the zip for the Bas Make codes ran to create smaller files from the Collins word list.

+1) The 3 to 10 Letter Words.txt is my fix for being unable to load the entire Collins Word List as mention in reply above. Might be able to get more Letter words thn 10 but I roughing out a running game not optimizing.
This file was used to load most of the words into an array in the app, as all the words wont fit.

+2) The Boggle 1 Point Words.txt are what the AI uses to attempt legal constructions from the given active game board. One point words only have 3 or 4 Letters.

So in the zip you have the txt file lists and the code that built them from the Collins files and the Boggle 1 source, but not the Collins files.
 

Thanks @jack for bringing this to my attention.


You know since the frick'n AI is so good at finding words, I think I will restrict it to 5 letters or more and give all the one pointers the player finds to the player. That will occupy the AI for finding longer words (and getting bigger points unless player finds them too.)

That may make a game the player could win! ;-)) and it would be more interesting checking out what the AI finds.
« Last Edit: January 15, 2022, 03:37:41 pm by bplus »

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Boggle play against AI - WIP
« Reply #14 on: January 16, 2022, 05:28:39 am »
Give the AI an education level that the user can select from 1 to 10.

1 has a 10% chance to "know" a word if it finds a match; 10 has a 100% chance.

For example, the AI finds "cat", but with the handicap, it only has a 10 * level percent chance of keeping the word in its list.

Seems simple enough to implement and allows for some customization for game difficulty.
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!