Spent this weekend writing a PopWords solver in python. PopWords is a game on the AppStore with a daily challenge.
Rules:
8x8 grid of letters
Make words by chaining letters together (start at a letter and continue to any unused letters left/right/up/down/diagonal).
Words of length 3 or higher. Points per word length are as follows: 1, 2, 4, 7, 11, 17, 25, 35?, 50, 70?, 100?, 140, 200, 270, unknown higher....
When a word is made, letters fall down to fill empty spots, then empty columns are removed.
Removing all letters doubles the user's score.
Current situation:
I've been able to write a solver (see:
https://github.com/Lathentar/PopWordSolver), but it is far too slow for the 8x8 grid. So far it's taken well over 5 hours for the daily puzzle.
Approach:
Take the word bank and make a n-tree where n is the number of letters available at each step of the tree. When finding words, find the letter, see if the letter is available in the given spot of the tree. Then use the tree at that letter for the next letter. Search for a '*' in the tree to see if you've made a completed word as well.
I use a depth first traversal after discovering all words that can be found on the current board sorted by length. For every board I encounter, I generate a string and put it into a dictionary with the result of that depth first search. Before traversing the board, I check to see if I've already seen that board and already know what the best solution is (memoization). I also check to see if it's possible to beat the best current score given the number of letters remaining on the board.
What other approaches do you guys think I could take. A greedy algorithm gives a good solution, but certainly not the best solution. Feel free to look at my code, though it's awful. First real program in python.