I am really having trouble grasping certain parts of this function so i will break it down to my knowledge and please correct me where i am wrong
so the code calls out to the function my current try and it increments its value plus one every time it loops thru.
then it creates a variable for bullcowcount for the struct to take account and start to take count ?
it creates a variable based on the length of my hidden word and it assigns it to the variable hiddenwordlength.
from there it starts to loop thru with a temp variable called MHWchar which starts off at = 0 which it runs thru and loops thru it until its equal or less than the hidden word length and incrementing MHWchar value plus one every time it doesn't equal to it.
then it does the same thing but with a variable called Gchar
then this is where I am most confused. it takes the players to guess input (Guess [Gchar]) and so what it does there is it takes the players input guess variable and it will iterate from 0 to the length of the word one digit at a time. creating a numeric code which is represented in the value of each letter in the alphabet which could be lets say 1234 if my word was = bcde = 1234
and so it would take these digits and do the same but with my hidden word [MHWChar] which if my word was bcde = 1234 would equal the same as my guess and so then if those numeric values are equal in which this example it is and so it would increment my bull count++, and so its basically taking whatever string guess is and running it thru the for loop under GChar and so it create a iteration for each digit and compare it to each other and creating a plus count in the bulls++ count in the struct
if (Guess [GChar] == MyHiddenWord[MHWChar])
is actually taking my guess word and running thru the Gchar for loop and breaking it down into iterations is that correct?
then it does the same thing but for the hidden word compares each of its numerical values iterations if they match it increments bull++ if not it does cows.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
|
FBullCowCount FBullCowGame::SubmitGuess(FString Guess)
{
//incriment the turn number
MyCurrentTry++;
// setup a return variable
FBullCowCount BullCowCount;
//loop through all letters in the guess
int32 HiddenWordLenght = MyHiddenWord.length();
for (int32 MHWChar = 0; MHWChar < HiddenWordLenght; MHWChar++){
//compare letters against the hidden word
for (int32 GChar = 0; GChar < HiddenWordLenght; GChar++){
//if they match then
if (Guess [GChar] == MyHiddenWord[MHWChar]) {
if (MHWChar == GChar) {//if theyre in the same place
BullCowCount.Bulls++;// increment bulls
}
else {
BullCowCount.Cows++;//incriment cows
|