Guest User

Untitled

a guest
Jun 25th, 2018
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.51 KB | None | 0 0
  1. #include "FBullCowGame.h"
  2. #include <map>
  3. #define TMap std::map
  4.  
  5. using int32 = int;
  6.  
  7.  
  8. int32 FBullCowGame::GetCurrentTry() const { return MyCurrentTry; }
  9. int32 FBullCowGame::GetWordLenght() const { return MyHiddenWord.length(); }
  10. int32 FBullCowGame::GetCurrentRound() const {return TotalRounds;}
  11.  
  12. EWordStatus FBullCowGame::IsCorrect(FString Guess)
  13. {
  14. if (IsIsogram(Guess))
  15. {
  16. return EWordStatus::NOT_ISOGRAM;
  17. }
  18. else if (false)
  19. {
  20. return EWordStatus::NOT_LOWERCASE;
  21. }
  22. else if (Guess.length() != MyHiddenWord.length())
  23. {
  24. return EWordStatus::INCORRECT_GUESS_LENGHT;
  25. }
  26. else
  27. {
  28. return EWordStatus::OK;
  29. }
  30. }
  31. bool FBullCowGame::IsIsogram(FString Guess)
  32. {
  33. TMap<char, bool> LettersSeen;
  34. for (auto Letter : Guess)
  35. {
  36. Letter = tolower(Letter);
  37. if (LettersSeen[Letter])
  38. {
  39. return true;
  40. }
  41. else
  42. {
  43. LettersSeen[Letter] = true;
  44. }
  45. }
  46.  
  47. int32 FBullCowGame::GetMaxTries() const { return MyHiddenWord.length(); }
  48.  
  49. void FBullCowGame::Reset()
  50. {
  51. MyCurrentTry = 1;
  52. TotalRounds++;
  53. }
  54.  
  55. FBullCowCount FBullCowGame::SubmitGuess(FString x)
  56. {
  57. FBullCowCount BullCowCount;
  58. int32 WordLenght = MyHiddenWord.length();
  59. for (int32 i = 0; i < WordLenght; i++) {
  60. for (int32 j = 0; j < WordLenght; j++) {
  61. if (x[i] == MyHiddenWord[j]) {
  62. if (x[i] == MyHiddenWord[i])
  63. BullCowCount.Bulls++;
  64. else
  65. BullCowCount.Cows++;
  66. }
  67. }
  68. }
  69. if (BullCowCount.Bulls == MyHiddenWord.length())
  70. bWin = true;
  71. MyCurrentTry++;
  72. return BullCowCount;
  73. }
  74.  
  75.  
  76. bool FBullCowGame::IsGameWon()const
  77. {
  78. return bWin;
  79. }
  80.  
  81. FBullCowGame::FBullCowGame()
  82. {
  83. Reset();
  84. }
Add Comment
Please, Sign In to add comment