Xna Game « Beworded » Started !

Hi there,

I’ve begun to code an XNA game, finally !! It is called, for the moment, « Beworded ». It’s like bejeweled, but with words.

You have a grid of letters, and you need to swap 2 letters in order to form words between 3 and 5 letters long. When a word (or several) is found, it disappears in a beautiful particle explosion, the grid collapses on its empty spaces and is refilled from the top with new letters.

The words are found in a dictionary. I’ve struggled to find a text list for French and English words. For those who want to create a game based on a dictionary, here is the procedure I followed:

  1. install aspell, and the dictionary in the language you want to export.
  2. in a shell, type "aspell dump master --lang=fr --master=fr --strip-accents > FR-full.txt", with the good locale. The --strip-accents replaces accentuated words with their non-accentuated counterparts (épéé -> epee). I didn’t want to struggle with accents, the game is already gonna be difficult. The problem is that you get multiple instances of the same word.
  3. If you want to select some words, do it with a grep and a regular expression: "grep -i "^[a-z]\{3\}$" FR-full.txt > FR-3.txt". It extracted the 3-letters words from the list.
  4. If you want to sort your words: "sort FR-3.txt /O FR-3-sort.txt" in a DOS shell, for example.
  5. If you want to paste multiple files together, do this in DOS: "copy FR-3-sort.txt + FR-4-sort.txt + FR-5-sort.txt FR-final.txt".
  6. Finally, I used some C# code to remove doubles, and « to-lower » everything. I didn’t know any other way to do it. I’m not a shell guru, at all.

Well, the only interesting line is the second one, how to extract words from aspell, the rest is up to you.

Now that I have my dictionary, I need a file describing the occurrence of every letter in the French and English language. There are multiple sources for this, with different results. They are calculated from text corpus, I found the English one on wikipedia.

With the Dictionary and the Letters Frequency, I can build a random letter generator (using the frequency) to fill a grid with letters, and check in the dictionary if any word in the grid is a real word !

It works, and it works really fast without optimization. I thought it would take ages, but no :)

What I did, naively, for the moment, in order to speed-up the words lookup in the dictionary was to build a small (26×26) lookup table indexed with the first 2 characters of the word, like table["aa"], table["zs"]. This table helps me find a range of indexes inside the full word table. With this I only have to compare my word with like 10-20 words. If anyone has a better idea, I’m all ears.

Then I started coding utility functions in the Grid class, like « give me the potential words to check when I swap these 2 letters », or remove that list of words in the Grid. Now I’m generating the first Grid iteratively, removing all natively formed words, collapsing the Grid and refilling it with new letters.

Here is an intermediate screenshot (with awesome particle effects and bump maps !!!):

That’s all for the moment !

See you.

Post a Comment

Your email is never published nor shared. Required fields are marked *