Click here to Skip to main content
12,353,249 members (72,682 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: C#
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 12-Nov-12 20:40pm
Edited 12-Nov-12 20:45pm
v2
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

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,
select top 1 * from dictionary where len(word)=4 order by rank;
Hope this helps you ,

Thanks.
  Permalink  
v2
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

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.
  Permalink  

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.160621.1 | Last Updated 13 Nov 2012
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100