I recently saw a question on SO about solving the scramble/boggle game, where the letters are in a 4x4 grid and you have to find as many words as possible. I looked at some of the solutions, tried it myself, and would now like to move onto solving a scrabble game.
The boggle solving code is rather simple; store the board state in a matrix and iterate over every move from every position and checking if words exist with the current letter chain.
With scrabble, the idea is similar, but I'm still having trouble figuring it out. My currently thinking of:
- Storing the board in 2 dimensional array.
- Iterating over each position and skipping if the position is empty.
- Creating some sort of regex pattern for the letters on the rack and the letter at the position...
I'm still really iffy on what to do at step 3 because I know the tile at the position could be the beginning end, or some point in the middle of a word. And then there's the matter of making sure that if a word does fit that it also makes words with other tiles it touches..
I'm not asking for code samples, just the thought process from more experienced programmers.
To clarify, my goal is:
Given the current state of a board and a person's tiles, calculate the legal moves and the points for that move.
For anyone following this and waiting for an answer, I found this: http://www.chaddington.com/portfolio/project.html#scrabble
I might look through what he wrote, but I do want to try to figure it out myself first.