Click here to Skip to main content
15,896,201 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello Folks,

I am a beginner and have been playing around with C#. I have recently written the code for the very popular 'Cows and Bulls' word game. Its working for 2 players i.e; One player thinks of a word and the other person has to guess it. I am giving only 10 chances for guessing.

I now want to make the game for a single player(Computer v Human). I was wondering if there was anyway of getting all the 4 letter words in the English Language without Letter repetition(I have limited the game to 4 Letter words only). I know I can use an Enumeration and write down all the 4 letter words. But that's Hard Coding the Words. That would be my last option.

Any help would be appreciated.
Posted
Updated 12-Nov-12 20:45pm
v2

Hi,

You can store the information of the words in the database. and add one more column with the rank. When computer use particular word, mark the rank as +1.

Everytime you choose the word use order by clause to order with rank. so the lowest rank will come first, Use the word and increment the word.

You can filter the word using len SQL function. So your query would be like,
SQL
select top 1 * from dictionary where len(word)=4 order by rank;

Hope this helps you ,

Thanks.
 
Share this answer
 
v2
As AmitGajjar said, you should store the words somewhere, though I'd only store the eligible words (4 letters, non-repeating characters). The list of words is going to be large if you use a reasonable size dictionary, so you might consider partitioning on the first character (e.g. an "a" table, "b" table) etc if performance is bad.

One thing you can do to make your task easier is to use Linux's dictionary see here for the file location[^]. You can easily write a perl script to process the file and emit all the eligible words into a new file (or files if you want to segregate by first letter). Then all you need do is get the words into your backing store, though you could use the text file(s) as your backing store.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900