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


Messages In This Thread
Scrabble Dictionary - by SMcNeill - 11-22-2022, 05:01 PM
RE: Scrabble Dictionary - by PhilOfPerth - 11-23-2022, 02:31 AM
RE: Scrabble Dictionary - by SMcNeill - 11-23-2022, 02:53 AM
RE: Scrabble Dictionary - by PhilOfPerth - 11-23-2022, 02:58 AM
RE: Scrabble Dictionary - by bplus - 11-23-2022, 04:08 PM
RE: Scrabble Dictionary - by PhilOfPerth - 11-24-2022, 12:00 AM
RE: Scrabble Dictionary - by bplus - 11-24-2022, 12:23 AM
RE: Scrabble Dictionary - by SMcNeill - 11-24-2022, 01:58 AM
RE: Scrabble Dictionary - by bplus - 11-24-2022, 02:58 AM
RE: Scrabble Dictionary - by PhilOfPerth - 11-24-2022, 04:12 AM
RE: Scrabble Dictionary - by bplus - 11-24-2022, 04:29 AM
RE: Scrabble Dictionary - by PhilOfPerth - 11-24-2022, 08:01 AM
RE: Scrabble Dictionary - by SMcNeill - 11-24-2022, 04:34 AM
RE: Scrabble Dictionary - by bplus - 11-24-2022, 04:40 AM
RE: Scrabble Dictionary - by bplus - 11-24-2022, 12:50 PM



Users browsing this thread: 3 Guest(s)