Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Scrabble Dictionary
#1
A useful little tool for anyone who likes to play Scrabble. 

Code: (Select All)
file$ = "Collins Scrabble Words (2019) with definitions.txt"
'279498 words

Type Dict_Type
    word As String
    definition As String
End Type

ReDim As String Word(1000000), Definition(1000000)



Open file$ For Binary As #1
Do Until EOF(1)
    Line Input #1, text$
    count = count + 1
    p = InStr(text$, Chr$(9))
    Word(count) = _Trim$(Left$(text$, p - 1))
    Definition(count) = _Trim$(Mid$(text$, p + 1))
Loop
ReDim _Preserve Word(count) As String
ReDim _Preserve Definition(count) As String


Do
    Color 4
    Input "Give me a word to look up for you =>"; word$
    If word$ = "" Then System
    i = BinaryStringSearch(UCase$(word$), Word())
    Color 15
    Print
    If i > -1 Then
        Print word$; " found!  It's definition is: "; Definition(i)
    Else
        Print word$; " doesn't exist!  You big dummy!  Cheater!  Who's gonna play Scrabble with you?!!"
    End If
    Print
Loop

Function BinaryStringSearch (search$, Array() As String)
    'These routines work with actual indexes, so we can search from Array(-10 to 10), if we want to.
    'When the search string is found, it'll return a value = to the index proper.
    'When it's not found, it'll return a value LESS THAN the LBOUND limit of the array,
    'And the point where the string WOULD'VE appeared, if it existed, is after the shared variable LastIndex

    BinaryStringSearch = BinaryStringSearchSome(search$, Array(), LBound(Array), UBound(Array))
End Function

Function BinaryStringSearchSome (search$, Array() As String, StartIndex As Long, EndIndex As Long)
    'These routines work with actual indexes, so we can search from Array(-10 to 10), if we want to.
    'When the search string is found, it'll return a value = to the index proper.
    'When it's not found, it'll return a value LESS THAN the LBOUND limit of the array,
    'And the point where the string WOULD'VE appeared, if it existed, is after the shared variable LastIndex

    min = StartIndex
    max = EndIndex

    Do
        gap = (max + min) \ 2
        compare = _StrCmp(search$, Array(gap))
        If compare > 0 Then
            min = gap + 1
        ElseIf compare < 0 Then
            max = gap - 1
        Else
            BinaryStringSearchSome = gap
            Exit Function
        End If
        If max - min < 1 Then
            If search$ = Array(min) Then
                BinaryStringSearchSome = min
            Else
                BinaryStringSearchSome = LBound(Array) - 1
                If search$ < Array(min) Then
                    LastIndex = min - 1
                Else
                    LastIndex = min
                End If
            End If
            found = -1
        End If
    Loop Until found
End Function



Download and extract the word list/dictionary from below to use with this program.  Smile


Attached Files
.7z   Collins Scrabble Words (2019) with definitions.7z (Size: 2.82 MB / Downloads: 49)
Reply
#2
(11-22-2022, 05:01 PM)SMcNeill Wrote: A useful little tool for anyone who likes to play Scrabble. 

Code: (Select All)
file$ = "Collins Scrabble Words (2019) with definitions.txt"
'279498 words

Type Dict_Type
    word As String
    definition As String
End Type

ReDim As String Word(1000000), Definition(1000000)



Open file$ For Binary As #1
Do Until EOF(1)
    Line Input #1, text$
    count = count + 1
    p = InStr(text$, Chr$(9))
    Word(count) = _Trim$(Left$(text$, p - 1))
    Definition(count) = _Trim$(Mid$(text$, p + 1))
Loop
ReDim _Preserve Word(count) As String
ReDim _Preserve Definition(count) As String


Do
    Color 4
    Input "Give me a word to look up for you =>"; word$
    If word$ = "" Then System
    i = BinaryStringSearch(UCase$(word$), Word())
    Color 15
    Print
    If i > -1 Then
        Print word$; " found!  It's definition is: "; Definition(i)
    Else
        Print word$; " doesn't exist!  You big dummy!  Cheater!  Who's gonna play Scrabble with you?!!"
    End If
    Print
Loop

Function BinaryStringSearch (search$, Array() As String)
    'These routines work with actual indexes, so we can search from Array(-10 to 10), if we want to.
    'When the search string is found, it'll return a value = to the index proper.
    'When it's not found, it'll return a value LESS THAN the LBOUND limit of the array,
    'And the point where the string WOULD'VE appeared, if it existed, is after the shared variable LastIndex

    BinaryStringSearch = BinaryStringSearchSome(search$, Array(), LBound(Array), UBound(Array))
End Function

