I've been teaching myself programming in c#, until such time that I actually save up the money to do some courses. Inbetween learning, I do some fun stuff. Now I decided to do a 'Word Mole' type game in WinForms. The biggest problem I have is where to store the words, and how long will it take to create such a list??? Wondering now if it won't be easier trying to figure out the AI for tic tac toe that I've been busy with??? Any ideas???

Dani AI

Generated

Both projects are great learning exercises. For the wordlist problem you do not need to retype a whole dictionary — there are maintained collections you can adopt and trim to your needs. Good starting sources are , Princeton WordNet and the community word lists in the dwyl/english-words GitHub repo. Pick a source that matches your rules (allowed characters, proper nouns, regional spelling) and check its license.

Prep the list once and reuse it. Normalize to lower-case, strip punctuation/diacritics, remove obvious proper names if you do not want them, then produce small subsets by word length or difficulty. Add a tiny metadata column (length, frequency rank) so the game can quickly choose easy/hard words without scanning everything.

Storage choices depend on size and access patterns. For instant membership checks keep an in-memory HashSet<string>. If you need many prefix queries (for generators/solvers) use a trie (prefix tree) and consider serializing it to disk for fast startup. For very large collections an embedded DB like SQLite works well and avoids loading everything into RAM; it also makes querying by length or frequency trivial.

Algorithm tips for generating the grid: place longest words first, allow overlaps only where letters match, randomize directions and positions, and use backtracking when placement fails. A simple C# placement routine looks like this:

bool TryPlaceWord(char[,] grid, string word, Random rnd)
{
    var dirs = new (int dx,int dy)[] { (1,0),(0,1),(1,1),(1,-1),(-1,0),(0,-1),(-1,-1),(-1,1) };
    int attempts = 200;
    while(attempts-- > 0)
    {
        var dir = dirs[rnd.Next(dirs.Length)];
        int x = rnd.Next(grid.GetLength(0));
        int y = rnd.Next(grid.GetLength(1));
        bool ok = true;
        for(int i=0;i<word.Length;i++)
        {
            int nx = x + dir.dx * i, ny = y + dir.dy * i;
            if(nx<0||ny<0||nx>=grid.GetLength(0)||ny>=grid.GetLength(1)||
               (grid[nx,ny] != '\0' && grid[nx,ny] != word[i])) { ok = false; break; }
        }
        if(!ok) continue;
        for(int i=0;i<word.Length;i++) grid[x + dir.dx*i, y + dir.dy*i] = word[i];
        return true;
    }
    return false;
}

If you also want to continue with the Tic Tac Toe side, implementing minimax (with memoization or alpha-beta) is compact and teaches recursion and game trees. Both projects are worth doing; pick the one that matches the concepts you want to practice first.

Recommended Answers

All 2 Replies

Answer 1: use text file (you dont need any dataBase). Do some logical hierarchal sequence of values in this file, so you can easy retrieve them back out (just something simple)
Answer 2: I dont actually know the game, so hard to tell. If you know it, you can have some clue how much time can it take.
Answer 3: Depends how much you want to complicate. But in basic, there is not much to complicate really, not as Tic Tac Toe. Simple have to use a Random class, and look which places are free, and you have to look for the "3 in the row" to win the game.
I would say you can write AI in a simple method (few minutes work).

thanks, was thinking down the lines of xml for the wordlist, but basically the list needs to contain a full dictionary. gonna see if I can findone to download from somewhere. As for the AI, I had in mind the kind where you would almost never be able to beat it. Still working on that when I'm not trying to get to grips with enums etc.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.