fork download
  1. #include <iostream>
  2. #include <string>
  3. #include <vector>
  4. #include <iterator>
  5. #include <algorithm>
  6. #include <random>
  7. #include <iomanip>
  8.  
  9. using namespace std;
  10. /*----------------------------------------------------------------------------*/
  11. class Card
  12. {
  13. private:
  14. short numb;
  15. short suit;
  16. public:
  17. Card(short Numb, short Suit)
  18. {
  19. numb = Numb;
  20. suit = Suit;
  21. }
  22. short getNumb() const
  23. { return numb; }
  24. short getSuit() const
  25. { return suit; }
  26. friend ostream& operator << (ostream&, Card&);
  27. };
  28. ostream& operator << (ostream& out, Card& card)
  29. {
  30. out << card.getNumb() << card.getSuit();
  31. return out;
  32. }
  33.  
  34. /*----------------------------------------------------------------------------*/
  35.  
  36. class Player
  37. {
  38. private:
  39. string username;
  40. short numb;
  41. short position;
  42. vector<Card> hand;
  43. double bankroll;
  44. public:
  45. Player(short Numb)
  46. {
  47. numb = Numb;
  48. bankroll = 100.0; //DEBUG
  49. }
  50. Player(short Numb, string Username)
  51. {
  52. numb = Numb;
  53. username = Username;
  54. bankroll = 100.0; //DEBUG
  55. }
  56. void setUsername(string Username)
  57. { username = Username; }
  58. void setNumb(short Numb)
  59. { numb = Numb; }
  60. void setPosition(short Position)
  61. { position = Position; }
  62. void setHand(vector<Card> Hand)
  63. { hand = Hand; }
  64. void setBankroll(double Bankroll)
  65. { bankroll = Bankroll; }
  66. void setCardToPlayersHand(Card card)
  67. { hand.push_back(card); }
  68. string getUsername() const
  69. { return username; }
  70. short getNumb() const
  71. { return numb; }
  72. short getPosition() const
  73. { return position; }
  74. vector<Card> getHand() const
  75. { return hand; }
  76. double getBankroll() const
  77. { return bankroll; }
  78. };
  79.  
  80. /*----------------------------------------------------------------------------*/
  81.  
  82. class Table
  83. {
  84. protected:
  85. vector<Player> players;
  86. public:
  87. Table()
  88. {
  89. for(short i = 1; i <= 9; i++)
  90. {
  91. players.push_back(Player(i));
  92. }
  93. short position = 1;
  94. for(vector<Player> :: iterator it = players.begin(); it < players.end(); it++)
  95. {
  96. (*it).setPosition(position);
  97. position++;
  98. }
  99. }
  100. vector<Player>& getPlayers()
  101. {
  102. return players;
  103. }
  104. /*DEBUG ONLY START*/
  105. void size()
  106. {
  107. cout << players.size();
  108. }
  109. void printingPlayersHands()
  110. {
  111. for(vector<Player> :: iterator itPlayer = players.begin(); itPlayer < players.end(); itPlayer++)
  112. {
  113. vector<Card> hand = (*itPlayer).getHand();
  114. for(vector<Card> :: iterator itCard = hand.begin(); itCard < hand.end(); itCard++)
  115. {
  116. cout << *itCard << '\t';
  117. }
  118. cout << '\n';
  119. }
  120. }
  121. void printingPlayersAll()
  122. {
  123.  
  124. cout << "Usernane |" << " Numb |" << " Position |" << " Bankroll |" << " Card 1 |" << " Card 2 |" << '\n';
  125. cout << "---------|------|----------|----------|--------|--------|" << '\n';
  126. for(vector<Player> :: iterator it = players.begin(); it < players.end(); it++)
  127. {
  128. cout << setw(8) << (*it).getUsername() << " |";
  129. cout << setw(5) << (*it).getNumb() << " |";
  130. cout << setw(9) << (*it).getPosition() << " |";
  131. cout << setw(9) << fixed << setprecision(2) << (*it).getBankroll() << " |";
  132. vector<Card> hand = (*it).getHand();
  133. for(vector<Card> :: iterator itCard = hand.begin(); itCard < hand.end(); itCard++)
  134. {
  135. cout << setw(6) << *itCard << " |";
  136. }
  137. cout << '\n';
  138. }
  139. }
  140. /*DEBUG ONLY END*/
  141. };
  142.  
  143. /*----------------------------------------------------------------------------*/
  144.  
  145. class Hand: public Table
  146. {
  147. private:
  148. vector<Card> cardDeck;
  149. vector<Card> table;
  150. public:
  151. Hand()
  152. {
  153. for(short i = 1; i<= 4; i++)
  154. {
  155. for(short j = 2; j <= 13 + 1; j++)
  156. {
  157. cardDeck.insert(cardDeck.end(), Card(j, i));
  158. }
  159. }
  160. vector<Player> :: iterator it = players.begin();
  161. short temp = (*it).getPosition();
  162. while(it < (players.end() - 1))
  163. {
  164. (*it).setPosition((*(it+1)).getPosition());
  165. it++;
  166. }
  167. (*it).setPosition(temp);
  168. (*it).setBankroll((*it).getBankroll()/2);
  169. }
  170. void dealToPlayers(short count)
  171. {
  172. short i = 0;
  173. while(i < count)
  174. {
  175. for(vector<Player> :: iterator it = getPlayers().begin(); it < getPlayers().end(); it++)
  176. {
  177. (*it).setCardToPlayersHand(cardDeck.front());
  178. cardDeck.erase(cardDeck.begin());
  179. }
  180. i++;
  181. }
  182. printingPlayersHands();
  183. }
  184. void dealToTable(short count)
  185. {
  186. short i = 0;
  187. while( i < count)
  188. {
  189. table.push_back(cardDeck.front());
  190. cardDeck.erase(cardDeck.begin());
  191. i++;
  192. }
  193. printingTable();
  194. }
  195. /*DEBUG ONLY START*/
  196. void printingTable()
  197. {
  198. for(vector<Card> :: iterator it = table.begin(); it < table.end(); it++)
  199. {
  200. cout << *it << '\t';
  201. }
  202. cout << '\n';
  203. }
  204. /*DEBUG ONLY END*/
  205. };
  206.  
  207. int main()
  208. {
  209. Hand hand;
  210. hand.dealToPlayers(2);
  211. cout << '\n' << "OK" << '\n';
  212.  
  213. // here must be bidding
  214.  
  215. hand.dealToTable(3);
  216. cout << '\n' << "OK" << '\n';
  217.  
  218. // here must be bidding
  219.  
  220. hand.dealToTable(1);
  221. cout << '\n' << "OK" << '\n';
  222.  
  223. // here must be bidding
  224.  
  225. hand.dealToTable(1);
  226. cout << '\n' << "OK" << '\n';
  227.  
  228. // here must be bidding
  229. hand.printingPlayersAll();
  230. for(int i = 1; i < 11; i++)
  231. {
  232. Hand hand_;
  233. hand_.dealToPlayers(2);
  234. hand_.dealToTable(3);
  235. hand_.dealToTable(1);
  236. hand_.dealToTable(1);
  237.  
  238. hand.printingPlayersAll();
  239. }
  240.  
  241.  
  242. return 0;
  243. }
