Jump to content
BrainDen.com - Brain Teasers
  • 0


unreality
 Share

Question

you'll need both files in the same directory:

fiveletterwords.txt

and it didn't let me upload ROLLO.java so here it is:



// ROLLO player

// by unreality

// Tuesday, July 6th, 2010 and Wednesday too haha

import java.util.Scanner;

import java.io.File;

import java.util.ArrayList;

import java.io.FileWriter;

public class ROLLO

{

   public static void main(String[] args)

   {

       Scanner inp = new Scanner(System.in);

       System.out.print("\f\nROLLO!");

       char[] word;

       boolean run = true;

       while (run)

       {

           word = generateWord();

           String rec = getRecord();

           System.out.print("\n\nThe computer has thought of a word. Enter your guesses at the prompt and hit enter!\nThe goal is to minimize your guesses.\nCurrent Record: "+rec+" guesses.\nType a tilde to give up. Type a 'q' to quit immediately.\nType a dash (-) to get a list of what you've guessed so far. Good luck!\n\n");

           int gcount = 0;

           String guess = "";

           ArrayList<Integer> ar_s = new ArrayList<Integer>();

           ArrayList<String> ar_g = new ArrayList<String>();

           while (!guess.equals(" ") && !guess.equals("~"))

           {

               System.out.print(">:  ");

               guess = inp.next().toLowerCase();

               if (guess.length() == 5)

               {

                   int c = 0;

                   for (int i=0; i<5; i++) if (guess.charAt(i) == word[i]) c++;

                   System.out.print("    >>> "+c+"\n\n");

                   ar_g.add(guess);

                   ar_s.add(c);

                   gcount++;

                   if (c == 5) guess = " ";

                }

                else if (guess.equals("q")) System.exit(0);

                else if (guess.equals("-"))

                {

                    System.out.print("\nGUESS TABLE:\n\n");

                    for (int x=0; x<ar_s.size(); x++)

                    {

                        System.out.println(ar_g.get(x)+" - "+ar_s.get(x));

                    }

                    System.out.println();

                }

                else if (guess.equals("#"))

                {

                    System.out.print("\n\n\t");

                    for (int i=0; i<5; i++) System.out.print(word[i]);

                    System.out.print("\n\n");

                }

            }

            if (guess.equals(" ")) {

                String extra = "";

                if (isNumeric(rec))

                {

                    int recc = Integer.parseInt(rec);

                    if (gcount == recc) extra = " You tied the record!";

                    if (gcount < recc) { extra = " That's the new record!"; setRecord(gcount); }

                }

                System.out.print("\nCongrats! You got it in "+gcount+" guesses!"+extra+"\nPlay again? (Y|N)   ");

            }

            else

            {

                System.out.print("Give up? The word was ");

                for (int i=0; i<5; i++) System.out.print(word[i]);

                System.out.print("\nPlay again? (Y|N)   ");

            }

                run = (inp.next().toUpperCase().charAt(0) == 'Y');


        }

        System.out.print("\n\n\tThanks for playing... have a great day...");

    }

    public static boolean isNumeric(String s)

    {

       for (int i=0; i<s.length(); i++) if (!isNumeric(s.charAt(i))) return false;

       return true;

    }

    public static boolean isNumeric(char ch)

    {

        return (ch=='0' ||

                ch=='1' ||

                ch=='2' ||

                ch=='3' ||

                ch=='4' ||

                ch=='5' ||

                ch=='6' ||

                ch=='7' ||

                ch=='8' ||

                ch=='9');


    }

    public static char[] generateWord()

    {

        Scanner f;

        try {f = new Scanner(new File("fiveletterwords.txt"));}

        catch(java.io.FileNotFoundException ff) { return "xxxxx".toCharArray(); }

        int numthere = 0; String throwaway="xxxxx";

        while (f.hasNext()) { throwaway=f.next(); if (throwaway.length() == 5) {numthere++;} }

        int randomPos = (int)(Math.random() * numthere);

        Scanner g;

        try {g = new Scanner(new File("fiveletterwords.txt"));}

        catch(java.io.FileNotFoundException ff) { return "xxxxx".toCharArray(); }

        for (int ii=0; ii<randomPos; ii++) throwaway = g.next();

        return throwaway.toCharArray();

    }

    public static String getRecord()

    {

        Scanner f;

        try {f = new Scanner(new File("fiveletterwords.txt"));}

        catch(java.io.FileNotFoundException ff) { return "1 bazillion"; }

        int numthere = 0; String throwaway="xxxxx";

        while (f.hasNext()) { throwaway=f.next(); numthere++; }

        Scanner g;

        try {g = new Scanner(new File("fiveletterwords.txt"));}

        catch(java.io.FileNotFoundException ff) { return "1 bazillion"; }

        for (int ii=0; ii<numthere; ii++) throwaway = g.next();

        return throwaway;

    }

    public static void setRecord(int newr)

    {

        FileWriter fw;

        try {fw = new FileWriter("fiveletterwords.txt", true); fw.write(newr+" "); fw.close(); }

        catch(java.io.IOException ioe) { return; }


    }

}

Link to comment
Share on other sites

11 answers to this question

Recommended Posts

  • 0

my jgrasp hasnt been working lately, so i havent run your program yet, but it might be a problem that in the .txt file every twelfth word is combined with the next one.

Link to comment
Share on other sites

  • 0

for the past couple days I've been working on a more complex program that takes the input of words and their scores and returns all possible letters for each spot (narrowing down to as few as possible). It can do logic by elimination, logic by one-excess and I'm working on multidimensional elimination/excess logic for higher scoring words. So it's not quite done yet. But I'm not sure i'll be able to work on it for the next couple days so I just wanted to say something about it :thumbsup:

Link to comment
Share on other sites

  • 0

for the past couple days I've been working on a more complex program that takes the input of words and their scores and returns all possible letters for each spot (narrowing down to as few as possible). It can do logic by elimination, logic by one-excess and I'm working on multidimensional elimination/excess logic for higher scoring words. So it's not quite done yet. But I'm not sure i'll be able to work on it for the next couple days so I just wanted to say something about it :thumbsup:

I've actually been working (sporadically :( ) on a similar thing, :ph34r: but I haven't been able to formulate a good attack plan for it and it didn't really get off the ground. I have the underlying framework, but I didn't figure out the algorithm(s) to find the possible letters. :rolleyes:

It's mainly just having a lack of focus on my part of late... :mellow:

Link to comment
Share on other sites

  • 0

I've got a method to my madness, there's just some bugs to be ironed out and some more code to write.

edit: if you want to know it's with little "logic strings" that are actually char arrays and the computer can combine them and eliminate them based on its 5 alphabets that it's reducing via elimination and updating from conclusions from the logic strings.

Edited by unreality
Link to comment
Share on other sites

  • 0

thanks i didnt realize it was visual (i was learning with just basic but i was recommended this too) but this is cool, i mean i did some like nxt lego programming, and that was visual, but okay ill try it

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...