public void ExtactColFromMatrixMethodReturnsSpecificSymbolInsteadOfNullOnSpecificPosition()
        {
            var arrOperator = new ArrayOperator();
            var randomGen   = new RandomGenerator();

            var fakeAlphabet = new string[]
            {
                null, null, null, null, null, null, "a"
            };

            var fakeMatrix = new string[5, 5];

            fakeMatrix[0, 0] = "a";
            fakeMatrix[1, 0] = "b";
            fakeMatrix[2, 0] = null;
            fakeMatrix[3, 0] = null;
            fakeMatrix[4, 0] = "a";


            var counter = 0;


            var stringToCompare = arrOperator.ExtractColFromMatrix(fakeMatrix, 0);

            for (int i = 0; i < stringToCompare.Length; i++)
            {
                if (stringToCompare[i].ToString() == GlobalConstants.SpecificSymbolToReplaceNull)
                {
                    counter++;
                }
            }
            Assert.AreEqual(2, counter);
        }
        public void ExtactColFromMatrixMethodReturnsSpecificSymbolInsteadOfNull()
        {
            var arrOperator = new ArrayOperator();
            var randomGen   = new RandomGenerator();

            var fakeAlphabet = new string[]
            {
                null, null, null, null, null, null, "a"
            };

            var fakeMatrix = new string[10, 7];


            for (int i = 0; i < fakeMatrix.GetLength(0); i++)
            {
                for (int col = 0; col < fakeMatrix.GetLength(1); col++)
                {
                    fakeMatrix[i, col] = randomGen.GenerateRandomLetter(fakeAlphabet);
                }
            }

            var stringToCompare = arrOperator.ExtractColFromMatrix(fakeMatrix, 3);

            StringAssert.Contains(stringToCompare, GlobalConstants.SpecificSymbolToReplaceNull);
        }
Exemple #3
0
        public void RevealWord(string[,] fieldOfCodedWords, List <string> guessedWords)
        {
            Console.Clear();
            var lineInArray = string.Empty;
            int startIndex  = 0;

            for (int row = 0; row < fieldOfCodedWords.GetLength(0); row++)
            {
                lineInArray = arrayOperator.ExtractRowFromMatrix(fieldOfCodedWords, row);

                for (int wordCount = 0; wordCount < guessedWords.Count; wordCount++)
                {
                    if (Regex.Match(lineInArray, guessedWords[wordCount]).Success)
                    {
                        startIndex = Regex.Match(lineInArray, guessedWords[wordCount]).Index;

                        for (int nextLetter = 0; nextLetter < guessedWords[wordCount].Length; nextLetter++)
                        {
                            coordinates.Add(new int[]
                            {
                                row, startIndex + nextLetter
                            });
                        }
                    }
                }
            }

            for (int col = 0; col < fieldOfCodedWords.GetLength(1); col++)
            {
                lineInArray = arrayOperator.ExtractColFromMatrix(fieldOfCodedWords, col);

                for (int wordCount = 0; wordCount < guessedWords.Count; wordCount++)
                {
                    if (Regex.Match(lineInArray, guessedWords[wordCount]).Success)
                    {
                        startIndex = Regex.Match(lineInArray, guessedWords[wordCount]).Index;

                        for (int nextLetter = 0; nextLetter < guessedWords[wordCount].Length; nextLetter++)
                        {
                            coordinates.Add(new int[]
                            {
                                startIndex + nextLetter, col
                            });
                        }
                    }
                }
            }

            var isMatch = false;

            for (int row = 0; row < fieldOfCodedWords.GetLength(0); row++)
            {
                for (int col = 0; col < fieldOfCodedWords.GetLength(1); col++)
                {
                    for (int indexOfCoordinatesOfGuessWord = 0; indexOfCoordinatesOfGuessWord < coordinates.Count; indexOfCoordinatesOfGuessWord++)
                    {
                        if (coordinates[indexOfCoordinatesOfGuessWord][0] == row && coordinates[indexOfCoordinatesOfGuessWord][1] == col)
                        {
                            isMatch = true;
                        }
                        else
                        {
                            continue;
                        }
                    }

                    if (isMatch)
                    {
                        Console.ForegroundColor = ConsoleColor.Yellow;
                        Console.Write("{0} ", fieldOfCodedWords[row, col]);
                        isMatch = false;
                    }
                    else
                    {
                        Console.ResetColor();
                        Console.Write("{0} ", fieldOfCodedWords[row, col]);
                    }
                }

                Console.WriteLine();
            }
            Console.WriteLine();
            Console.WriteLine();
            Console.WriteLine("You've managed to guess {0} words", guessedWords.Count);
            coordinates.Clear();
        }
