PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

Programming word games?

I'm actually considering a simple word game in my spare time while working on a bigger project. :) I was just wondering, what's the best method to store all those words that I will use in my game? Will I be better off learning ADO CE and storing everything in a database? Or use a resource file? Or just use a plain "external" text file? Any advice from those who have experience working w/ these kinds of games?

Thanks in advance!

Erick
Personally I would just use an external file in my own proprietary format. If you want your source to be portable then you should stay away from OS / system specific database APIs.

I would either use a text file or store structures in a binary format (if you have additional information to store beyond just a word list). The latter is faster to implement (no parsing / tokenizing, etc), however the former would allow the file to be edited outside your application using a standard text editor.

Dan East
Personally, I'd avoid ADOCE, as the most useful DB feature for word games, the like expression, is crippled on ADOCE - in fact it only allows % at the beginning or end, and no ?s. Pretty rubbish really.

I'm not sure what the best architecture to use is, perhaps memory mapped files, although they're a bit of a pain at times.

There's quite a bit of research available on the net for doing indexing where the field is expected to be wildcard searched, such as a postfix index (i.e. hello is indexed normally under h, but also in a postfix index under e l and o). So to search for 'h%l%' you find H in the main index, and correlate it against the l section of the postfix index to find candidates.
I agree with Dan. Make your own file.
Dan: Thanks for the tip. You're right, I think I'm better off just using my own format.

Andyclap: What you mentioned is very interesting. I'll try to research on that from the net. Got any quick links where I can start with btw? Thanks!
An easy way, which I learned in some algorithm class I took years back, is to store the words in a tree structure. This structure will make it really easy to look if a word exists, and (if I remember corrctly) it will be quite small compared to a simple word file.

Each node in the tree contains a letter. First level contains the first character of the word, the second level the second character and so on. Each complete word is marked with an end marker node.

To find if a word exists just follow the nodes from top down, select the node that matches your next character in the word you are looking for. If you cant find the character at some level then the word you are looking for aren’t in your dictionary. If you have reached the end of the word and you find a end marker, the word exists.

Code:

C
A
R T
* *


Example of simple tree with the words CAR and CAT.

/Okku
That could be quite useful, you could do wildcard searching by scanning all child nodes where you get a ?, and recursively scanning the child tree where you get a %. I'm sure this has all been done before many times.

Not sure of any particular web links, but if you find any good ones, I'd certainly be interested if you posted 'em here.
In this case, the "tree" is more usually termed a <a href="http://www.nist.gov/dads/HTML/trie.html">"trie"</a>. That should be better to google for. Or actually, if you don't mind more academic stuff, use <a href="http://citeseer.nj.nec.com/cs?q=trie&cs;=1">citeseer</a>. <A href="http://citeseer.nj.nec.com/andersson96suffix.html">This one</a> might be a reasonable place to start.
Yup it's a trie. I believe they are covered in the big Cormen/Rivest "Introduction to Algorithms" book.
"Trie" isn't in the index of the copy on my desk. But it does cover "string matching" quite extensively. I don't have time to peruse it more right now.

I suspect (i.e possibly recall) that Knuth covers it well in the "seaching and sorting" volume (book 3 I believe), but that one's at home.
I checked my Knuth vol 3, tries are indeed covered.
Guys, in line with this topic, how do you efficiently parse a short word into separate letters? For example I have a TCHAR variable containing the word "BOY", how do I parse it such that I can have it like my_char[0] = "B", my_char[1] = "O", my_char[2] = "Y"? Mine is working but I'm not sure I'm doing it right and there maybe a simpler way to go about this. Thanks!
I would just use std::basic_string<_TCHAR>.

Then, str[0] is the first _TCHAR, str[1] is the second, and so on.

Further, you have all the standard string algorithms (like searching and replacing) at your disposal.
The two "Programming Pearls" books by Jon Bentley, aside from being fantastic awesome books, have a lot on string and word processing. I highly recommend them. Think of it as "Graphics Gems" for various non-graphics programming tasks.