Bogger
Bogger

Reputation: 1

Wordle logic problem regarding when a letter needs to turn yellow, turning random letters yellow

In wordle, when you guess a word carrying a letter present in the word to guess, the letter is supposed to turn yellow. This a command line application, so I would need to change the foreground color, and background color before I print the string. Im having a problem of random letters being turned yellow, here is an exampleenter image description here

     public static void GameBoard()
        {
            Clear();

            WriteLine(emptySpace+" THE GAMEBOARD\n");
            for (int i = 0; i < 30; i++)
            {
                if (i % 5 == 0)
                {
                    Write("\n" + emptySpace);
                }
                colorValidity(guessedWords, i);
            }
            WriteLine($"\n\nYour guesses: {turns}");
            Write("\n\nWORD: ");
            foreach(var i in wordToGuess) Write(i);
            WriteLine("\n\n");
            Turn();
        }
        public static void colorValidity(char[] guessedWordsArr, int iteratedCount)
        {
            string wordToGuessStr = wordToGuess.ToString();
            if (iteratedCount % 5 == 0) count = 0;
            //"Yellow" letter validity 
            if (!guessedWordsArr[iteratedCount].Equals(wordToGuess[count])
                && wordToGuessStr.Contains(guessedWordsArr[iteratedCount]))
            {
                changeToColor($"[{guessedWordsArr[iteratedCount]}]", 1);
            }
            //"Green" letter validity
            else if (guessedWordsArr[iteratedCount].Equals(wordToGuess[count]))
            {
                changeToColor($"[{guessedWordsArr[iteratedCount]}]", 2);
            }  
            else
            {
                 //Posting index with no color
                 Write($"[{guessedWordsArr[iteratedCount]}]");
            }
            count++;    
        }

The guesses are placed into a 30 length char[] array, the reason for count to be incremented is to loop through each letter in a 5 length guess, but being reset to zero once the iterated count (i) is divisible by 5, showing that a new guess has been placed due to the result being 0

Upvotes: 0

Views: 170

Answers (0)

Related Questions