Exemple #4
0
        public void GenerateCrossword()
        {
            var colFromMatrix           = string.Empty;
            var rowFromMatrix           = string.Empty;
            var listFromSpecificPattern = new List <string>();
            var frameOfAPotentialWord   = string.Empty;
            var colOutsideRange         = 1;
            var indexCounter            = 0;
            var adaptatedIndex          = 0;
            var randomWord = string.Empty;

            for (int row = 1; row < crossword.GetLength(0); row++)
            {
                for (int col = colOutsideRange; col < crossword.GetLength(1); col++)
                {
                    colFromMatrix         = arrayOperator.ExtractColFromMatrix(crossword, col);
                    frameOfAPotentialWord = wordsOperator.ExtractFrameOfAPotentialWord(colFromMatrix);

                    if (frameOfAPotentialWord == string.Empty)
                    {
                        break;
                    }

                    if (!frameOfAPotentialWord.Contains(GlobalConstants.SpecificSymbolToReplaceNull))
                    {
                        while (!wordVerificator.ContainsWordWithSpecificBeginning(listOfAllWords, frameOfAPotentialWord))
                        {
                            if (frameOfAPotentialWord.Length > 1)
                            {
                                frameOfAPotentialWord = frameOfAPotentialWord.Substring(1);
                                indexCounter++;
                            }
                            else
                            {
                                break;
                            }
                        }

                        adaptatedIndex          = indexCounter;
                        listFromSpecificPattern = wordsOperator.GetListOfAllWordsFromASpecifiedBeginning(frameOfAPotentialWord);
                        randomWord = randomGenerator.GenerateRandomWord(listFromSpecificPattern);

                        wordsOperator.CollectedWordsFromCrossword.Add(randomWord);


                        crossword    = matrixWriter.WriteOnCol(crossword, randomWord, adaptatedIndex, col);
                        indexCounter = 0;

                        Console.Clear();
                        painter.PaintMatrix(crossword, col, adaptatedIndex);

                        break;
                    }
                    else
                    {
                        while (!wordVerificator.ContainsWordWithSpecificPositionOfCharacters(listOfAllWords, frameOfAPotentialWord))
                        {
                            if (frameOfAPotentialWord.Length > 1)
                            {
                                frameOfAPotentialWord = frameOfAPotentialWord.Substring(1);
                                indexCounter++;
                            }
                            else
                            {
                                break;
                            }
                        }

                        adaptatedIndex          = indexCounter;
                        listFromSpecificPattern = wordsOperator.GetListOfAllWordsFromASpecifiedPattern(frameOfAPotentialWord);
                        randomWord = randomGenerator.GenerateRandomWord(listFromSpecificPattern);

                        wordsOperator.CollectedWordsFromCrossword.Add(randomWord);

                        crossword    = matrixWriter.WriteOnCol(crossword, randomWord, adaptatedIndex, col);
                        indexCounter = 0;

                        Console.Clear();
                        painter.PaintMatrix(crossword, col, adaptatedIndex);

                        break;
                    }
                }

                //row begins here
                frameOfAPotentialWord = string.Empty;
                rowFromMatrix         = arrayOperator.ExtractRowFromMatrix(crossword, row);
                frameOfAPotentialWord = wordsOperator.ExtractFrameOfAPotentialWord(rowFromMatrix);
                indexCounter          = 0;

                if (frameOfAPotentialWord == string.Empty)
                {
                    break;
                }

                //fillerOfMatrix
                if (!frameOfAPotentialWord.Contains(GlobalConstants.SpecificSymbolToReplaceNull))
                {
                    while (!wordVerificator.ContainsWordWithSpecificBeginning(listOfAllWords, frameOfAPotentialWord))
                    {
                        if (frameOfAPotentialWord.Length > 1)
                        {
                            frameOfAPotentialWord = frameOfAPotentialWord.Substring(1);
                            indexCounter++;
                        }
                        else
                        {
                            continue;
                        }
                    }

                    adaptatedIndex          = indexCounter;
                    listFromSpecificPattern = wordsOperator.GetListOfAllWordsFromASpecifiedBeginning(frameOfAPotentialWord);
                    randomWord = randomGenerator.GenerateRandomWord(listFromSpecificPattern);

                    wordsOperator.CollectedWordsFromCrossword.Add(randomWord);

                    crossword    = matrixWriter.WriteOnRow(crossword, randomWord, row, adaptatedIndex);
                    indexCounter = 0;
                    colOutsideRange++;

                    Console.Clear();
                    painter.PaintMatrix(crossword, row, adaptatedIndex);

                    continue;
                }
                else
                {
                    while (!wordVerificator.ContainsWordWithSpecificPositionOfCharacters(listOfAllWords, frameOfAPotentialWord))
                    {
                        if (frameOfAPotentialWord.Length > 1)
                        {
                            frameOfAPotentialWord = frameOfAPotentialWord.Substring(1);
                            indexCounter++;
                        }
                        else
                        {
                            throw new FormatException("No such word exists in the given database.");
                        }
                    }

                    adaptatedIndex          = indexCounter;
                    listFromSpecificPattern = wordsOperator.GetListOfAllWordsFromASpecifiedPattern(frameOfAPotentialWord);
                    randomWord = randomGenerator.GenerateRandomWord(listFromSpecificPattern);
                    wordsOperator.CollectedWordsFromCrossword.Add(randomWord);

                    crossword    = matrixWriter.WriteOnRow(crossword, randomWord, row, adaptatedIndex);
                    indexCounter = 0;
                    colOutsideRange++;

                    Console.Clear();
                    painter.PaintMatrix(crossword, row, adaptatedIndex);


                    continue;
                }
            }
            painter.ListAllTheWords(wordsOperator);
            Thread.Sleep(300);
            Console.Clear();

            painter.PaintMatrixWithSymbol(crossword, GlobalConstants.SymbolToHideNumbersWith);
            crosswordSolver.SolveCrossword(crossword, wordsOperator);
        }