Hello,
I’ve have one major bug in my Bulls and Cows Game: PlayGame() doesn’t work. I tried debugging it myself and what I found is that somewhere in my code the MyMaxTry variable is getting reset to 0 rather than staying at 8. I found this by printing MyMaxTry inside GetMaxTries(), which returns 0 in the compiler.
Code #1
int32 FBullCowGame::GetMaxTries() const
{
std::cout << MyMaxTry << std::endl; // check to see value...
return MyMaxTry;
}
This ^^^ is what it returns: The “Welcome … thinkinng of?” is part of void PrintIntro() while, “Would you like to play again?” is part of bool AskToPlayAgain(), so void PlayGame() must be the problem.
Below is my PlayGame() function:
Code #2
void PlayGame()
{
BCGame.Reset();
int32 MaxTries = BCGame.GetMaxTries();
// Loop for the # of terms asking for guesses
for (int32 count = 1; count <= MaxTries; count++)
{
FText Guess = GetGuess(); // TODO: check for valid guess before incrementing count
// Submit guess to the game
FBullCowCount BullCowCount = BCGame.SubmitGuess(Guess);
// Print # of Bulls and Cows
std::cout << "Bulls = " << BullCowCount.Bulls;
std::cout << ". Cows = " << BullCowCount.Cows;
std::cout << std::endl;
}
// TODO: game summary
return;
}
I’ve been comparing my code to the Github repository and I can’t find where I went wrong. I know something must have happened around episode 68 (but it may not have been that episode).
I’ve tried following my code logically by checking the definitions of each object and one place where it might have gone wrong is here: when I check the definition of GetMaxTries() (which is the source of the problem) in
int32 MaxTries = BCGame.GetMaxTries();
in main.cpp, VS Code brings me to Code #1 (above) in FBullCowGame.cpp. Next, when I check the definition of MyMaxTry in the function it brings me the private section of the class in FBullCowGame.h (which has the MyMaxTry variable declared, but not initiated). I believe that it should instead bring me to this part of the code in FBullCowGame.cpp:
void FBullCowGame::Reset()
{
constexpr int32 MAX_TRY = 8;
constexpr int32 MyMaxTry = MAX_TRY;
int32 MyCurrentTry = 1;
// some unimportant code...
return;
}
What should I do to fix this?
Thanks, 
Enrico
