Example #1
0
        public void LoadJsonFiles()
        {
            try
            {
                baseList = ReadJsonFile.ReadBaseFile();

                valueList = ReadJsonFile.ReadValuesFile();

                cypherRowList = ReadJsonFile.ReadCypherFile();

                wordsToFind = ReadJsonFile.ReadWordsFile();
            }
            catch (Exception ex)
            {
            }
        }
Example #2
0
        public List <PuzzelSolution> FindWords(char[,] matrix)
        {
            try
            {
                List <string> wordsToFind = ReadJsonFile.ReadWordsFile();
                int           rows        = matrix.GetLength(0);
                int           columns     = matrix.GetLength(1);

                foreach (var word in wordsToFind)
                {
                    var wordLength  = word.Length;
                    var firstLetter = word[0];

                    bool foundWord = false;

                    for (int x = 0; x < rows; x++)
                    {
                        for (int y = 0; y < columns; y++)
                        {
                            if (firstLetter == matrix[x, y])
                            {
                                foundWord = FindWordHorizontal(matrix, word, x, y);

                                if (!foundWord)
                                {
                                    foundWord = FindWordVertical(matrix, word, x, y);
                                }

                                if (!foundWord)
                                {
                                    foundWord = FindWordDiagonal(matrix, word, x, y);
                                }

                                if (!foundWord)
                                {
                                    foundWord = FindWordDiagonalLeft(matrix, word, x, y);
                                }

                                if (!foundWord)
                                {
                                    foundWord = FindWordHorizontalB(matrix, word, x, y);
                                }

                                if (!foundWord)
                                {
                                    foundWord = FindWordVerticalB(matrix, word, x, y);
                                }

                                if (!foundWord)
                                {
                                    foundWord = FindWordDiagonalB(matrix, word, x, y);
                                }

                                if (!foundWord)
                                {
                                    foundWord = FindWordDiagonalLeftB(matrix, word, x, y);
                                }

                                if (!foundWord)
                                {
                                    foundWord = FindWordAnyDirection(matrix, word, x, y);
                                }
                            }

                            if (foundWord)
                            {
                                break;
                            }
                        }
                        if (foundWord)
                        {
                            break;
                        }
                    }
                }

                return(puzzelSolutions);
            }
            catch (Exception ex)
            {
                return(null);
            }
        }