Exemple #1
0
    private string AddLetterMappings(string word, int index, string currentKey)
    {
        string allKeys = "";

        for (int i = index; i < word.Length; i++)
        {
            if (Stopping)
            {
                return("");
            }

            string key = CBWordDict.AddToKey(currentKey, i, word[i]);

            if (!string.IsNullOrEmpty(allKeys))
            {
                allKeys += ";";
            }

            allKeys += key;

            // Only recurse if this word is less than the max length and there is another letter in the word
            if (word.Length <= CBUtilities.MaxLengthForFullWordMapping && i + 1 < word.Length)
            {
                allKeys += ";";
                allKeys += AddLetterMappings(word, i + 1, key);
            }
        }

        return(allKeys);
    }
Exemple #2
0
    public void StartFindingWords(CBWordDict wordDictionary, int boardSize, List <List <CrosswordBuilder.Cell> > cells)
    {
        this.wordDictionary = wordDictionary;
        this.boardSize      = boardSize;

        blocks = new List <List <bool> >();

        for (int i = 0; i < cells.Count; i++)
        {
            blocks.Add(new List <bool>());

            for (int j = 0; j < cells[i].Count; j++)
            {
                blocks[i].Add(cells[i][j].isBlock);
            }
        }

        if (IsProcessing)
        {
            waitForWorkerToStop = true;
            worker.Stop();
        }
        else
        {
            StartProcessing();
        }
    }
Exemple #3
0
    public void StartFindingWords(
        CBWordDict wordDictionary,
        List <string> wordsToTry,
        List <List <CrosswordBuilder.Cell> > cells,
        List <string> usedWords,
        int startRow,
        int startCol,
        int length,
        bool isAcross)
    {
        this.wordDictionary = wordDictionary;
        this.wordsToTry     = wordsToTry;
        this.cells          = cells;
        this.usedWords      = usedWords;
        this.startRow       = startRow;
        this.startCol       = startCol;
        this.length         = length;
        this.isAcross       = isAcross;

        if (IsProcessing)
        {
            waitForWorkerToStop = true;
            worker.Stop();
        }
        else
        {
            StartProcessing();
        }
    }
Exemple #4
0
    public List <string> GetPossibleWords(List <List <CrosswordBuilder.Cell> > cells, int startRow, int startCol, int length, bool isAcross)
    {
        if (!HasWordsOfLength(length))
        {
            // Return an empty list
            return(null);
        }

        string        wordDictKey   = "";
        List <string> possibleWords = null;

        for (int i = 0; i < length; i++)
        {
            int row = startRow + (isAcross ? 0 : i);
            int col = startCol + (isAcross ? i : 0);

            CrosswordBuilder.Cell cell = cells[row][col];

            if (cell.character != ' ')
            {
                wordDictKey = CBWordDict.AddToKey(wordDictKey, i, cell.character);

                if (length > CBUtilities.MaxLengthForFullWordMapping)
                {
                    List <string> words = GetMappedWords(length, wordDictKey);

                    // If there are no words with this key then there are no words that fit in the given cells
                    if (words == null)
                    {
                        return(null);
                    }

                    // If the new list is less than the one we have so far then lets use that one instead
                    if (possibleWords == null || words.Count < possibleWords.Count)
                    {
                        possibleWords = words;
                    }

                    wordDictKey = "";
                }
            }
        }

        // If possible words is not null then we still need to get the words
        if (possibleWords == null)
        {
            // If wordDictKey is empty then all the cells are blank
            if (string.IsNullOrEmpty(wordDictKey))
            {
                // Return all words of the given length
                return(loadedWords[length]);
            }

            // Return the words using the key
            return(GetMappedWords(length, wordDictKey));
        }

        return(possibleWords);
    }
Exemple #5
0
    public List <List <bool> > GenerateRandomBlocks(CBWordDict wordDictionary, int boardSize, int maxNeighbourCount, bool noSquares)
    {
        CBAutoFillerWorker tempWorker = new CBAutoFillerWorker();

        tempWorker.WordDictionary = wordDictionary;
        tempWorker.BoardSize      = boardSize;

        // This method completes really fast so theres no need to run it in a seperate thread
        return(tempWorker.GenerateRandomBlocks(maxNeighbourCount, noSquares));
    }