Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

My apologies to the universe for this code

By: a guest on May 4th, 2013  |  syntax: C++  |  size: 14.43 KB  |  views: 5,784  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. #include <ctime>
  2. #include <iostream>
  3. using namespace std;
  4. class poker
  5. {
  6. public:
  7. int cards, cards_used[52], face, suit, card_rank[2], pot, real1, human_fold();
  8. int bet_amount, ai, ai2, raise_amount, limit, dan, human_bet, j, i;
  9. char choice, bet_choice, wait, bet_choice2, choice2;
  10. void get_cards(), show_cards(),card_process(), computer_ai(), fold(), raise(), find_out();
  11. void human_bet_process(), dealcards();
  12. int showothercards(), showcards();
  13. };
  14. int my_money = 20000;
  15. /*
  16. ------------------------------------------------------------------------------
  17. --------------------------------------------------------------------------------
  18. */
  19. void game()
  20. {
  21. poker game;
  22. game.dealcards();
  23. game.computer_ai();
  24. }
  25. int main()
  26. {
  27. cout << "remember, y for yes and n for no\n";
  28. system("pause");
  29. system("cls");
  30. game();
  31. }
  32. void poker::dealcards()
  33. {
  34. //seed the random generator
  35. srand(time(NULL));
  36. for(int loop = 0; loop < 1; loop++)
  37. {//loop begining
  38.                        
  39. cards = rand()%52;                      // randomize 52 cards
  40. cards = rand()%52;
  41. cards = rand()%52;
  42. cards = rand()%52;
  43. cards = rand()%52;
  44. while (cards_used[cards] ==1)
  45. {//inner loop begining
  46. while(i > j)
  47. {
  48. cards = rand()%52;
  49. cards = rand()%52;
  50. cards = rand()%52; //randomising the cards even more
  51. cards = rand()%52;     
  52. }        
  53. //inner loop end
  54. }
  55. face = cards%13;
  56. suit = cards/13;
  57. //outer loop end
  58. }
  59. //give player 1 his card       
  60. switch(face)
  61. {
  62. case 0:
  63. card_rank[1] = 1;
  64. break;
  65. case 1:
  66. card_rank[1] = 2;
  67. break;
  68. case 2:
  69. card_rank[1] = 3;
  70. break;
  71. case 3:
  72. card_rank[1] = 4;
  73. break;
  74. case 4:
  75. card_rank[1] = 5;
  76. break;
  77. case 5:
  78. card_rank[1] = 6;
  79. break;
  80. case 6:
  81. card_rank[1] = 7;
  82. break;
  83. case 7:
  84. card_rank[1] = 8;
  85. break;
  86. case 8:
  87. card_rank[1] = 9;
  88. break;
  89. case 9:
  90. card_rank[1] = 10;
  91. break;
  92. case 10:
  93. card_rank[1] = 11;
  94. break;
  95. case 11:
  96. card_rank[1] = 12;
  97. break;
  98. case 12:
  99. card_rank[1] = 13;
  100. break;
  101. }
  102. //------------------------------------------------------------------------------------------------
  103. //player 2 cards
  104.                        
  105. cards = rand()%52;                      // randomize 52 cards
  106. while (cards_used[cards] ==1)
  107. {
  108. cards = rand()%52;              //changing the cards
  109. }
  110. face = cards%13;
  111. suit = cards/13;
  112.        
  113. switch(face)
  114. {
  115. case 0:
  116. card_rank[2] = 2;
  117. cout << "2 \n";
  118. break;
  119. case 1:
  120. card_rank[2] = 3;
  121. cout << "3 \n";
  122. break;
  123. case 2:
  124. card_rank[2] = 4;
  125. cout << "4 \n";
  126. break;
  127. case 3:
  128. card_rank[2] = 5;
  129. cout << "5 \n";
  130. break;
  131. case 4:
  132. card_rank[2] = 6;
  133. cout << "6 \n";
  134. break;
  135. case 5:
  136. card_rank[2] = 7;
  137. cout << "7 \n";
  138. break;
  139. case 6:
  140. card_rank[2] = 8;
  141. cout << "8 \n";
  142. break;
  143. case 7:
  144. card_rank[2] = 9;
  145. cout << "9 \n";
  146. break;
  147. case 8:
  148. card_rank[2] = 10;
  149. cout << "10 \n";
  150. break;
  151. case 9:
  152. card_rank[2] = 11;
  153. cout << "J \n";
  154. break;
  155. case 10:
  156. card_rank[2] = 12;
  157. cout << "Q \n";
  158. break;
  159. case 11:
  160. card_rank[2] = 13;
  161. cout << "K \n";
  162. break;
  163. case 12:
  164. cout << "A \n";
  165. card_rank[2] = 14;
  166. break;
  167. }
  168. real1 = card_rank[2];
  169. }
  170. //this is the longest func,the ai
  171. void poker::computer_ai()
  172. {
  173. ai = rand()%12;
  174. ai2 = rand()%12;
  175. //------------------------------------------------
  176. switch(card_rank[1])
  177. {
  178. //if it sees a 2
  179. case 1:
  180. if(ai == 1)
  181. {
  182. limit = 3000;
  183. if(ai2 == 1)
  184. {
  185. limit = 3000;
  186. raise_amount = 500;
  187. poker::raise();
  188. }
  189. else if(ai2 == 2)
  190. {
  191. limit = 3000;
  192. raise_amount =450;
  193. poker::raise();
  194. }
  195. }
  196. if(ai == 6)
  197. {
  198. limit = 50000;
  199. raise_amount = 4000;
  200. poker::raise();
  201. }
  202. else
  203. {
  204. limit = 3000;
  205. raise_amount = 510;
  206. poker::raise();
  207. }
  208. break;
  209. /*------------------------------------------------------------------------------
  210. --------------------------------------------------------------------------------
  211. */
  212. //if it sees a 3
  213. case 2:
  214. if(ai == 1)
  215. {
  216. limit = 3100;
  217. if(ai2 == 1)
  218. {
  219. limit = 3100;
  220. raise_amount = 400;
  221. poker::raise();
  222. }
  223. else if(ai2 == 2)
  224. {
  225. limit = 4100;
  226. raise_amount = 2000;
  227. poker::raise();
  228. }
  229. }
  230. if(ai == 2)
  231. {
  232. if(ai2 == 1)
  233. {
  234. limit = 3100;
  235. raise_amount = 775;
  236. poker::raise();
  237. }
  238. else if(ai2 == 2)
  239. {
  240. limit = 4200;
  241. raise_amount = 2000;
  242. poker::raise();
  243. }
  244. }
  245. else if(ai == 10)
  246. {
  247. poker::fold();
  248. }
  249. if(ai == 6)
  250. {
  251. limit = 50000;
  252. raise_amount = 4000;
  253. poker::raise();
  254. }
  255. else
  256. {
  257. limit = 4100;
  258. raise_amount = 2100;
  259. poker::raise();
  260. }
  261. //more can come here
  262. break;
  263. /*------------------------------------------------------------------------------
  264. --------------------------------------------------------------------------------
  265. */
  266. //if it sees a 3
  267. case 3:
  268. if(ai == 1)
  269. {
  270. if(ai2 == 1)
  271. {
  272. raise_amount = 1600;
  273. limit = 5000;
  274. poker::raise();
  275. }
  276. if(ai2 == 2)
  277. {
  278. raise_amount = 1500;
  279. limit = 4000;
  280. poker::raise();
  281. }
  282. }
  283. else if(ai >1 && ai <5)
  284. {
  285. if(ai2 == 1)
  286. {
  287. limit = 2100;
  288. raise_amount = 500;
  289. poker::raise();
  290. }
  291. else if(ai2 == 2)
  292. {
  293. limit = 2100;
  294. raise_amount = 700;
  295. poker::raise();
  296. }
  297. }
  298. else if(ai >5 && ai< 8)
  299. {
  300. if(ai2 == 1)
  301. {
  302. limit = 2100;
  303. raise_amount = 700;
  304. poker::raise();
  305. }
  306. else if(ai2 == 2)
  307. {
  308. limit = 2100;
  309. raise_amount = 850;
  310. poker::raise();
  311. }
  312. }
  313. else if(ai == 10)
  314. {
  315. poker::fold();
  316. }
  317. if(ai == 6)
  318. {
  319. limit = 50000;
  320. raise_amount = 4000;
  321. poker::raise();
  322. }
  323. else
  324. {
  325. limit = 2100;
  326. raise_amount = 900;
  327. poker::raise();
  328. }
  329. break;
  330. /*------------------------------------------------------------------------------
  331. --------------------------------------------------------------------------------
  332. */
  333. //if it sees a 4
  334. case 4:
  335. if(ai == 1)
  336. {
  337. if(ai2 == 1)
  338. {
  339. limit = 3000;
  340. raise_amount = 1500;
  341. poker::raise();
  342. }
  343. if(ai2 == 2)
  344. {
  345. limit = 3000;
  346. raise_amount = 1200;
  347. poker::raise();
  348. }
  349. else
  350. {
  351. raise_amount = 700;
  352. limit = 3000;
  353. poker::raise();
  354. }
  355. }
  356. else if(ai >1 && ai <5)
  357. {
  358. if(ai2 == 1)
  359. {
  360. limit = 2100;
  361. raise_amount = 500;
  362. poker::raise();
  363. }
  364. else if(ai2 == 2)
  365. {
  366. limit = 2100;
  367. raise_amount = 700;
  368. poker::raise();
  369. }
  370. else
  371. {
  372. raise_amount = 1000;
  373. limit = 4000;
  374. poker::raise();
  375. }
  376. }
  377. else if(ai >5 && ai< 8)
  378. {
  379. if(ai2 == 1)
  380. {
  381. limit = 2100;
  382. raise_amount = 700;
  383. poker::raise();
  384. }
  385. else if(ai2 == 2)
  386. {
  387. limit = 2000;
  388. raise_amount = 850;
  389. poker::raise();
  390. }
  391. else if(ai2 >2 && ai2<7)
  392. {
  393. raise_amount = 500;
  394. limit = 2000;
  395. poker::raise();
  396. }
  397. else
  398. {
  399. raise_amount = 800;
  400. limit = 5000;
  401. poker::raise();
  402. }
  403. }
  404. else if(ai == 6)
  405. {
  406. limit = 1000000;
  407. raise_amount = 3000;
  408. poker::raise();
  409. }
  410. else if(ai == 10)
  411. {
  412. poker::fold();
  413. }
  414. else
  415. {
  416. limit = 2100;
  417. raise_amount = 900;
  418. poker::raise();
  419. }
  420. break;
  421. /*------------------------------------------------------------------------------
  422. --------------------------------------------------------------------------------
  423. */
  424. //if it sees a 5
  425. case 5:
  426. if(ai == 1)
  427. {
  428. if(ai2 == 1)
  429. {
  430. limit = 3000;
  431. raise_amount = 1500;
  432. poker::raise();
  433. }
  434. if(ai2 == 2)
  435. {
  436. limit = 3000;
  437. raise_amount = 1200;
  438. poker::raise();
  439. }
  440. }
  441. else if(ai >1 && ai <5)
  442. {
  443. if(ai2 = 1)
  444. {
  445. limit = 2100;
  446. raise_amount = 500;
  447. poker::raise();
  448. }
  449. else if(ai2 == 2)
  450. {
  451. limit = 2100;
  452. raise_amount = 700;
  453. poker::raise();
  454. }
  455. }
  456. else if(ai >5 && ai< 8)
  457. {
  458. if(ai2 == 1)
  459. {
  460. limit = 2100;
  461. raise_amount = 700;
  462. poker::raise();
  463. }
  464. else if(ai2 == 2)
  465. {
  466. limit = 2000;
  467. raise_amount = 850;
  468. poker::raise();
  469. }
  470. else
  471. {
  472. raise_amount = 500;
  473. limit = 3000;
  474. poker::raise();
  475. }
  476. }
  477. else if(ai == 6)
  478. {
  479. limit = 50000;
  480. raise_amount = 4000;
  481. poker::raise();
  482. }
  483. else if(ai == 10)
  484. {
  485. poker::fold();
  486. }
  487. else
  488. {
  489. limit = 3000;
  490. raise_amount = 200;
  491. poker::raise();
  492. }
  493. break;
  494. /*------------------------------------------------------------------------------
  495. --------------------------------------------------------------------------------
  496. */
  497. //if it sees a 6
  498. case 6:
  499. if(ai != 6)
  500. {
  501. if(ai2 == 1)
  502. {
  503. limit = 5000;
  504. raise_amount = 1000;
  505. poker::raise();
  506. }
  507. else if(ai2 == 2)
  508. {
  509. limit = 3000;
  510. raise_amount = 500;
  511. poker::raise();
  512. }
  513. }
  514. if(ai <= 4)
  515. {
  516. limit = 3000;
  517. if(ai2 = 1)
  518. {
  519. limit = 2000;
  520. raise_amount = 830;
  521. poker::raise();
  522. }
  523. else if(ai2 == 2)
  524. {
  525. limit = 3000;
  526. raise_amount = 500;
  527. poker::raise();
  528. }
  529. }
  530. else if(ai == 10)
  531. {
  532. poker::fold();
  533. }
  534. else
  535. {
  536. limit = 3000;
  537. raise_amount = 700;
  538. poker::raise();
  539. }
  540. break;
  541. /*------------------------------------------------------------------------------
  542. --------------------------------------------------------------------------------*/
  543. case 7:
  544. if(ai == 1)
  545. {
  546. poker::fold();
  547. }
  548. else if(ai >1 && ai <6)
  549. {
  550. if(ai2 == 1)
  551. {
  552. limit = 2000;
  553. raise_amount = 500;
  554. poker::raise();
  555. }
  556. else if(ai2 == 2)
  557. {
  558. limit = 3000;
  559. raise_amount = 700;
  560. poker::raise();
  561. }
  562. }
  563. if(ai == 10)
  564. {
  565. poker::fold();
  566. }
  567. else if(ai == 11)
  568. {
  569. poker::fold();
  570. }
  571. else if(ai == 6)
  572. {
  573. limit = 2000;
  574. raise_amount = 430;
  575. poker::raise();
  576. }
  577. else
  578. {
  579. raise_amount = 1000;
  580. limit = 5000;
  581. poker::raise();
  582. }
  583. break;
  584. case 8:
  585. if(ai ==6)
  586. {
  587. limit = 50000;
  588. raise_amount = 2000;
  589. poker::raise();
  590. }
  591. else if(ai <6 && ai >0)
  592. {
  593. if(ai2 == 1)
  594. {
  595. raise_amount = 3000;
  596. limit = 10000;
  597. poker::raise();
  598. }
  599. else if(ai2 ==2)
  600. {
  601. limit = 2000;
  602. raise_amount = 500;
  603. poker::raise();
  604. }
  605. else
  606. {
  607. raise_amount = 700;
  608. limit = 4000;
  609. poker::raise();
  610. }
  611. }
  612. else if(ai >6 && ai <9)
  613. {
  614. if(ai2 == 1)
  615. {
  616. raise_amount == 1000;
  617. limit = 3000;
  618. poker::raise();
  619. }
  620. else if(ai2 == 2)
  621. {
  622. limit = 2300;
  623. raise_amount == 650;
  624. poker::raise();
  625. }
  626. }
  627. else
  628. {
  629. poker::fold();
  630. }
  631. break;
  632. //if it sees a nine
  633. case 9:
  634. if(ai> 0 && ai <6)
  635. {
  636. poker::fold();
  637. }
  638. else if(ai == 6)
  639. {
  640. limit = 50000;
  641. raise_amount = 3000;
  642. poker::raise();
  643. }
  644. else if(ai> 7 && ai <10)
  645. {
  646. if(ai2 == 1)
  647. {
  648. limit = 6000;
  649. raise_amount = 1000;
  650. poker::raise();
  651. }
  652. else if(ai2 == 2)
  653. {
  654. limit = 4000;
  655. raise_amount == 700;
  656. poker::raise();
  657. }
  658. }
  659. if(ai> 10 && ai<12)
  660. {
  661. poker::fold();
  662. }
  663. if(ai == 12)
  664. {
  665. limit = 2000;
  666. raise_amount == 600;
  667. poker::raise();
  668. }
  669. else
  670. {
  671. raise_amount = 1000;
  672. limit = 3000;
  673. poker::raise();
  674. }
  675. break;
  676. //if it sees a Q
  677. case 10:
  678. if(ai == 5)
  679. {
  680. limit = 6000;
  681. raise_amount = 1000;
  682. poker::raise();
  683. }
  684. if(ai == 6)
  685. {
  686. limit = 50000;
  687. raise_amount = 2000;
  688. poker::raise();
  689. }
  690. if(ai<5 && ai>0)
  691. {
  692. limit = 4000;
  693. raise_amount = 500;
  694. poker::raise();
  695. }
  696. else
  697. {
  698. raise_amount = 1000;
  699. limit = 5000;
  700. poker::raise();
  701. }
  702. break;
  703. //---------------------------------
  704. //king
  705. case 11:
  706. if(ai == 5)
  707. {
  708. limit = 6000;
  709. raise_amount = 1000;
  710. poker::raise();
  711. }
  712. else if(ai <5)
  713. {
  714. poker::fold();
  715. }
  716. else if(ai >5 && ai !=6)
  717. {
  718. limit = 3000;
  719. raise_amount = 600;
  720. poker::raise();
  721. }
  722. if(ai == 6)
  723. {
  724. limit = 50000;
  725. raise_amount = 2000;
  726. poker::raise();
  727. }
  728. break;
  729. //----------------------------------
  730. case 12:
  731. if(ai == 5)
  732. {
  733. limit = 6000;
  734. raise_amount = 100;
  735. poker::raise();
  736. }
  737. if(ai == 6)
  738. {
  739. limit = 5000;
  740. raise_amount = 200;
  741. poker::raise();
  742. }
  743. else
  744. {
  745. limit = 3000;
  746. raise_amount = 500;
  747. poker::raise();
  748. }
  749. break;
  750. case 13:
  751. if(ai !=6)
  752. {
  753. poker::fold();
  754. }
  755. else
  756. {
  757. if(ai2 == 1)
  758. {
  759. raise_amount = 200;
  760. limit = 600;
  761. poker::raise();
  762. }
  763. else if(ai = 10)
  764. {
  765. poker::fold();
  766. }
  767. if(ai == 6)
  768. {
  769. limit = 5000;
  770. raise_amount = 760;
  771. poker::raise();
  772. }
  773. else if(ai2 == 2)
  774. {
  775. limit = 3000;
  776. raise_amount = 500;
  777. poker::raise();
  778. }
  779. else
  780. {
  781. limit = 2000;
  782. raise_amount = 500;
  783. poker::raise();
  784. }
  785. break;
  786. }
  787. }
  788. cout << "an error in the ai, card: " << card_rank[1] << " ai num1: " << ai << " and ai2: " << ai2;
  789. system("pause");
  790. }
  791. /*
  792. end of the ai, yes, it does exist
  793. now, the easy part, the game process
  794. I think I might cry at the fact no one will ever see that to its fullest extent, :(
  795. *screams* :()
  796. *sleeps*
  797. ;|/|
  798. > | |
  799. ;|\|
  800. ok, it was 12:30 in the morning when I did that
  801. but now that is about 13 hours from that I will get back to it
  802. */
  803. //if the computer raises it goes to this finction
  804. void poker::raise()
  805. {//1
  806. card_rank[1] = card_rank[1] + 1;
  807. if(limit >= raise_amount)
  808. {//the 1st if (if it can raise that much, in case of a glitch in the ai)
  809. //it notifies you that the computer raised
  810. cout << "\n\nthe computer raised " << raise_amount << "\n";
  811. //does the math
  812. pot = pot + raise_amount;
  813. //do you want to meet that?
  814. cout << "\nwould you like to meet the bet of " << raise_amount << " ";;
  815. cin >> bet_choice;
  816. //if yes
  817. if(bet_choice == 'y')
  818. {//2nd if begin (did you meet that)
  819. my_money = my_money - raise_amount;
  820. pot = pot + raise_amount;
  821. cout << "\nwould you like to place a bet? ";
  822. cin >> bet_choice2;
  823. }
  824. //if no, you fold
  825. else
  826. {
  827. poker::fold();
  828. }
  829. //if you wanted to bet (see line 921)
  830. if(bet_choice2 == 'y')
  831. {
  832. poker::human_bet_process();
  833. }
  834. //if you didnt want to (see line 921)
  835. else
  836. {
  837. find_out();
  838. }
  839. }
  840. //if it was over the limit
  841. else
  842. {
  843. cout << "error in the ai (went over cap)";
  844. system("pause");
  845. }//final if end
  846. }//function end
  847. //well, are you going to win?
  848. void poker::find_out()
  849. {
  850. //show both cards
  851. cout << "player 1: ";
  852. poker::showcards();
  853. cout << "player 2: ";
  854. poker::showothercards();
  855. //if you won
  856. if(card_rank[1] > real1)
  857. {
  858. //the processes
  859. my_money = my_money + pot;
  860. cout << "player 1 won \nyou now have " << my_money << "\n";
  861. pot = 0;
  862. system("pause");
  863. system("cls");
  864. game();
  865. }
  866. // if it was a tie
  867. else if(card_rank[1] == real1)
  868. {
  869. cout << "\ntie\n";
  870. my_money = my_money + pot/2;
  871. pot = 0;
  872. system("pause");
  873. system("cls");
  874. pot = 0;
  875. game();
  876. }
  877. //if you lost
  878. else
  879. {
  880. cout << "you lost \n";
  881. system("pause");
  882. system("cls");
  883. pot = 0;
  884. game();
  885. }
  886. }
  887. //if you folded (option in void raise())
  888. int poker::human_fold()
  889. {
  890. cout << "you have folded \n";
  891. cout << "you had ";
  892. poker::showcards();
  893. cout << "\nplay another? ";
  894. cin >> choice;
  895. if(choice == 'y')
  896. {
  897. pot = 0;
  898. system("cls");
  899. main();
  900. }
  901. else
  902. {
  903. return 1;
  904. }
  905. }
  906. //this finction process your bet (see void raise())
  907. void poker::human_bet_process()
  908. {
  909. try
  910. {
  911. cout << "how much?: ";
  912. cin >> human_bet;
  913. pot = pot + human_bet;
  914. my_money = my_money - human_bet;
  915. if(limit >= human_bet)
  916. {
  917. pot = pot + human_bet;
  918. poker::find_out();
  919. }
  920. else
  921. {
  922. poker::fold();
  923. }
  924. }
  925. catch (...)
  926. {
  927. cout << "an error in human fold has occored";
  928. cin >> wait;
  929. }
  930. }
  931. //if the pc folded
  932. void poker::fold()
  933. {
  934. try
  935. {
  936. cout << "\nyou have ";
  937. poker::showcards();
  938. cout << "\nthe computer has folded, you have won\n";
  939. my_money = my_money + pot;
  940. system("pause");
  941. system("cls");
  942. pot = 0;
  943. game();
  944. }
  945. catch (...)
  946. {
  947. cout << "an error has occored in fold";
  948. cin >> wait;
  949. }
  950. }
  951. int poker::showcards()
  952. {
  953. if(card_rank[1] == 11)
  954. cout << "J\n";
  955. //----------------
  956. else if(card_rank[1] == 12)
  957. cout << "Q\n";
  958. //----------------
  959. else if(card_rank[1] == 13)
  960. cout << "K\n";
  961. //----------------
  962. else if(card_rank[1] == 14)
  963. cout << "A\n";
  964. //----------------
  965. else
  966. cout << card_rank[1] << "\n";
  967. }
  968. int poker::showothercards()
  969. {
  970. if(real1 == 11)
  971. {
  972. cout << "J\n";
  973. return 0;
  974. }
  975. //----------------
  976. else if(real1 == 12)
  977. {
  978. cout << "Q\n";
  979. return 0;
  980. }
  981. //----------------
  982. else if(real1 == 13)
  983. {
  984. cout << "Q\n";
  985. return 0;
  986. }
  987. //----------------
  988. else if(real1 == 14)
  989. {
  990. cout << "A\n";
  991. return 0;
  992. }
  993. //----------------
  994. else
  995. cout << real1 << "\n";
  996. }