Success #stdin #stdout 0s 3280KB
stdin
Standard input is empty
stdout
21	111	
31	121	
41	131	
51	141	
61	22	
71	32	
81	42	
91	52	
101	62	

OK
72	82	92	

OK
72	82	92	102	

OK
72	82	92	102	112	

OK
Usernane | Numb | Position | Bankroll | Card 1 | Card 2 |
---------|------|----------|----------|--------|--------|
         |    1 |        2 |   100.00 |     21 |    111 |
         |    2 |        3 |   100.00 |     31 |    121 |
         |    3 |        4 |   100.00 |     41 |    131 |
         |    4 |        5 |   100.00 |     51 |    141 |
         |    5 |        6 |   100.00 |     61 |     22 |
         |    6 |        7 |   100.00 |     71 |     32 |
         |    7 |        8 |   100.00 |     81 |     42 |
         |    8 |        9 |   100.00 |     91 |     52 |
         |    9 |        1 |    50.00 |    101 |     62 |
21	111	
31	121	
41	131	
51	141	
61	22	
71	32	
81	42	
91	52	
101	62	
72	82	92	
72	82	92	102	
72	82	92	102	112	
Usernane | Numb | Position | Bankroll | Card 1 | Card 2 |
---------|------|----------|----------|--------|--------|
         |    1 |        2 |   100.00 |     21 |    111 |
         |    2 |        3 |   100.00 |     31 |    121 |
         |    3 |        4 |   100.00 |     41 |    131 |
         |    4 |        5 |   100.00 |     51 |    141 |
         |    5 |        6 |   100.00 |     61 |     22 |
         |    6 |        7 |   100.00 |     71 |     32 |
         |    7 |        8 |   100.00 |     81 |     42 |
         |    8 |        9 |   100.00 |     91 |     52 |
         |    9 |        1 |    50.00 |    101 |     62 |
