Code: Select all
;idle scrabble word finder words up to 8 letters
;returns a list of words from given input set from largest words to smallest words
;thanks Marco for your dictonary work :-)
EnableExplicit
Global NewMap Dict.i(90000)
Structure PemDic
Map one.s()
Map two.s()
Map three.s()
Map four.s()
Map five.s()
Map six.s()
Map seven.s()
Map eight.s()
EndStructure
Procedure LoadDicFile(Dicfile.s)
Protected fn,fm,pos,word.s
fn = ReadFile(#PB_Any,Dicfile)
If fn
fm = ReadStringFormat(fn)
While Not Eof(fn)
word = ReadString(fn,fm,-1)
pos = FindString(word,"/")
If pos > 0
word = Left(word,pos-1)
EndIf
word = LCase(word)
Dict.s(word)=Len(word)
Wend
CloseFile(fn)
EndIf
EndProcedure
Prototype.s pCbPermute(out.s,len,*user)
Procedure Permute(*v,start,len,*cb.pCBPermute,*user)
Protected i.i,sout.s,tw.c,tmpc.c,sz.i
If start = len-1
If *v
sout.s
For i = 0 To len -1
tw.c = PeekC(*v+(i* SizeOf(Character)))
sout + Chr(tw)
Next
If *cb
*cb(sout,len,*user)
EndIf
EndIf
Else
sz = SizeOf(Character)
For i = start To len -1
tmpc.c = PeekC(*v+(i*sz))
PokeC(*v+(i*sz),PeekC(*v+(start*sz)));
PokeC(*v+(start*sz),tmpc)
permute(*v,start+1,len,*cb,*user);
PokeC(*v+(start*sz),PeekC(*v+(i*sz)))
PokeC(*v+(i*sz),tmpc);
Next
EndIf
EndProcedure
Procedure cbPermute(out.s,len,*user)
Protected inp.s,*pem.pemdic
*pem = *user
If len >= 2
inp = Right(out,2)
If FindMapElement(dict(),inp)
*pem\two(inp) = inp
EndIf
EndIf
If len >= 3
inp = Right(out,3)
If FindMapElement(dict(),inp)
*pem\three(inp)=inp
EndIf
EndIf
If len >= 4
inp = Right(out,4)
If FindMapElement(dict(),inp)
*pem\four(inp) = inp
EndIf
EndIf
If len >= 5
inp = Right(out,5)
If FindMapElement(dict(),inp)
*pem\five(inp)=inp
EndIf
EndIf
If len >= 6
inp = Right(out,6)
If FindMapElement(dict(),inp)
*pem\six(inp)=inp
EndIf
EndIf
If len >= 7
inp = Right(out,7)
If FindMapElement(dict(),inp)
*pem\seven(inp)= inp
EndIf
EndIf
If len >= 8
inp = Right(out,8)
If FindMapElement(dict(),inp)
*pem\eight(inp)= inp
EndIf
EndIf
EndProcedure
Procedure GenListWords(*pem.PemDic,List words.s())
ForEach *pem\eight()
AddElement(words())
words() = *pem\eight()
Next
ForEach *pem\seven()
AddElement(words())
words() = *pem\seven()
Next
ForEach *pem\six()
AddElement(words())
words() = *pem\six()
Next
ForEach *pem\five()
AddElement(words())
words() = *pem\five()
Next
ForEach *pem\four()
AddElement(words())
words() = *pem\four()
Next
ForEach *pem\three()
AddElement(words())
words() = *pem\three()
Next
ForEach *pem\two()
AddElement(words())
words() = *pem\two()
Next
EndProcedure
Procedure GetWords(input.s,List words.s())
Protected *pem = AllocateStructure(pemdic)
If Len(input) < 9
Permute(@input,0,Len(input),@cbPermute(),*pem)
GenListWords(*pem,words())
EndIf
FreeStructure(*pem)
EndProcedure
Global path.s = GetTemporaryDirectory()+"en-GB.dic"
Global NewList words.s()
InitNetwork()
If ReceiveHTTPFile("https://raw.githubusercontent.com/marcoagpinto/aoo-mozilla-en-dict/master/en_GB%20(Marco%20Pinto)/en-GB.dic",path)
loadDicfile(path.s)
Else
MessageRequester("BOFH","failed to download")
End
EndIf
GetWords("permutes",words())
ForEach words()
Debug words()
Next
ClearList(words())