Advertisement
Guest User

Untitled

a guest
Nov 13th, 2019
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 28.11 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <thread>
  4. #include <algorithm>
  5. #include <functional>
  6. #include <array>
  7. #include <vector>
  8.  
  9. using namespace std;
  10.  
  11. struct card {
  12. string palo;
  13. string num;
  14. int value = 0;
  15. };
  16.  
  17. card deck[52];
  18. card player[6];
  19. card player2[6];
  20. card player3[6];
  21. card player4[6];
  22. card pool;
  23. int checked[5] = { 0,0,0,0,0 };
  24. int sameCount = 0;
  25. int pairCount = 0;
  26. int threeCount = 0;
  27. int fourCount = 0;
  28. int numCards = 0;
  29. int numPlayers = 2;
  30. int win = 0;
  31. int currentPlayer = 1;
  32. int winturn = 0;
  33. int playerPoints = 0;
  34. int player2Points = 0;
  35. int player3Points = 0;
  36. int player4Points = 0;
  37. inline int random(int inicio, int limite) { return inicio + rand() % (1 + limite - inicio); }
  38. void shuffle();
  39. void menu();
  40. void givecards();
  41. void playeraction();
  42. void shiftcards();
  43. void drawcard();
  44. void pooldraw();
  45. void showhand(int draw);
  46. int checkwin(int confirm);
  47. void test();
  48. void drawpool();
  49.  
  50. int main()
  51. {
  52. setlocale(LC_ALL, "spanish");
  53. srand(time(NULL));
  54. menu();
  55. shuffle();
  56. givecards();
  57. pooldraw();
  58. playeraction();
  59. }
  60.  
  61. void menu()
  62. {
  63. int option = 0;
  64. numCards = 0;
  65. pool.value = 0;
  66. cout << "GO FISH RECARGADO" << endl;
  67. cout << "(1) 2 jugadores\n(2) 3 jugadores\n(3) 4 jugadores\nIngrese opción: " << endl;
  68. cin >> option;
  69. switch (option) {
  70. case 1:
  71. numPlayers = 2;
  72. break;
  73. case 2:
  74. numPlayers = 3;
  75. break;
  76. case 3:
  77. numPlayers = 4;
  78. break;
  79. default:
  80. cout << "Ingrese una opción válida." << endl;
  81. break;
  82. }
  83. }
  84.  
  85. void shuffle() {
  86. srand(time(NULL));
  87. int dispose[52] = { 0,0,0,0,0,0,0,0,0,0,0,0,0,
  88. 0,0,0,0,0,0,0,0,0,0,0,0,0,
  89. 0,0,0,0,0,0,0,0,0,0,0,0,0,
  90. 0,0,0,0,0,0,0,0,0,0,0,0,0, };
  91.  
  92. for (int i = 0; i < 52; i++) {
  93. deck[i].value = random(1, 13);
  94. dispose[i] = random(1, 4);
  95. if (dispose[i] == 1)
  96. deck[i].palo = "CORAZONES";
  97. else if (dispose[i] == 2)
  98. deck[i].palo = "DIAMANTES";
  99. else if (dispose[i] == 3)
  100. deck[i].palo = "ESPADAS";
  101. else if (dispose[i] == 4)
  102. deck[i].palo = "TRÉBOLES";
  103. if (deck[i].value == 1)
  104. deck[i].num = "AS";
  105. else if (deck[i].value == 2)
  106. deck[i].num = "2";
  107. else if (deck[i].value == 3)
  108. deck[i].num = "3";
  109. else if (deck[i].value == 4)
  110. deck[i].num = "4";
  111. else if (deck[i].value == 5)
  112. deck[i].num = "5";
  113. else if (deck[i].value == 6)
  114. deck[i].num = "6";
  115. else if (deck[i].value == 7)
  116. deck[i].num = "7";
  117. else if (deck[i].value == 8)
  118. deck[i].num = "8";
  119. else if (deck[i].value == 9)
  120. deck[i].num = "9";
  121. else if (deck[i].value == 10)
  122. deck[i].num = "10";
  123. else if (deck[i].value == 11) {
  124. deck[i].num = "JOTA";
  125. }
  126. else if (deck[i].value == 12) {
  127. deck[i].num = "REINA";
  128. }
  129. else if (deck[i].value == 13) {
  130. deck[i].num = "REY";
  131. }
  132. }
  133. }
  134.  
  135. void givecards()
  136. {
  137. for (int i = 0; i < 5; i++) {
  138. player[i].num = deck[i].num;
  139. player[i].palo = deck[i].palo;
  140. player[i].value = deck[i].value;
  141. numCards++;
  142. }
  143. for (int i = 0; i < 5; i++) {
  144. player2[i].num = deck[numCards].num;
  145. player2[i].palo = deck[numCards].palo;
  146. player2[i].value = deck[numCards].value;
  147. numCards++;
  148. }
  149. for (int i = 0; i < 5; i++) {
  150. player3[i].num = deck[numCards].num;
  151. player3[i].palo = deck[numCards].palo;
  152. player3[i].value = deck[numCards].value;
  153. numCards++;
  154. }
  155. for (int i = 0; i < 5; i++) {
  156. player4[i].num = deck[numCards].num;
  157. player4[i].palo = deck[numCards].palo;
  158. player4[i].value = deck[numCards].value;
  159. numCards++;
  160. }
  161. player[5].num = "0";
  162. player[5].palo = "non";
  163. player[5].value = 0;
  164. player2[5].num = "0";
  165. player2[5].palo = "non";
  166. player2[5].value = 0;
  167. player3[5].num = "0";
  168. player3[5].palo = "non";
  169. player3[5].value = 0;
  170. player4[5].num = "0";
  171. player4[5].palo = "non";
  172. player4[5].value = 0;
  173. }
  174.  
  175. void pooldraw() {
  176. pool.value = deck[numCards].value;
  177. pool.num = deck[numCards].num;
  178. pool.palo = deck[numCards].palo;
  179. numCards++;
  180. }
  181.  
  182. void drawpool() {
  183. if (currentPlayer == 1) {
  184. player[5].value = pool.value;
  185. player[5].num = pool.num;
  186. player[5].palo = pool.palo;
  187. }
  188. else if (currentPlayer == 2) {
  189. player2[5].value = pool.value;
  190. player2[5].num = pool.num;
  191. player2[5].palo = pool.palo;
  192. }
  193. else if (currentPlayer == 3) {
  194. player3[5].value = pool.value;
  195. player3[5].num = pool.num;
  196. player3[5].palo = pool.palo;
  197. }
  198. else if (currentPlayer == 4) {
  199. player4[5].value = pool.value;
  200. player4[5].num = pool.num;
  201. player4[5].palo = pool.palo;
  202. }
  203. else {
  204. cout << "DRAW?";
  205. }
  206. numCards++;
  207. }
  208.  
  209. void test() {
  210. player[0].num = "5";
  211. player[0].palo = "CORAZÓN";
  212. player[0].value = 5;
  213. player[1].num = "5";
  214. player[1].palo = "TRÉBOLES";
  215. player[1].value = 5;
  216. player[2].num = "5";
  217. player[2].palo = "DIAMANTES";
  218. player[2].value = 5;
  219. player[3].num = "3";
  220. player[3].palo = "ESPADAS";
  221. player[3].value = 3;
  222. player[4].num = "3";
  223. player[4].palo = "CORAZÓN";
  224. player[4].value = 3;
  225. }
  226.  
  227. void playeraction() {
  228. int option = 0;
  229. win = 0;
  230. winturn = 0;
  231. while (win == 0) {
  232. system("cls");
  233. showhand(0);
  234. cout << "\n(1) Jalar carta de pool\n(2) Jalar carta de mazo\n";
  235. if (checkwin(0) == 1)
  236. cout << "(3) Hacer jugada";
  237. cout << "Ingrese su opción:";
  238. cin >> option;
  239. switch (option) {
  240. case 1:
  241. drawpool();
  242. break;
  243. case 2:
  244. drawcard();
  245. break;
  246. case 3:
  247. checkwin(1);
  248. default:
  249. cout << "Ingrese una opción válida.";
  250. break;
  251. }
  252. system("cls");
  253. showhand(1);
  254. cout << "Ingrese qué carta quiere descartar: ";
  255. cin >> option;
  256. if (currentPlayer == 1) {
  257. switch (option) {
  258. case 1:
  259. pool.value = player[0].value;
  260. pool.num = player[0].num;
  261. pool.palo = player[0].palo;
  262. player[0].value = 0;
  263. break;
  264. case 2:
  265. pool.value = player[1].value;
  266. pool.num = player[1].num;
  267. pool.palo = player[1].palo;
  268. player[1].value = 0;
  269. break;
  270. case 3:
  271. pool.value = player[2].value;
  272. pool.num = player[2].num;
  273. pool.palo = player[2].palo;
  274. player[2].value = 0;
  275. break;
  276. case 4:
  277. pool.value = player[3].value;
  278. pool.num = player[3].num;
  279. pool.palo = player[3].palo;
  280. player[3].value = 0;
  281. break;
  282. case 5:
  283. pool.value = player[4].value;
  284. pool.num = player[4].num;
  285. pool.palo = player[4].palo;
  286. player[4].value = 0;
  287. break;
  288. case 6:
  289. pool.value = player[5].value;
  290. pool.num = player[5].num;
  291. pool.palo = player[5].palo;
  292. player[5].value = 0;
  293. break;
  294. default:
  295. cout << "Ingrese una opción válida.";
  296. break;
  297. }
  298. }
  299. else if (currentPlayer == 2) {
  300. switch (option) {
  301. case 1:
  302. pool.value = player2[0].value;
  303. pool.num = player2[0].num;
  304. pool.palo = player2[0].palo;
  305. player2[0].value = 0;
  306. break;
  307. case 2:
  308. pool.value = player2[1].value;
  309. pool.num = player2[1].num;
  310. pool.palo = player2[1].palo;
  311. player2[1].value = 0;
  312. break;
  313. case 3:
  314. pool.value = player2[2].value;
  315. pool.num = player2[2].num;
  316. pool.palo = player2[2].palo;
  317. player2[2].value = 0;
  318. break;
  319. case 4:
  320. pool.value = player2[3].value;
  321. pool.num = player2[3].num;
  322. pool.palo = player2[3].palo;
  323. player2[3].value = 0;
  324. break;
  325. case 5:
  326. pool.value = player2[4].value;
  327. pool.num = player2[4].num;
  328. pool.palo = player2[4].palo;
  329. player2[4].value = 0;
  330. break;
  331. case 6:
  332. pool.value = player2[5].value;
  333. pool.num = player2[5].num;
  334. pool.palo = player2[5].palo;
  335. player2[5].value = 0;
  336. break;
  337. default:
  338. cout << "Ingrese una opción válida.";
  339. break;
  340. }
  341. }
  342. else if (currentPlayer == 3) {
  343. switch (option) {
  344. case 1:
  345. pool.value = player3[0].value;
  346. pool.num = player3[0].num;
  347. pool.palo = player3[0].palo;
  348. player3[0].value = 0;
  349. break;
  350. case 2:
  351. pool.value = player3[1].value;
  352. pool.num = player3[1].num;
  353. pool.palo = player3[1].palo;
  354. player3[1].value = 0;
  355. break;
  356. case 3:
  357. pool.value = player3[2].value;
  358. pool.num = player3[2].num;
  359. pool.palo = player3[2].palo;
  360. player3[2].value = 0;
  361. break;
  362. case 4:
  363. pool.value = player3[3].value;
  364. pool.num = player3[3].num;
  365. pool.palo = player3[3].palo;
  366. player3[3].value = 0;
  367. break;
  368. case 5:
  369. pool.value = player3[4].value;
  370. pool.num = player3[4].num;
  371. pool.palo = player3[4].palo;
  372. player3[4].value = 0;
  373. break;
  374. case 6:
  375. pool.value = player3[5].value;
  376. pool.num = player3[5].num;
  377. pool.palo = player3[5].palo;
  378. player3[5].value = 0;
  379. break;
  380. default:
  381. cout << "Ingrese una opción válida.";
  382. break;
  383. }
  384. }
  385. else if (currentPlayer == 4) {
  386. switch (option) {
  387. case 1:
  388. pool.value = player4[0].value;
  389. pool.num = player4[0].num;
  390. pool.palo = player4[0].palo;
  391. player4[0].value = 0;
  392. break;
  393. case 2:
  394. pool.value = player4[1].value;
  395. pool.num = player4[1].num;
  396. pool.palo = player4[1].palo;
  397. player4[1].value = 0;
  398. break;
  399. case 3:
  400. pool.value = player4[2].value;
  401. pool.num = player4[2].num;
  402. pool.palo = player4[2].palo;
  403. player4[2].value = 0;
  404. break;
  405. case 4:
  406. pool.value = player4[3].value;
  407. pool.num = player4[3].num;
  408. pool.palo = player4[3].palo;
  409. player4[3].value = 0;
  410. break;
  411. case 5:
  412. pool.value = player4[4].value;
  413. pool.num = player4[4].num;
  414. pool.palo = player4[4].palo;
  415. player4[4].value = 0;
  416. break;
  417. case 6:
  418. pool.value = player4[5].value;
  419. pool.num = player4[5].num;
  420. pool.palo = player4[5].palo;
  421. player4[5].value = 0;
  422. break;
  423. default:
  424. cout << "Ingrese una opción válida.";
  425. break;
  426. }
  427. }
  428. shiftcards();
  429. cout << pairCount << endl;
  430. cout << threeCount << endl;
  431. cout << fourCount << endl;
  432. currentPlayer++;
  433. if (winturn == 1)
  434. winturn++;
  435. else if (winturn > numPlayers)
  436.  
  437. win = 1;
  438. cin >> option;
  439. }
  440. }
  441.  
  442.  
  443. // Winning round
  444. int checkwin(int confirm) {
  445. int num[5] = { 0,0,0,0,0 };
  446. int possiblePlay = 0;
  447. sameCount = 0;
  448. pairCount = 0;
  449. threeCount = 0;
  450. fourCount = 0;
  451. checked[0] = 0;
  452. checked[1] = 0;
  453. checked[2] = 0;
  454. checked[3] = 0;
  455. checked[4] = 0;
  456. if (currentPlayer == 1) {
  457. for (int i = 0; i < 6; i++) {
  458. if (player[0].value == player[i].value && i != 0) {
  459. sameCount++;
  460. if (sameCount == 1) {
  461. pairCount++;
  462. }
  463. else if (sameCount == 2) {
  464. pairCount = 0;
  465. threeCount++;
  466. }
  467. else if (sameCount == 3) {
  468. fourCount++;
  469. pairCount = 0;
  470. threeCount = 0;
  471. }
  472. }
  473. }
  474. sameCount = 0;
  475. checked[0] = player[0].value;
  476. for (int i = 0; i < 6; i++) {
  477. if (player[1].value == player[i].value && i != 1 && player[1].value != checked[0]) {
  478. sameCount++;
  479. if (sameCount == 1) {
  480. pairCount++;
  481. }
  482. else if (sameCount == 2) {
  483. pairCount = 0;
  484. threeCount++;
  485. }
  486. else if (sameCount == 3) {
  487. fourCount++;
  488. pairCount = 0;
  489. threeCount = 0;
  490. }
  491. }
  492. }
  493. sameCount = 0;
  494. checked[1] = player[1].value;
  495. for (int i = 0; i < 6; i++) {
  496. if (player[2].value == player[i].value && i != 2 && player[2].value != checked[1] && player[2].value != checked[0]) {
  497. sameCount++;
  498. if (sameCount == 1) {
  499. pairCount++;
  500. }
  501. else if (sameCount == 2) {
  502. pairCount = 0;
  503. threeCount++;
  504. }
  505. else if (sameCount == 3) {
  506. fourCount++;
  507. pairCount = 0;
  508. threeCount = 0;
  509. }
  510. }
  511. }
  512. sameCount = 0;
  513. checked[2] = player[2].value;
  514. for (int i = 0; i < 6; i++) {
  515. if (player[3].value == player[i].value && i != 3 && player[3].value != checked[2] && player[3].value != checked[1] && player[3].value != checked[0]) {
  516. sameCount++;
  517. if (sameCount == 1) {
  518. pairCount++;
  519. }
  520. else if (sameCount == 2) {
  521. pairCount = 0;
  522. threeCount++;
  523. }
  524. else if (sameCount == 3) {
  525. fourCount++;
  526. pairCount = 0;
  527. threeCount = 0;
  528. }
  529. }
  530. }
  531. sameCount = 0;
  532. checked[3] = player[3].value;
  533. for (int i = 0; i < 6; i++) {
  534. if (player[4].value == player[i].value && i != 4 && player[4].value != checked[3] && player[4].value != checked[2] && player[4].value != checked[1] && player[4].value != checked[0]) {
  535. sameCount++;
  536. if (sameCount == 1) {
  537. pairCount++;
  538. }
  539. else if (sameCount == 2) {
  540. pairCount = 0;
  541. threeCount++;
  542. }
  543. else if (sameCount == 3) {
  544. fourCount++;
  545. pairCount = 0;
  546. threeCount = 0;
  547. }
  548. }
  549. }
  550. sameCount = 0;
  551. checked[4] = player[4].value;
  552. for (int i = 0; i < 6; i++) {
  553. if (player[5].value == player[i].value && i != 5 && player[5].value != checked[4] && player[5].value != checked[3] && player[5].value != checked[2] && player[5].value != checked[1] && player[5].value != checked[0]) {
  554. sameCount++;
  555. if (sameCount == 1) {
  556. pairCount++;
  557. }
  558. else if (sameCount == 2) {
  559. pairCount = 0;
  560. threeCount++;
  561. }
  562. else if (sameCount == 3) {
  563. fourCount++;
  564. pairCount = 0;
  565. threeCount = 0;
  566. }
  567. }
  568. }
  569. if (pairCount == 3) {
  570. win = 1;
  571. }
  572. else if (pairCount == 1 && threeCount == 1) {
  573. winturn = 0;
  574. }
  575. }
  576. else if (currentPlayer == 2) {
  577. for (int i = 0; i < 6; i++) {
  578. if (player2[0].value == player2[i].value && i != 0) {
  579. sameCount++;
  580. if (sameCount == 1) {
  581. pairCount++;
  582. }
  583. else if (sameCount == 2) {
  584. pairCount = 0;
  585. threeCount++;
  586. }
  587. else if (sameCount == 3) {
  588. fourCount++;
  589. pairCount = 0;
  590. threeCount = 0;
  591. }
  592. }
  593. }
  594. sameCount = 0;
  595. checked[0] = player2[0].value;
  596. for (int i = 0; i < 6; i++) {
  597. if (player2[1].value == player2[i].value && i != 1 && player2[1].value != checked[0]) {
  598. sameCount++;
  599. if (sameCount == 1) {
  600. pairCount++;
  601. }
  602. else if (sameCount == 2) {
  603. pairCount = 0;
  604. threeCount++;
  605. }
  606. else if (sameCount == 3) {
  607. fourCount++;
  608. pairCount = 0;
  609. threeCount = 0;
  610. }
  611. }
  612. }
  613. sameCount = 0;
  614. checked[1] = player2[1].value;
  615. for (int i = 0; i < 6; i++) {
  616. if (player2[2].value == player2[i].value && i != 2 && player2[2].value != checked[1] && player2[2].value != checked[0]) {
  617. sameCount++;
  618. if (sameCount == 1) {
  619. pairCount++;
  620. }
  621. else if (sameCount == 2) {
  622. pairCount = 0;
  623. threeCount++;
  624. }
  625. else if (sameCount == 3) {
  626. fourCount++;
  627. pairCount = 0;
  628. threeCount = 0;
  629. }
  630. }
  631. }
  632. sameCount = 0;
  633. checked[2] = player2[2].value;
  634. for (int i = 0; i < 6; i++) {
  635. if (player2[3].value == player2[i].value && i != 3 && player2[3].value != checked[2] && player2[3].value != checked[1] && player2[3].value != checked[0]) {
  636. sameCount++;
  637. if (sameCount == 1) {
  638. pairCount++;
  639. }
  640. else if (sameCount == 2) {
  641. pairCount = 0;
  642. threeCount++;
  643. }
  644. else if (sameCount == 3) {
  645. fourCount++;
  646. pairCount = 0;
  647. threeCount = 0;
  648. }
  649. }
  650. }
  651. sameCount = 0;
  652. checked[3] = player2[3].value;
  653. for (int i = 0; i < 6; i++) {
  654. if (player2[4].value == player2[i].value && i != 4 && player2[4].value != checked[3] && player2[4].value != checked[2] && player2[4].value != checked[1] && player2[4].value != checked[0]) {
  655. sameCount++;
  656. if (sameCount == 1) {
  657. pairCount++;
  658. }
  659. else if (sameCount == 2) {
  660. pairCount = 0;
  661. threeCount++;
  662. }
  663. else if (sameCount == 3) {
  664. fourCount++;
  665. pairCount = 0;
  666. threeCount = 0;
  667. }
  668. }
  669. }
  670. sameCount = 0;
  671. checked[4] = player2[4].value;
  672. for (int i = 0; i < 6; i++) {
  673. if (player2[5].value == player2[i].value && i != 5 && player2[5].value != checked[4] && player2[5].value != checked[3] && player2[5].value != checked[2] && player2[5].value != checked[1] && player2[5].value != checked[0]) {
  674. sameCount++;
  675. if (sameCount == 1) {
  676. pairCount++;
  677. }
  678. else if (sameCount == 2) {
  679. pairCount = 0;
  680. threeCount++;
  681. }
  682. else if (sameCount == 3) {
  683. fourCount++;
  684. pairCount = 0;
  685. threeCount = 0;
  686. }
  687. }
  688. }
  689. if (pairCount == 3) {
  690. win = 1;
  691. }
  692. else if (pairCount == 1 && threeCount == 1) {
  693. winturn = 0;
  694. }
  695. }
  696. else if (currentPlayer == 3) {
  697. for (int i = 0; i < 6; i++) {
  698. if (player3[0].value == player3[i].value && i != 0) {
  699. sameCount++;
  700. if (sameCount == 1) {
  701. pairCount++;
  702. }
  703. else if (sameCount == 2) {
  704. pairCount = 0;
  705. threeCount++;
  706. }
  707. else if (sameCount == 3) {
  708. fourCount++;
  709. pairCount = 0;
  710. threeCount = 0;
  711. }
  712. }
  713. }
  714. sameCount = 0;
  715. checked[0] = player3[0].value;
  716. for (int i = 0; i < 6; i++) {
  717. if (player3[1].value == player3[i].value && i != 1 && player3[1].value != checked[0]) {
  718. sameCount++;
  719. if (sameCount == 1) {
  720. pairCount++;
  721. }
  722. else if (sameCount == 2) {
  723. pairCount = 0;
  724. threeCount++;
  725. }
  726. else if (sameCount == 3) {
  727. fourCount++;
  728. pairCount = 0;
  729. threeCount = 0;
  730. }
  731. }
  732. }
  733. sameCount = 0;
  734. checked[1] = player3[1].value;
  735. for (int i = 0; i < 6; i++) {
  736. if (player3[2].value == player3[i].value && i != 2 && player3[2].value != checked[1] && player3[2].value != checked[0]) {
  737. sameCount++;
  738. if (sameCount == 1) {
  739. pairCount++;
  740. }
  741. else if (sameCount == 2) {
  742. pairCount = 0;
  743. threeCount++;
  744. }
  745. else if (sameCount == 3) {
  746. fourCount++;
  747. pairCount = 0;
  748. threeCount = 0;
  749. }
  750. }
  751. }
  752. sameCount = 0;
  753. checked[2] = player3[2].value;
  754. for (int i = 0; i < 6; i++) {
  755. if (player3[3].value == player3[i].value && i != 3 && player3[3].value != checked[2] && player3[3].value != checked[1] && player3[3].value != checked[0]) {
  756. sameCount++;
  757. if (sameCount == 1) {
  758. pairCount++;
  759. }
  760. else if (sameCount == 2) {
  761. pairCount = 0;
  762. threeCount++;
  763. }
  764. else if (sameCount == 3) {
  765. fourCount++;
  766. pairCount = 0;
  767. threeCount = 0;
  768. }
  769. }
  770. }
  771. sameCount = 0;
  772. checked[3] = player3[3].value;
  773. for (int i = 0; i < 6; i++) {
  774. if (player3[4].value == player3[i].value && i != 4 && player3[4].value != checked[3] && player3[4].value != checked[2] && player3[4].value != checked[1] && player3[4].value != checked[0]) {
  775. sameCount++;
  776. if (sameCount == 1) {
  777. pairCount++;
  778. }
  779. else if (sameCount == 2) {
  780. pairCount = 0;
  781. threeCount++;
  782. }
  783. else if (sameCount == 3) {
  784. fourCount++;
  785. pairCount = 0;
  786. threeCount = 0;
  787. }
  788. }
  789. }
  790. sameCount = 0;
  791. checked[4] = player3[4].value;
  792. for (int i = 0; i < 6; i++) {
  793. if (player3[5].value == player3[i].value && i != 5 && player3[5].value != checked[4] && player3[5].value != checked[3] && player3[5].value != checked[2] && player3[5].value != checked[1] && player3[5].value != checked[0]) {
  794. sameCount++;
  795. if (sameCount == 1) {
  796. pairCount++;
  797. }
  798. else if (sameCount == 2) {
  799. pairCount = 0;
  800. threeCount++;
  801. }
  802. else if (sameCount == 3) {
  803. fourCount++;
  804. pairCount = 0;
  805. threeCount = 0;
  806. }
  807. }
  808. }
  809. }
  810. else if (currentPlayer == 4) {
  811. for (int i = 0; i < 6; i++) {
  812. if (player4[0].value == player4[i].value && i != 0) {
  813. sameCount++;
  814. if (sameCount == 1) {
  815. pairCount++;
  816. }
  817. else if (sameCount == 2) {
  818. pairCount = 0;
  819. threeCount++;
  820. }
  821. else if (sameCount == 3) {
  822. fourCount++;
  823. pairCount = 0;
  824. threeCount = 0;
  825. }
  826. }
  827. }
  828. sameCount = 0;
  829. checked[0] = player4[0].value;
  830. for (int i = 0; i < 6; i++) {
  831.  
  832. if (player4[1].value == player4[i].value && i != 1 && player4[1].value != checked[0]) {
  833. sameCount++;
  834. if (sameCount == 1) {
  835. pairCount++;
  836. }
  837. else if (sameCount == 2) {
  838. pairCount = 0;
  839. threeCount++;
  840. }
  841. else if (sameCount == 3) {
  842. fourCount++;
  843. pairCount = 0;
  844. threeCount = 0;
  845. }
  846. }
  847. }
  848. sameCount = 0;
  849. checked[1] = player4[1].value;
  850. for (int i = 0; i < 6; i++) {
  851. if (player4[2].value == player4[i].value && i != 2 && player4[2].value != checked[1] && player4[2].value != checked[0]) {
  852. sameCount++;
  853. if (sameCount == 1) {
  854. pairCount++;
  855. }
  856. else if (sameCount == 2) {
  857. pairCount = 0;
  858. threeCount++;
  859. }
  860. else if (sameCount == 3) {
  861. fourCount++;
  862. pairCount = 0;
  863. threeCount = 0;
  864. }
  865. }
  866. }
  867. sameCount = 0;
  868. checked[2] = player4[2].value;
  869. for (int i = 0; i < 6; i++) {
  870. if (player4[3].value == player4[i].value && i != 3 && player4[3].value != checked[2] && player4[3].value != checked[1] && player4[3].value != checked[0]) {
  871. sameCount++;
  872. if (sameCount == 1) {
  873. pairCount++;
  874. }
  875. else if (sameCount == 2) {
  876. pairCount = 0;
  877. threeCount++;
  878. }
  879. else if (sameCount == 3) {
  880. fourCount++;
  881. pairCount = 0;
  882. threeCount = 0;
  883. }
  884. }
  885. }
  886. sameCount = 0;
  887. checked[3] = player4[3].value;
  888. for (int i = 0; i < 6; i++) {
  889. if (player4[4].value == player4[i].value && i != 4 && player4[4].value != checked[3] && player4[4].value != checked[2] && player4[4].value != checked[1] && player4[4].value != checked[0]) {
  890. sameCount++;
  891. if (sameCount == 1) {
  892. pairCount++;
  893. }
  894. else if (sameCount == 2) {
  895. pairCount = 0;
  896. threeCount++;
  897. }
  898. else if (sameCount == 3) {
  899. fourCount++;
  900. pairCount = 0;
  901. threeCount = 0;
  902. }
  903. }
  904. }
  905. sameCount = 0;
  906. checked[4] = player4[4].value;
  907. for (int i = 0; i < 6; i++) {
  908. if (player4[5].value == player4[i].value && i != 5 && player4[5].value != checked[4] && player4[5].value != checked[3] && player4[5].value != checked[2] && player4[5].value != checked[1] && player4[5].value != checked[0]) {
  909. sameCount++;
  910. if (sameCount == 1) {
  911. pairCount++;
  912. }
  913. else if (sameCount == 2) {
  914. pairCount = 0;
  915. threeCount++;
  916. }
  917. else if (sameCount == 3) {
  918. fourCount++;
  919. pairCount = 0;
  920. threeCount = 0;
  921. }
  922. }
  923. }
  924. }
  925.  
  926. // Tres pares
  927. if (confirm == 1) {
  928. if (pairCount == 3) {
  929. win = 1;
  930. cout << "EL JUGADOR " << currentPlayer << "HA GANADO.";
  931. }
  932. // 1 tercia y 1 par
  933. else if (pairCount == 1 && threeCount == 1) {
  934. winturn = 1;
  935. }
  936. // Poker
  937. else if (pairCount == 2) {
  938. winturn = 1;
  939. }
  940. // Escalera
  941. if (currentPlayer == 1) {
  942. for (int i = 0; i < 5; i++) {
  943. num[i] = player[i].value;
  944. playerPoints += player[i].value;
  945. }
  946. sort(num, num + 5);
  947. if (num[0] < num[1] < num[2] < num[3] < num[4]) {
  948. winturn = 1;
  949. }
  950. }
  951. else if (currentPlayer == 2) {
  952. for (int i = 0; i < 5; i++) {
  953. num[i] = player2[i].value;
  954. }
  955. sort(num, num + 5);
  956. if (num[0] < num[1] < num[2] < num[3] < num[4]) {
  957. winturn = 1;
  958. }
  959. }
  960. else if (currentPlayer == 3) {
  961. for (int i = 0; i < 5; i++) {
  962. num[i] = player3[i].value;
  963. }
  964. sort(num, num + 5);
  965. if (num[0] < num[1] < num[2] < num[3] < num[4]) {
  966. winturn = 1;
  967. }
  968. }
  969. else if (currentPlayer == 4) {
  970. for (int i = 0; i < 5; i++) {
  971. num[i] = player4[i].value;
  972. }
  973. sort(num, num + 5);
  974. if (num[0] < num[1] < num[2] < num[3] < num[4]) {
  975. winturn = 1;
  976. }
  977. }
  978. }
  979. if ((pairCount == 1 && threeCount == 1) || pairCount == 2 || num[0] < num[1] < num[2] < num[3] < num[4])
  980. possiblePlay = 1;
  981. return possiblePlay;
  982. }
  983.  
  984. void shiftcards() {
  985. if (currentPlayer == 1) {
  986. for (int i = 0; i < 6; i++) {
  987. if (player[i].value == 0) {
  988. player[i].num = player[i + 1].num;
  989. player[i].palo = player[i + 1].palo;
  990. player[i].value = player[i + 1].value;
  991. if (i < 5) {
  992. player[i + 1].num = "0";
  993. player[i + 1].palo = "non";
  994. player[i + 1].value = 0;
  995. }
  996. }
  997. }
  998. player[5].num = "0";
  999. player[5].palo = "non";
  1000. player[5].value = 0;
  1001. }
  1002. else if (currentPlayer == 2) {
  1003. for (int i = 0; i < 6; i++) {
  1004. if (player2[i].value == 0) {
  1005. player2[i].num = player2[i + 1].num;
  1006. player2[i].palo = player2[i + 1].palo;
  1007. player2[i].value = player2[i + 1].value;
  1008. if (i < 5) {
  1009. player2[i + 1].num = "0";
  1010. player2[i + 1].palo = "non";
  1011. player2[i + 1].value = 0;
  1012. }
  1013. }
  1014. }
  1015. player2[5].num = "0";
  1016. player2[5].palo = "non";
  1017. player2[5].value = 0;
  1018. }
  1019. else if (currentPlayer == 3) {
  1020. for (int i = 0; i < 6; i++) {
  1021. if (player3[i].value == 0) {
  1022. player3[i].num = player3[i + 1].num;
  1023. player3[i].palo = player3[i + 1].palo;
  1024. player3[i].value = player3[i + 1].value;
  1025. if (i < 5) {
  1026. player3[i + 1].num = "0";
  1027. player3[i + 1].palo = "non";
  1028. player3[i + 1].value = 0;
  1029. }
  1030. }
  1031. }
  1032. player3[5].num = "0";
  1033. player3[5].palo = "non";
  1034. player3[5].value = 0;
  1035. }
  1036. else if (currentPlayer == 4) {
  1037. for (int i = 0; i < 6; i++) {
  1038. if (player4[i].value == 0) {
  1039. player4[i].num = player4[i + 1].num;
  1040. player4[i].palo = player4[i + 1].palo;
  1041. player4[i].value = player4[i + 1].value;
  1042. if (i < 5) {
  1043. player4[i + 1].num = "0";
  1044. player4[i + 1].palo = "non";
  1045. player4[i + 1].value = 0;
  1046. }
  1047. }
  1048. }
  1049. player4[5].num = "0";
  1050. player4[5].palo = "non";
  1051. player4[5].value = 0;
  1052. }
  1053. }
  1054.  
  1055. void drawcard() {
  1056. if (currentPlayer == 1) {
  1057. player[5].value = deck[numCards].value;
  1058. player[5].num = deck[numCards].num;
  1059. player[5].palo = deck[numCards].palo;
  1060. }
  1061. else if (currentPlayer == 2) {
  1062. player2[5].value = deck[numCards].value;
  1063. player2[5].num = deck[numCards].num;
  1064. player2[5].palo = deck[numCards].palo;
  1065. }
  1066. else if (currentPlayer == 3) {
  1067. player3[5].value = deck[numCards].value;
  1068. player3[5].num = deck[numCards].num;
  1069. player3[5].palo = deck[numCards].palo;
  1070. }
  1071. else if (currentPlayer == 4) {
  1072. player4[5].value = deck[numCards].value;
  1073. player4[5].num = deck[numCards].num;
  1074. player4[5].palo = deck[numCards].palo;
  1075. }
  1076. else {
  1077. cout << "DRAW?";
  1078. }
  1079. numCards++;
  1080. }
  1081.  
  1082. void showhand(int draw) {
  1083.  
  1084. if (currentPlayer > numPlayers) {
  1085. currentPlayer = 1;
  1086. }
  1087. cout << "TURNO JUGADOR " << currentPlayer;
  1088. cout << "\t\t\tCARTAS EN BARAJA: " << 52 - numCards << endl;
  1089. cout << "\t\t\t\tPOOL:" << pool.num << " de " << pool.palo << endl;
  1090. if (winturn == 1)
  1091. cout << "\t\t\t\tÚLTIMO TURNO" << pool.num << " de " << pool.palo << endl;
  1092. if (currentPlayer == 1) {
  1093. if (draw == 1) {
  1094. for (int i = 0; i < 6; i++) {
  1095. if (player[i].value == 0)
  1096. cout << "" << endl;
  1097. else
  1098. cout << "(" << i + 1 << ") " << player[i].num << " de " << player[i].palo << endl;
  1099. }
  1100. }
  1101. else if (draw == 0) {
  1102. for (int i = 0; i < 6; i++) {
  1103. if (player[i].value == 0)
  1104. cout << "" << endl;
  1105. else
  1106. cout << " " << player[i].num << " de " << player[i].palo << endl;
  1107. }
  1108. }
  1109. else
  1110. cout << "xd";
  1111. }
  1112. else if (currentPlayer == 2) {
  1113. if (draw == 1) {
  1114. for (int i = 0; i < 6; i++) {
  1115. if (player2[i].value == 0)
  1116. cout << "";
  1117. else
  1118. cout << "(" << i + 1 << ") " << player2[i].num << " de " << player2[i].palo << endl;
  1119. }
  1120. }
  1121. else if (draw == 0) {
  1122. for (int i = 0; i < 6; i++) {
  1123. if (player2[i].value == 0)
  1124. cout << "";
  1125. else
  1126. cout << " " << player2[i].num << " de " << player2[i].palo << endl;
  1127. }
  1128. }
  1129. else
  1130. cout << "xd";
  1131. }
  1132. else if (currentPlayer == 3) {
  1133. if (draw == 1) {
  1134. for (int i = 0; i < 6; i++) {
  1135. if (player3[i].value == 0)
  1136. cout << "" << endl;
  1137. else
  1138. cout << "(" << i + 1 << ") " << player3[i].num << " de " << player3[i].palo << endl;
  1139. }
  1140. }
  1141. else if (draw == 0) {
  1142. for (int i = 0; i < 6; i++) {
  1143. if (player3[i].value == 0)
  1144. cout << "" << endl;
  1145. else
  1146. cout << " " << player3[i].num << " de " << player3[i].palo << endl;
  1147. }
  1148. }
  1149. else
  1150. cout << "xd";
  1151. }
  1152. else if (currentPlayer == 4) {
  1153. if (draw == 1) {
  1154. for (int i = 0; i < 6; i++) {
  1155. if (player4[i].value == 0)
  1156. cout << "";
  1157. else
  1158. cout << "(" << i + 1 << ") " << player4[i].num << " de " << player4[i].palo << endl;
  1159. }
  1160. }
  1161. else if (draw == 0) {
  1162. for (int i = 0; i < 6; i++) {
  1163. if (player4[i].value == 0)
  1164. cout << "";
  1165. else
  1166. cout << " " << player4[i].num << " de " << player4[i].palo << endl;
  1167. }
  1168. }
  1169. else
  1170. cout << "xd";
  1171. }
  1172. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement