Scrabble Cheater

I just thought I’d post my code here for a scrabble cheater. You enter the letters and it finds all the words you can make. In case you’re wondering, it works by accessing the system’s dictionaries and finding all the words that include some of those letters. I need some help with some things though:

  • Making them ordered by length or points at the end (for points maybe count a’s and multiply by 2 or whatever its worth)

  • Making it so if your letters are “guner”, “gunner” doesnt show up, “gunner” includes all of the letters in “guner” (I fixed it so that example doesnt work by adding a length limit, it wont show up cause “gunner” is more letters than you have, but if they enter “gunerc” then “gunner” will still come up)

  • Compression maybe

  • Allowing all the words to show up, not just as many fit on the dialog (maybe splitting it into multiple pages and viewing the next page when you click “Ok”)

  • Any ideas you guys have (I’m gonna add something so you can add requirements for beginning and end of word)

Thanks so much you guys!

NOTE: All commented out areas right now were for checking a site to see if they’re valid Scrabble words (cause some people have lol in there dictionary and stuff) but I took that out cause it took to long to load the page 100 times

Code:

set theThings to (display dialog "Enter your letters here:" with title "Scrabble Helper" default answer "abcdefg" buttons {"Cancel", "Find Words"} default button 2)
set theletters to text returned of theThings
set filterBoolean to false
--if button returned of theThings is "With Filter" then set filterBoolean to true

set wordsString to do shell script "cd /usr/share/dict; grep -x '[" & theletters & "]*' web2"
set TID to AppleScript's text item delimiters
set AppleScript's text item delimiters to {"
"}
set wordsList to words in wordsString
repeat with i from 1 to (length of wordsList)
	if (length of item i of wordsList) > (length of theletters) then
		set item i of wordsList to "invalid word"
	else
		--if filterBoolean is true then if not (offset of "not a valid" in (do shell script "curl [url=http://www.wordnik.com/words/]http://www.wordnik.com/words/"[/url] & item i of wordsList)) is 0 then set item i of wordsList to "invalid word"
	end if
end repeat
set wordsString to wordsList as string
set wordsString to removeFrom("
invalid word", wordsString, "")
display dialog wordsString with title "Scrabble Helper" buttons {"Ok"} default button 1

on maximum(numberOne, numberTwo)
	if numberOne > numberTwo then return numberOne
	numberTwo
end maximum

on minimum(numberOne, numberTwo)
	if numberOne < numberTwo then return numberOne
	numberTwo
end minimum

on removeFrom(waht, fromWaht, replaceWith)
	set TID to AppleScript's text item delimiters
	set AppleScript's text item delimiters to {waht}
	set theWords to every text item in fromWaht
	set AppleScript's text item delimiters to (replaceWith)
	set theWords to theWords as string
	set AppleScript's text item delimiters to TID
	return theWords
end removeFrom