Results 1 to 12 of 12
  1. #1
    dragonwolf is offline Member
    Join Date
    Nov 2009
    Posts
    6
    Rep Power
    0

    Default Boggle game - verify words entered by user

    My boggle program works to the point where it will generate the game board and ask the user to input words they have found.

    What I need to do now is write a recursive section of code that:
    Step 1: Searches the letters on the board and verify that the word is valid.
    Step 2: Validate it against a text file dictionary.

    I appreciate the help.

    Java Code:
    package testrun;
    
    import java.util.*;
    
    public class Main
    {
        //declarations
        static String[] alpha = {"A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Qu","R","S","T","U","V","W","X","Y","Z"};
        static Random rand = new Random();
    
        //array lists
        static ArrayList<String> row1 = new ArrayList<String>();
        static ArrayList<String> row2 = new ArrayList<String>();
        static ArrayList<String> row3 = new ArrayList<String>();
        static ArrayList<String> row4 = new ArrayList<String>();
        static ArrayList<String> row5 = new ArrayList<String>();
    
        public static void main(String[] args)
        {
            code();
    
            for(int i = 0; i < row1.size(); i++)
            {
                System.out.print(row1.get(i) + " ");
            }
            System.out.println();
    
            for(int i = 0; i < row2.size(); i++)
            {
                System.out.print(row2.get(i) + " ");
            }
            System.out.println();
    
            for(int i = 0; i < row3.size(); i++)
            {
                System.out.print(row3.get(i) + " ");
            }
            System.out.println();
    
            for(int i = 0; i < row4.size(); i++)
            {
                System.out.print(row4.get(i) + " ");
            }
            System.out.println();
    
            for(int i = 0; i < row5.size(); i++)
            {
                System.out.print(row5.get(i) + " ");
            }
            System.out.println();
    
            System.out.println("To end game enter '//'");
            System.out.println("Enter words found: ");
            endGame();
        } // end main
    
        //iterator to remove brackets and commas
        public static String join(Iterable<?> elements, String delimiter)
        {
            StringBuilder sb = new StringBuilder();
            for(Object e: elements)
            {
                sb.append(delimiter);
                sb.append(e);
            }
            return sb.toString();
        }//end String join
    
        //generate arrayList items
        public static void code()
        {
            row1.add(alpha[produceNumber()]);
            row1.add(alpha[produceNumber()]);
            row1.add(alpha[produceNumber()]);
            row1.add(alpha[produceNumber()]);
            row1.add(alpha[produceNumber()]);
    
            row2.add(alpha[produceNumber()]);
            row2.add(alpha[produceNumber()]);
            row2.add(alpha[produceNumber()]);
            row2.add(alpha[produceNumber()]);
            row2.add(alpha[produceNumber()]);
    
            row3.add(alpha[produceNumber()]);
            row3.add(alpha[produceNumber()]);
            row3.add(alpha[produceNumber()]);
            row3.add(alpha[produceNumber()]);
            row3.add(alpha[produceNumber()]);
    
            row4.add(alpha[produceNumber()]);
            row4.add(alpha[produceNumber()]);
            row4.add(alpha[produceNumber()]);
            row4.add(alpha[produceNumber()]);
            row4.add(alpha[produceNumber()]);
    
            row5.add(alpha[produceNumber()]);
            row5.add(alpha[produceNumber()]);
            row5.add(alpha[produceNumber()]);
            row5.add(alpha[produceNumber()]);
            row5.add(alpha[produceNumber()]);
        }//end code
    
        //get random letter from string array
        public static int produceNumber()
        {
            return (rand.nextInt(alpha.length));
        }//end produceNumber
    
        //userInput for words found
        //endGame sentinel
        public static void endGame()
        {
            Scanner userInput = new Scanner(System.in);
            String input;
            input = userInput.nextLine().toUpperCase();
            if(input.contains("//"))
            {
                System.exit(0);
            }
            else
            {
                endGame();
            }
        }//end endGame
    }

  2. #2
    dragonwolf is offline Member
    Join Date
    Nov 2009
    Posts
    6
    Rep Power
    0

    Default

    Is what I'm wanting to do with my code impossible?

  3. #3
    dinosoep is offline Senior Member
    Join Date
    Nov 2009
    Posts
    150
    Rep Power
    6

    Default

    nope, just dont lucky.
    try to write someparts yourself and show us the errors.
    we can solve problems but won't program the game...
    EDIT: comment your code :)
    Last edited by dinosoep; 11-29-2009 at 11:37 PM. Reason: i don't know

  4. #4
    sky
    sky is offline Member
    Join Date
    Nov 2009
    Posts
    96
    Rep Power
    0

    Default

    Just reading your implementation of the board I don't feel that a recursive solution seems natural.

  5. #5
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    Quote Originally Posted by sky View Post
    Just reading your implementation of the board I don't feel that a recursive solution seems natural.
    You certainly should not use recursion here as you're doing:
    Java Code:
        public static void endGame()
        {
            Scanner userInput = new Scanner(System.in);
            String input;
            input = userInput.nextLine().toUpperCase();
            if(input.contains("//"))
            {
                System.exit(0);
            }
            else
            {
                endGame();
            }
        }
    but using recursion to check for all possible words on the board does make sense.

  6. #6
    dragonwolf is offline Member
    Join Date
    Nov 2009
    Posts
    6
    Rep Power
    0

    Default

    Ok. So instead of telling me what isn't recommended, why not try helping me out with something that is recommended? Or a different implementation that allows a recursion solution? Just curious.

    As far as using a recursion to check the board for possible words goes, that is what I want. After running that recursion code I want to implement a different code to see if that segment of letters is in my text file. This shouldn't be that hard.
    Last edited by dragonwolf; 11-30-2009 at 02:08 AM.

  7. #7
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    Well you want to repeatedly ask the user for a new word til they're done, and so you tell us, what works well in Java when you want to repeat things?
    Last edited by Fubarable; 11-30-2009 at 02:36 AM.

  8. #8
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    Quote Originally Posted by dragonwolf View Post
    ...This shouldn't be that hard.
    So why not give it a whirl and try to implement this yourself first. If it doesn't work, then come on back with your code.

    Good luck!

  9. #9
    dragonwolf is offline Member
    Join Date
    Nov 2009
    Posts
    6
    Rep Power
    0

    Default

    I have tried.... been trying for two weeks.... what I meant was that what I'm asking shouldn't be that hard to understand. I am needing help writing some code that will recursively scan the game board making sure that the words entered are valid.

  10. #10
    dragonwolf is offline Member
    Join Date
    Nov 2009
    Posts
    6
    Rep Power
    0

    Default

    Well, I'm done soliciting help from this site. Nobody seems to care to try. All people here seem to care about is belittling others who have little experience with programming. I don't really care to put up with it. So nobody bother trying to help with the question that I originally posted....not that anybody would try as far as I know.

  11. #11
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    Quote Originally Posted by dragonwolf View Post
    Well, I'm done soliciting help from this site. Nobody seems to care to try. All people here seem to care about is belittling others who have little experience with programming. I don't really care to put up with it. So nobody bother trying to help with the question that I originally posted....not that anybody would try as far as I know.
    Nobody's belittling anybody, so please calm down. I've asked you in one post that if you want to repeat a process, to loop, and not use recursion, what would you use -- and you've not answered. You stated that you tried recursion to solve the issue of searching your array but failed, and we've asked you to post your code attempt, but you've not responded. It seems to me that you're only getting out of this thread what you're putting in to it.

    Best of luck.

  12. #12
    dragonwolf is offline Member
    Join Date
    Nov 2009
    Posts
    6
    Rep Power
    0

    Default

    What I'm looking for is pseudo-code to help get me started. That is what I'm looking for. Nobody seems to understand that. I'm done.

Similar Threads

  1. Verify Password
    By hypes057 in forum New To Java
    Replies: 11
    Last Post: 08-29-2011, 02:27 PM
  2. Java RE SE does not install/verify
    By jlbm in forum New To Java
    Replies: 1
    Last Post: 03-20-2009, 09:45 PM
  3. Replies: 5
    Last Post: 11-22-2008, 02:34 PM
  4. Verify if a file as been, for sure, printed
    By pjmorce in forum Advanced Java
    Replies: 0
    Last Post: 11-20-2008, 11:45 AM
  5. The words *game* in java programming :confused:
    By ibmzz in forum Advanced Java
    Replies: 1
    Last Post: 01-23-2008, 10:23 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •