Advertisement
Guest User

Untitled

a guest
Feb 17th, 2019
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.14 KB | None | 0 0
  1. #include<iostream>
  2. #include<string>
  3. #include <ctime>
  4. using namespace std;
  5.  
  6. struct Player {
  7. string name;
  8. int number_games;
  9. int * games;
  10. int playerscore = 0;
  11.  
  12. Player(int number_of_games)
  13. {
  14. number_games = number_of_games;
  15. games = new int[number_of_games];
  16. }
  17.  
  18. };
  19.  
  20. int games[] = {
  21. 1 /* Rock */,
  22. 2 /* paper */,
  23. 3 /* Scissor */,
  24. 4 /* lizard */,
  25. 5 /* spock */
  26. };
  27.  
  28.  
  29. int element_to_number(string val)
  30. {
  31. //
  32. if (val == "Rock" || val == "Rock,")
  33. return 1;
  34. else if (val == "Paper" || val == "Paper,")
  35. return 2;
  36. else if (val == "Scissor" || val == "Scissor,")
  37. return 3;
  38. else if (val == "Lizard" || val == "Lizard,")
  39. return 4;
  40. else
  41. return 5;
  42. //
  43. }
  44.  
  45. int SimulateGame(int PlayerChoice, int CompChoice)
  46. {
  47. if ((PlayerChoice == 1 && CompChoice == 1) ||
  48. (PlayerChoice == 2 && CompChoice == 2) ||
  49. (PlayerChoice == 3 && CompChoice == 3) ||
  50. (PlayerChoice == 4 && CompChoice == 4) ||
  51. (PlayerChoice == 5 && CompChoice == 5))
  52. {
  53. return 2;
  54. }
  55.  
  56. else if ((PlayerChoice == 3 && CompChoice == 2) ||
  57. (PlayerChoice == 2 && CompChoice == 1) ||
  58. (PlayerChoice == 1 && CompChoice == 4) ||
  59. (PlayerChoice == 4 && CompChoice == 5) ||
  60. (PlayerChoice == 5 && CompChoice == 3) ||
  61. (PlayerChoice == 3 && CompChoice == 4) ||
  62. (PlayerChoice == 4 && CompChoice == 2) ||
  63. (PlayerChoice == 2 && CompChoice == 5) ||
  64. (PlayerChoice == 5 && CompChoice == 1) ||
  65. (PlayerChoice == 1 && CompChoice == 3))
  66. {
  67. return 1;
  68. }
  69.  
  70. else if ((PlayerChoice == 2 && CompChoice == 3) ||
  71. (PlayerChoice == 1 && CompChoice == 2) ||
  72. (PlayerChoice == 4 && CompChoice == 1) ||
  73. (PlayerChoice == 5 && CompChoice == 4) ||
  74. (PlayerChoice == 3 && CompChoice == 5) ||
  75. (PlayerChoice == 4 && CompChoice == 3) ||
  76. (PlayerChoice == 2 && CompChoice == 4) ||
  77. (PlayerChoice == 5 && CompChoice == 2) ||
  78. (PlayerChoice == 1 && CompChoice == 5) ||
  79. (PlayerChoice == 3 && CompChoice == 1))
  80. {
  81. return 0;
  82. }
  83. }
  84.  
  85. int computerplay() {
  86. srand(time(NULL));
  87. int r = (rand() % 5) + 1;
  88. return r;
  89. }
  90.  
  91. int main()
  92. {
  93. freopen("input.txt", "r", stdin);
  94. freopen("output.txt", "w", stdout);
  95.  
  96. int a;
  97. cin >> a;
  98. Player **players = new Player*[a];
  99. for (int i = 0; i < a; i++)
  100. {
  101. string name;
  102. int number_games;
  103. cin >> name >> number_games;
  104. players[i] = new Player(number_games);
  105. players[i]->name = name;
  106. for (int j = 0; j < number_games; j++) {
  107. string val;
  108. cin >> val;
  109. players[i]->games[j] = element_to_number(val);
  110. }
  111. }
  112.  
  113. for (int i = 0; i < a; i++)
  114. {
  115. for (int j = 0; j < players[i]->number_games; j++) {
  116. bool replay = false;
  117. int pcgame = computerplay();
  118. int winScore = SimulateGame(*players[i]->games, pcgame);
  119. while (winScore == 2)
  120. {
  121. replay = true;
  122. int pcgame = computerplay();
  123. winScore = SimulateGame(*players[i]->games, pcgame);
  124. if (winScore != 2)
  125. players[i]->playerscore += winScore;
  126. }
  127. if (replay == false)
  128. players[i]->playerscore += winScore;
  129. players[i]->games[j];
  130. }
  131. float winLuck = float(players[i]->playerscore) / float(players[i]->number_games);
  132. cout << players[i]->name << " - " << winLuck << endl;
  133. }
  134. return 0;
  135. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement