• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

Scrabble cheater

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello! I'm fairly new to java programming, and I thought, having projects was a good idea! We had a schoolproject recently, which gave me this idea. So a inputreader class is already in check! It reads strings from a txt.file.

I'm afraid this needs some patience to look through...

Now for my program...

Ever heard about Scrabble?

There is a similar program here: http://www.wordfeudcheat.com/

I want the user to input whatever characters he/she has.
Then I want my program to split up that word into characters: for eg. user enters: flog. Program reads it as: f, l, o, g.
Then shuffle each character, until it matches a word in a dictionary, in a txt.file.
For eg: golf.

Now: Firstly I got a program that did this... But it would try to match with an extremely inefficcient way: the first character randomized, then the latter char + second char randomized.
Would be much better if it could randomize all charaters (in previous example's case) at once an make a new string to check for...
Lets say user inputs 10 chars. The the program would be 90+% inefficient, if you understand what I mean. I will post sourcecode!

Then I tried a different approach: What it does, is that it takes the input in a variable, and converts it to an array of characters.
Then it adds the characters to a list, because I want to shuffle each character, then add them.... So arralist might look like: [f, l, o, g]

...then I use stringbuilder to append each by a for each loop: So if I enter by input: flog, I might get: folg. Yeah!
But then I try to iterate that operation, and then get something like: folg, folggolf, folggolfglof, and so on, which means it has to guess the word right, the first time, which is extremely improbable.


Here is the code:

Code for first program attempt:




Code for second program attempt:




 
Sheriff
Posts: 7111
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I've written a Scrabble cheater program, and my experience is that you need a permuter (to shuffle the letters) and a sublister (because not all the letters may be used). Collections.shuffle() looks like it might work for the permuter if you use a good randomizer but you still need a sublister. I can get you an algorithm to build one if you need.

Also (slightly OT) I have three dictionary files, one for OSPD, one for TWL, and one for SOWPODS.

Small nitpick: don't write

write

It's better to use the interface as the type than the implementation.
 
Marshal
Posts: 73997
332
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And welcome to the Ranch
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic