Sorry, this is a year after your last post.
I’ve just started the course, and so far it’s been quite good. There’s been one or two times where I’ve questioned some of the decisions made in the tutorials, (one being putting the summary statistic inside the play game logic, in my opinion, whilst the game method is run, the game variables and logic are still “live”, and hence could change. Not reached the part where this is/ should be implemented yet, so hopefully Ben has changed his mind), and in this video, yep I don’t think lecture actually addressed the issue of the error arising. There’s still an index out of bounds exception, due to the WordLength being used.
I would say that your above solution is correct. Guess.Length() is the right thing to do. Also, if you don’t change it, I would possibly say that HiddenWordLength is better, it’s more specific… it lets you know EXACTLY which WordLength is used.
Also, as a bit more optimization, although small, I would be tempted to replace WordLength with the method GetHiddenWordLength(), it’s there, so might as well use it, and not define a new variable (unless there is a reason not to do it like this?).
// loop through all letters in the hidden word
for (int32 HiddenWordChar = 0; HiddenWordChar < GetHiddenWordLength(); HiddenWordChar++)
{
// compare latters against the guess
for (int32 GuessChar = 0; GuessChar < Guess.length(); GuessChar++)
{
// if they match
if (MyHiddenWord[HiddenWordChar] == Guess[GuessChar])
{
if (HiddenWordChar == GuessChar)
{
BullCowCount.Bulls++; // increment bulls
}
else
{
BullCowCount.Cows++; // increment cows
}
}
}
}