21	111	
31	121	
41	131	
51	141	
61	22	
71	32	
81	42	
91	52	
101	62	
72	82	92	
72	82	92	102	
72	82	92	102	112	
Usernane | Numb | Position | Bankroll | Card 1 | Card 2 |
---------|------|----------|----------|--------|--------|
         |    1 |        2 |   100.00 |     21 |    111 |
         |    2 |        3 |   100.00 |     31 |    121 |
         |    3 |        4 |   100.00 |     41 |    131 |
         |    4 |        5 |   100.00 |     51 |    141 |
         |    5 |        6 |   100.00 |     61 |     22 |
         |    6 |        7 |   100.00 |     71 |     32 |
         |    7 |        8 |   100.00 |     81 |     42 |
         |    8 |        9 |   100.00 |     91 |     52 |
         |    9 |        1 |    50.00 |    101 |     62 |
21	111	
31	121	
41	131	
51	141	
61	22	
71	32	
81	42	
91	52	
101	62	
72	82	92	
72	82	92	102	
72	82	92	102	112	
Usernane | Numb | Position | Bankroll | Card 1 | Card 2 |
---------|------|----------|----------|--------|--------|
         |    1 |        2 |   100.00 |     21 |    111 |
         |    2 |        3 |   100.00 |     31 |    121 |
         |    3 |        4 |   100.00 |     41 |    131 |
         |    4 |        5 |   100.00 |     51 |    141 |
         |    5 |        6 |   100.00 |     61 |     22 |
         |    6 |        7 |   100.00 |     71 |     32 |
         |    7 |        8 |   100.00 |     81 |     42 |
         |    8 |        9 |   100.00 |     91 |     52 |
         |    9 |        1 |    50.00 |    101 |     62 |
21	111	
31	121	
41	131	
51	141	
61	22	
71	32	
81	42	
91	52	
101	62	
72	82	92	
72	82	92	102	
72	82	92	102	112	
Usernane | Numb | Position | Bankroll | Card 1 | Card 2 |
---------|------|----------|----------|--------|--------|
         |    1 |        2 |   100.00 |     21 |    111 |
         |    2 |        3 |   100.00 |     31 |    121 |
         |    3 |        4 |   100.00 |     41 |    131 |
         |    4 |        5 |   100.00 |     51 |    141 |
         |    5 |        6 |   100.00 |     61 |     22 |
         |    6 |        7 |   100.00 |     71 |     32 |
         |    7 |        8 |   100.00 |     81 |     42 |
         |    8 |        9 |   100.00 |     91 |     52 |
         |    9 |        1 |    50.00 |    101 |     62 |
21	111	
31	121	
41	131	
51	141	
61	22	
71	32	
81	42	
91	52	
101	62	
72	82	92	
72	82	92	102	
72	82	92	102	112	
Usernane | Numb | Position | Bankroll | Card 1 | Card 2 |
---------|------|----------|----------|--------|--------|
         |    1 |        2 |   100.00 |     21 |    111 |
         |    2 |        3 |   100.00 |     31 |    121 |
         |    3 |        4 |   100.00 |     41 |    131 |
         |    4 |        5 |   100.00 |     51 |    141 |
         |    5 |        6 |   100.00 |     61 |     22 |
         |    6 |        7 |   100.00 |     71 |     32 |
         |    7 |        8 |   100.00 |     81 |     42 |
         |    8 |        9 |   100.00 |     91 |     52 |
         |    9 |        1 |    50.00 |    101 |     62 |
21	111	
31	121	
41	131	
51	141	
61	22	
71	32	
81	42	
91	52	
101	62	
72	82	92	
72	82	92	102	
72	82	92	102	112	
Usernane | Numb | Position | Bankroll | Card 1 | Card 2 |
---------|------|----------|----------|--------|--------|
         |    1 |        2 |   100.00 |     21 |    111 |
         |    2 |        3 |   100.00 |     31 |    121 |
         |    3 |        4 |   100.00 |     41 |    131 |
         |    4 |        5 |   100.00 |     51 |    141 |
         |    5 |        6 |   100.00 |     61 |     22 |
         |    6 |        7 |   100.00 |     71 |     32 |
         |    7 |        8 |   100.00 |     81 |     42 |
         |    8 |        9 |   100.00 |     91 |     52 |
         |    9 |        1 |    50.00 |    101 |     62 |
21	111	
31	121	
41	131	
51	141	
61	22	
71	32	
81	42	
91	52	
101	62	
72	82	92	
72	82	92	102	
72	82	92	102	112	
Usernane | Numb | Position | Bankroll | Card 1 | Card 2 |
---------|------|----------|----------|--------|--------|
         |    1 |        2 |   100.00 |     21 |    111 |
         |    2 |        3 |   100.00 |     31 |    121 |
         |    3 |        4 |   100.00 |     41 |    131 |
         |    4 |        5 |   100.00 |     51 |    141 |
         |    5 |        6 |   100.00 |     61 |     22 |
         |    6 |        7 |   100.00 |     71 |     32 |
         |    7 |        8 |   100.00 |     81 |     42 |
         |    8 |        9 |   100.00 |     91 |     52 |
         |    9 |        1 |    50.00 |    101 |     62 |
21	111	
31	121	
41	131	
51	141	
61	22	
71	32	
81	42	
91	52	
101	62	
72	82	92	
72	82	92	102	
72	82	92	102	112	
Usernane | Numb | Position | Bankroll | Card 1 | Card 2 |
---------|------|----------|----------|--------|--------|
         |    1 |        2 |   100.00 |     21 |    111 |
         |    2 |        3 |   100.00 |     31 |    121 |
         |    3 |        4 |   100.00 |     41 |    131 |
         |    4 |        5 |   100.00 |     51 |    141 |
         |    5 |        6 |   100.00 |     61 |     22 |
         |    6 |        7 |   100.00 |     71 |     32 |
         |    7 |        8 |   100.00 |     81 |     42 |
         |    8 |        9 |   100.00 |     91 |     52 |
         |    9 |        1 |    50.00 |    101 |     62 |
21	111	
31	121	
41	131	
51	141	
61	22	
71	32	
81	42	
91	52	
101	62	
72	82	92	
72	82	92	102	
72	82	92	102	112	
Usernane | Numb | Position | Bankroll | Card 1 | Card 2 |
---------|------|----------|----------|--------|--------|
         |    1 |        2 |   100.00 |     21 |    111 |
         |    2 |        3 |   100.00 |     31 |    121 |
         |    3 |        4 |   100.00 |     41 |    131 |
         |    4 |        5 |   100.00 |     51 |    141 |
         |    5 |        6 |   100.00 |     61 |     22 |
         |    6 |        7 |   100.00 |     71 |     32 |
         |    7 |        8 |   100.00 |     81 |     42 |
         |    8 |        9 |   100.00 |     91 |     52 |
         |    9 |        1 |    50.00 |    101 |     62 |
21	111	
31	121	
41	131	
51	141	
61	22	
71	32	
81	42	
91	52	
101	62	
72	82	92	
72	82	92	102	
72	82	92	102	112	
Usernane | Numb | Position | Bankroll | Card 1 | Card 2 |
---------|------|----------|----------|--------|--------|
         |    1 |        2 |   100.00 |     21 |    111 |
         |    2 |        3 |   100.00 |     31 |    121 |
         |    3 |        4 |   100.00 |     41 |    131 |
         |    4 |        5 |   100.00 |     51 |    141 |
         |    5 |        6 |   100.00 |     61 |     22 |
         |    6 |        7 |   100.00 |     71 |     32 |
         |    7 |        8 |   100.00 |     81 |     42 |
         |    8 |        9 |   100.00 |     91 |     52 |
         |    9 |        1 |    50.00 |    101 |     62 |