FBullCowCount FBullCowGame::SubmitValidGuess(FString Guess) { CurrentTry++; FBullCowCount Count; for (int32 GuessChar = 0; GuessChar < Guess.length(); GuessChar++) { for (int32 HiddenWordChar = 0; HiddenWordChar < HiddenWord.length(); HiddenWordChar++) { if (Guess[GuessChar] == HiddenWord[HiddenWordChar]) { if (GuessChar == HiddenWordChar) { Count.Bulls++; } else { Count.Cows++; } } } } if (Count.Bulls == GetHiddenWordLength()) { bGameIsWon = true; } else { bGameIsWon = false; } return Count; }
EWordStats FBullCowGame::ChechGuessValidity(std::string x) const { if (!IsIsogram(x))//not isogram return EWordStats::Not_Isogram; else if (!IsLowerCase(x))//CapsLock ON return EWordStats::N_LCase; else if (x.length() != GetHiddenWordLength())//wrong size return EWordStats::To_Wrong; else//ok return EWordStats::OK; }
EWordStatus FBullCowGame::CheckGuessValidity(FString Guess) const { if (!IsIsogram(Guess)) { return EWordStatus::Not_Isogram; } if (Guess.length() != GetHiddenWordLength()) { return EWordStatus::Wrong_Lenght; } if (!IsLowerCase(Guess)) { return EWordStatus::Not_Lowercase; } return EWordStatus::OK; }
EGuessStatus FBullCowGame::CheckGuessValidity(FString *Guess) const { if ((*Guess).length() != GetHiddenWordLength()) { return EGuessStatus::WRONG_LENGTH; } else if (!IsIsogram(Guess)) { return EGuessStatus::NOT_ISOGRAM; } else if (!IsLowercase(Guess)) { return EGuessStatus::NOT_LOWERCASE; } else { return EGuessStatus::OK; } }
EGuessStatus FBullCowGame::CheckGuessValidity(FString Guess) const { if (!IsIsogram(Guess)) // if the guess isn't an isogram { return EGuessStatus::Not_Isogram; } else if (!IsLowercase(Guess)) // if the guess isn't all lowercase { return EGuessStatus::Not_Lowercase; } else if (Guess.length() != GetHiddenWordLength()) // if the guess length is wrong { return EGuessStatus::Wrong_Length; } else { return EGuessStatus::OK; } }
EGuessStatus FBullCowGame::CheckGuessValidity(FString ThisGuess) const /* Checks the user guess for validity - checks if an isogram - checks if all lower-case - checks if correct length Returns error code if fails any of those checks */ { if (!IsIsogram(ThisGuess)) { // if the guess is not an isogram return EGuessStatus::Not_Isogram; } else if (!IsLowercase(ThisGuess)) { // if the guess is not lower-case return EGuessStatus::Not_Lowercase; } else if (ThisGuess.length() != GetHiddenWordLength()) { // if the guess is different length from hidden word then return error return EGuessStatus::Wrong_Length; }; return EGuessStatus::OK; // TODO Later make actual error }; // CheckGuessValidity
int32 FBullCowGame::GetMaxTries() const { // map the difficulty level to the amount of tries allowed std::map <int32, int32> WordLengthToMaxTries{ {3,10}, {4,10}, {5,10}, {6,16}, {7,20} }; return WordLengthToMaxTries[GetHiddenWordLength()]; }
int32 FBullCowGame::GetMaxTries() const { // Returns the number of guesses allowed for the length of the hidden word TMap<int32, int32> WordLengthToMaxTries = { { 3, 4 },{ 4, 7 },{ 5, 10 },{ 6, 13 },{ 7, 16 } }; return WordLengthToMaxTries[GetHiddenWordLength()]; }