Advertisement
Guest User

Untitled

a guest
Sep 20th, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.75 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3.  
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8.  
  9. int n_players;
  10. cout << "Enter amount of players" << endl;
  11. cin >> n_players;
  12.  
  13. int scores[n_players];
  14. int bids[n_players];
  15. int achieved[n_players];
  16. string names[n_players];
  17.  
  18. // Denumirea jucatorilor
  19.  
  20. for(int i = 0; i < n_players; i++){
  21. cout << "Enter name of player " << i + 1;
  22. if(i == 0){
  23. cout << " (Starting player)" << endl;
  24. }else{
  25. cout << endl;
  26. }
  27. cin >> names[i];
  28. }
  29.  
  30. int round = 1;
  31. int roundamount = 0;
  32. int turn = 0;
  33. int bidsum = 0;
  34. int ach = 0;
  35.  
  36. for(int i = 0; i < n_players; i++){
  37. scores[i] = 0;
  38. }
  39.  
  40. while(round <= 3 * n_players + 12){
  41.  
  42. if(1 <= round && round <= n_players){
  43. roundamount = 1;
  44. }else if(round > n_players && round <= n_players + 6){
  45. roundamount = round - n_players + 1;
  46. }else if(round > n_players + 6 && round <= 2 * n_players + 6){
  47. roundamount = 8;
  48. }else if(round > 2 * n_players + 6 && round <= 2 * n_players + 12){
  49. roundamount = 2 * n_players + 14 - round;
  50. }else{
  51. roundamount = 1;
  52. }
  53. cout << "-----------------------------------------------------" << endl << "Round " << round << "/" << 3 * n_players + 12;
  54.  
  55. if(roundamount == 1){
  56. cout << " (" << roundamount << " card per person)" << endl;
  57. }else{
  58. cout << " (" << roundamount << " cards per person)" << endl;
  59. }
  60.  
  61.  
  62. turn = (round + 3) % 4;
  63.  
  64. bidsum = 0;
  65.  
  66. for(int i = 0; i < n_players; i++){
  67. achieved[i] = 0;
  68. bids[i] = 0;
  69. }
  70.  
  71.  
  72. for(int i = 0; i < n_players; i++){
  73.  
  74. cout << "How many will " << names[turn] << " bid? ";
  75.  
  76. if(i == n_players - 1 && bidsum <= roundamount){
  77. cout << "You are not allowed to bid " << roundamount - bidsum << "! ";
  78. }
  79.  
  80. if(i == n_players - 1 && bidsum > roundamount){
  81. cout << "You can bid any amount! ";
  82. }
  83.  
  84. cin >> bids[turn];
  85.  
  86. bidsum = bidsum + bids[turn];
  87.  
  88. if(i == n_players - 1){
  89. while(bidsum == roundamount){
  90. cout << "Bid a different amount! ";
  91. bidsum = bidsum - bids[turn];
  92. cin >> bids[turn];
  93. bidsum = bidsum + bids[turn];
  94. }
  95. }
  96.  
  97. turn++;
  98. if(turn == n_players)
  99. turn = 0;
  100.  
  101. }
  102.  
  103. while(roundamount > 0){
  104.  
  105.  
  106. cout << endl << endl << endl << "Who took that hand?" << endl;
  107.  
  108. for(int i = 0; i < n_players; i++){
  109. cout << i + 1 << " - " << names[i] << endl;
  110. }
  111.  
  112. cin >> ach;
  113.  
  114. achieved[ach - 1]++;
  115.  
  116.  
  117.  
  118.  
  119.  
  120. roundamount--;
  121.  
  122. }
  123.  
  124. for(int i = 0; i < n_players; i++){
  125. if(bids[i] == achieved[i]){
  126. scores[i] = achieved[i] * 10 + 50 + scores[i];
  127. }else{
  128. scores[i] = 0 - abs(bids[i] - achieved[i]) * 10 + scores[i];
  129. }
  130. }
  131.  
  132.  
  133.  
  134. cout << endl << endl << "-----------------------------------------------------" << endl << "Scores: " << endl;
  135.  
  136. for(int i = 0; i < n_players; i++){
  137. cout << names[i] << " -> " << scores[i] << endl;
  138. }
  139.  
  140.  
  141.  
  142. round++;
  143.  
  144. }
  145.  
  146. int zero = 0;
  147. int maxplayer = -1;
  148. int maxamount = 0;
  149. int equals = 0;
  150.  
  151. cout << endl << endl << "-----------------------------------------------------" << endl << "Final Scores:" << endl;
  152. for(int i = 0; i < n_players; i++){
  153. cout << names[i] << " -> " << scores[i] << endl;
  154. }
  155. cout << "-----------------------------------------------------" << endl;
  156.  
  157. for(int i = 0; i < n_players; i++){
  158. if(scores[i] == 0){
  159. zero++;
  160. cout << names[i] << " won the game by getting 0 points!";
  161. }
  162. }
  163.  
  164. if(zero == 0){
  165. for(int i = 0; i < n_players; i++){
  166. if(scores[i] > maxamount){
  167. maxamount = scores[i];
  168. maxplayer = i;
  169. }
  170. }
  171. for(int i = 0; i < n_players; i++){
  172. if(scores[i] == maxamount){
  173. if(equals >= 1){
  174. cout << " and " << names[i];
  175. }else{
  176. cout << names[i];
  177. }
  178. equals++;
  179. }
  180. }
  181.  
  182. cout << " won the game!";
  183. }
  184.  
  185.  
  186.  
  187.  
  188. return 0;
  189. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement