0

Hi all.

I am building a program to emulate a game 'Boggle', and have hit a dead end.
I have tried to search for hints online as to what I need to do from here, but everything I find is either just a block of code sparingly commented or doesn't help.

So far I have got it to find words in straight lines from any edge letter; i.e.:

Letters:
R V G E
N T W U
S D H I
V L H O

Found Words:
RVGE
RNSV
RTHO
NTWU
SDHI
VLHO
VSNR
VDWE
VTDL
LDTV
GWHH
HHWG
EUIO
EGVR
EWDV
UWTN
IHDS
OHLV
OIUE
OHTR

However, I need it to search from each letter in all directions as well.
Any hints on what I need to alter?
I stand by my signature, so no walls of code please :)

The search code:

static bool FindWord(string word = null) {
    int width = 4; // Grid width
    int height = 4; // Grid Height
    int cX = 0; // x coordinate
    int cY = 0; // y coordinate
    int d = 0; // Search direction

    for (cX = 0; cX < width; cX++) {
        for (cY = 0; cY < height; cY++) {
            for (d = 0; d < 8; d++) {
                Search(cX, cY, d, "", width, height);
            }
        }
    }

    return true;
}

static string Search(int cX, int cY, int d, string word, int width, int height) {
    string oneLetter;
    // Stay within bounds 
    if (cY >= width || cY < 0 || cX >= height || cX < 0) {
        return null;
    }

    oneLetter = dieFaces[cY, cX];
    string newWord = word + oneLetter;
            switch (d) {
                case 0:
                    if(newWord.Length > 3) Console.WriteLine(newWord);
                    Search(cX + 1, cY, d, newWord, width, height);
                    break;
                case 1:
                    if (newWord.Length > 3) Console.WriteLine(newWord);
                    Search(cX, cY + 1, d, newWord, width, height);
                    break;
                case 2:
                    if (newWord.Length > 3) Console.WriteLine(newWord);
                    Search(cX - 1, cY, d, newWord, width, height);
                    break;
                case 3:
                    if (newWord.Length > 3) Console.WriteLine(newWord);
                    Search(cX, cY - 1, d, newWord, width, height);
                    break;
                case 4:
                    if (newWord.Length > 3) Console.WriteLine(newWord);
                    Search(cX + 1, cY + 1, d, newWord, width, height);
                    break;
                case 5:
                    if (newWord.Length > 3) Console.WriteLine(newWord);
                    Search(cX - 1, cY + 1, d, newWord, width, height);
                    break;
                case 6:
                    if (newWord.Length > 3) Console.WriteLine(newWord);
                    Search(cX - 1, cY - 1, d, newWord, width, height);
                    break;
                case 7:
                    if (newWord.Length > 3) Console.WriteLine(newWord);
                    Search(cX + 1, cY -1, d, newWord, width, height);
                    break;
            }
    return newWord;
}

Hopefully someone will have a clue :)

2
Contributors
1
Reply
2
Views
6 Years
Discussion Span
Last Post by Momerath
0

Since you can move in any direction (as long as you haven't visited that spot before) you'll need to generate all possible moves from each spot, and continue doing so until you have generated all possible words (boggle says 3 letters or more). So I'd generate a list of all possible starting moves, then loop through the list generating a list of all the next moves. After that, and set the 'possible moves list' to the 'next moves list' and run the routine again. Keep doing this until there is nothing in the 'possible moves list'. Since you don't want code, you don't get any :) You'll also have to track (for each move list) which spots have been visited.

Edited by Momerath: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.