Monday, 11 March 2013
Yet Another Project Underway: Scrabble
Well I've got another project underway. I'm trying to make a 4 player Scrabble game. I already have a 1750 word dictionary built in, and an algorithm for finding words in it from a jumble of 7 letters. I had originally had aspirations of creating an AI to play against. But after loading the dictionary, there was only about 6200 bytes left. Also, the word finding algorithm takes about 20 minutes to search the entire list for words that can be created from 7 random tiles.
So I have settled for trying to make a simulation of the board, which will automatically score words placed on it, and keep track of tiles from a virtual "bag" of 100 tiles for up to four players. The dictionary will be used only as a "Help" feature if requested, and will search for word recommendations until a key is pressed to cancel the search. Perhaps this can function as a simple "AI." A single player could choose 2 player mode, and then use the help function to get some recommendations of words for the "second" player, which could then be placed by the first player to create a "pseudo opponent."
Or I might just make a routine that allows players to key in words directly for placement on the board for scoring. This way you could use the program in conjunction with a real game, but just as a "score keeper." Or perhaps both options.
I've basically got the algorithm in hand:
1. Input letters for your word (or manipulate 7 tiles on screen until in desired order, use left arrow ASCII char 95 as terminator of desired word)
2. Move cursor on board to beginning position for word
3. Prompt whether Right or Down direction desired
4. If down, then count down for each letter in the letter list compiling a list of @ locations and also counting colour bonuses and letter scores. Skip over any existing letters on the board, but count them for scoring purposes. At the end of this process, check for any letters in front of the first letter position or after the last position.
5. Process each @ location for possible horizontal words. If one is found, count letters (including @ location letter and any colour bonuses for that location)
6. Place actual tiles on the board (reverse video) and report score
7. Confirm placement
8. Undo if not confirmed
A similar process will be needed for right direction, which if I do it right, can perhaps simply use the same code as above, just with different vectors. In fact, I'm sure I'll have to have a single routine, because otherwise I'll probably run out of space! 20K of memory is not a lot to work with, but its an interesting challenge. We'll see if it can be done.