Function BinaryStringSearchSome (search$, Array() As String, StartIndex As Long, EndIndex As Long)
    'These routines work with actual indexes, so we can search from Array(-10 to 10), if we want to.
    'When the search string is found, it'll return a value = to the index proper.
    'When it's not found, it'll return a value LESS THAN the LBOUND limit of the array,
    'And the point where the string WOULD'VE appeared, if it existed, is after the shared variable LastIndex

    min = StartIndex
    max = EndIndex

    Do
        gap = (max + min) \ 2
        compare = _StrCmp(search$, Array(gap))
        If compare > 0 Then
            min = gap + 1
        ElseIf compare < 0 Then
            max = gap - 1
        Else
            BinaryStringSearchSome = gap
            Exit Function
        End If
        If max - min < 1 Then
            If search$ = Array(min) Then
                BinaryStringSearchSome = min
            Else
                BinaryStringSearchSome = LBound(Array) - 1
                If search$ < Array(min) Then
                    LastIndex = min - 1
                Else
                    LastIndex = min
                End If
            End If
            found = -1
        End If
    Loop Until found
End Function



Download and extract the word list/dictionary from below to use with this program.  Smile
That's the file I've used in the wordslists folder for my word-games (alchemy et al) but I weeded out the definitions and obscene words, and separated them into 26 separate files for easier searching.  I didn't think most people would be too concerned about the meanings when just playing a casual game Big Grin
Of all the places on Earth, and all the planets in the Universe, I'd rather live here (Perth, W.A.) Big Grin
Please visit my Website at: http://oldendayskids.blogspot.com/
Reply
#3
(11-23-2022, 02:31 AM)PhilOfPerth Wrote: That's the file I've used in the wordslists folder for my word-games (alchemy et al) but I weeded out the definitions and obscene words, and separated them into 26 separate files for easier searching.  I didn't think most people would be too concerned about the meanings when just playing a casual game Big Grin


Apparently you've never played with real people before, then!  When it comes to any sort of game, people will argue over the tiniest little thing.  

"That's not a real word!"

"It's right here in the word list!"

"Well, what the hell is it then?  Can you use it in a sentence?  Give a definition for it?"

"Sure!  Just want me boondoggle your nose ofn your face!"

Of course, I love some of the definitions they give for words.  Try "cat" or "dog" sometime..   It seems this dictionary always gives you verb usage over noun use, in most instances.  LOL!
Reply
#4
Ah, I guess we Aussies aren't as argumentative as youse blokes!  Big Grin
Of all the places on Earth, and all the planets in the Universe, I'd rather live here (Perth, W.A.) Big Grin
Please visit my Website at: http://oldendayskids.blogspot.com/
Reply
#5
Definitely going to play with this if not gradebooks, I have a version of Alchemy down to less than 100 lines by consolidating Phil's word lists and going RA. I think I did do something with Collins dictionary before, Boggle?, anyway you definitely want access to definitions if not to argue with friends and family then to learn! Smile
b = b + ...
Reply
#6
Yeah, I guess so... maybe I'll add Definitions as an option. BTW what's "RA"?
Of all the places on Earth, and all the planets in the Universe, I'd rather live here (Perth, W.A.) Big Grin
Please visit my Website at: http://oldendayskids.blogspot.com/
Reply
#7
(11-24-2022, 12:00 AM)PhilOfPerth Wrote: Yeah, I guess so... maybe I'll add Definitions as an option. BTW what's "RA"?

RA is Random access, my experiment last night showed me it took almost as long to load the list of words into an array than it did to create (consolidate from the letter files and a complementary AnaCode file along with the word list). I got tired of waiting for arrays to load so I made the Word list Random access and searched the file instead of an array loaded from the file. What a time saver! Specially when retesting code every 2 minutes or so and having to wait for dang arrays to get loaded.
b = b + ...
Reply
#8
Two minutes to load into an array?  That doesn't sound right.  How big of a list are you loading, and how are you parsing it to have it take that long?
Reply
#9
No it was taking under 2 minutes to load 2 arrays for 279422 words maybe 30-40 secs, just that I was developing code and had to retest code every 2 minutes or so to work out blunders a step at a time.

It was most aggravating debugging the binary search I was rewriting instead of digging around for a copy.
I forgot to exit the dang function when the word was found! Yeah funny now Smile 

At least that part worked when I switched over to RA nothing else was... you have to dim fixed strings you can't just use a string the right length for RA (a little rusty).
b = b + ...
Reply
#10
I don't really see the point of Random Access for the words; probably I'm missing something again.   Confused
Maybe a quicksort routine would help speed things up though.
Anyway, I'm half-way through creating matching Meanings files, so I'll stay with that for now.
Of all the places on Earth, and all the planets in the Universe, I'd rather live here (Perth, W.A.) Big Grin
Please visit my Website at: http://oldendayskids.blogspot.com/
Reply




Users browsing this thread: 3 Guest(s)