Advertisement
fatalryuu

Untitled

Dec 5th, 2022
631
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 18.40 KB | None | 0 0
  1. //---------------------------------------------------------------------------
  2.  
  3. #include <vcl.h>
  4. #pragma hdrstop
  5.  
  6. #include "MainUnit.h"
  7. //---------------------------------------------------------------------------
  8. #pragma package(smart_init)
  9. #pragma resource "*.dfm"
  10. #include "WelcomeUnit.h"
  11. #include "BotPreparingUnit.h"
  12. #include "EndUnit.h"
  13. #include "RulesUnit.h"
  14.  
  15. using namespace std;
  16.  
  17. TMainForm *MainForm;
  18. typedef struct {
  19.     int value;
  20.     String suit;
  21. } Card;
  22. const int TABLE_CARDS_Y = 352;
  23. const int FIRST_TABLE_CARD_X = 392;
  24. const int GAP_BETWEEN_TABLE_CARDS = 32;
  25. const int CARD_WIDTH = 200;
  26. const int AMOUNT_OF_CARDS = 52;
  27. const int AMOUNT_OF_SUITS = 4;
  28. const int AMOUNT_OF_COMBINATIONS = 10;
  29. const int DIVIDER_FOR_SMALL_BLIND = 200;
  30. const int AMOUNT_OF_CARDS_FOR_COMBINATION = 7;
  31. const int COMBINATION_LENGTH = 5;
  32. const int MAX_AMOUNT_OF_PLAYERS = 4;
  33. const int AMOUNT_OF_HAND_CARDS = 2;
  34. const int AMOUNT_OF_TABLE_CARDS = 5;
  35. const int DIVIDER_FOR_BIG_BID = 5;
  36. const int DIVIDER_FOR_SMALL_BID = 20;
  37. const int MAX_PERCENTAGE = 100;
  38. const int FIRST_CARD_LEFT = 230;
  39. const int NEW_PAIR_LEFT_ITERATOR = 224;
  40. const int SECOND_CARD_LEFT_ITERATOR = 168;
  41. const int CARDS_TOP = 765;
  42. const int FIRST_NAMELABEL_LEFT = 190;
  43. const int PAIR_OF_CARDS_WIDTH = 368;
  44. const int NAMELABEL_TOP = 722;
  45. const int FISRT_CROWN_LEFT = 336;
  46. const int NEXT_CROWN_LEFT = 392;
  47. const int CROWN_TOP = 655;
  48. const int FONT_SIZE_FOR_NAMELABEL = 22;
  49. const String HIDE_CARDS_STR = "Скрыть карты";
  50. const String SHOW_CARDS_STR = "Показать карты";
  51. const String SUITS[AMOUNT_OF_SUITS] = {"clubs", "diamonds", "hearts", "spades"};
  52. const String BANK_LABEL = "Банк: ";
  53. const String SELECTED_LABEL = "Выбрано: ";
  54. const String CHIPS_LABEL = "Фишки: ";
  55. const String ACTIVE_LABEL = "Активный: ";
  56. const String PREPARING_LABEL = "Готовится: ";
  57. const String WINNER_LABEL = "Победитель: ";
  58. const String COMBINATION_LABEL = "Комбинация: ";
  59. const String CALL_CAPTION = "Кол (";
  60. const String CHECK_CAPTION = "Чек";
  61. const String ALL_IN_CAPTION = "ВА-БАНК";
  62. const String FOLDED_CAPTION = " (Сбросил)";
  63.  
  64. TImage** imagesOfPlayersCards;
  65. TLabel** lablesOfPlayersNames;
  66. int amountOfPlayers;
  67. int currPlayer;
  68. bool isInGame[MAX_AMOUNT_OF_PLAYERS];
  69. Card cardsArr[AMOUNT_OF_CARDS];
  70. Card playersCards[MAX_AMOUNT_OF_PLAYERS][AMOUNT_OF_HAND_CARDS];
  71. Card tableCards[AMOUNT_OF_TABLE_CARDS];
  72. int playersCombinations[MAX_AMOUNT_OF_PLAYERS];
  73. String playersNames[MAX_AMOUNT_OF_PLAYERS];
  74. String winnerName;
  75. String combinationName;
  76. String combinations[AMOUNT_OF_COMBINATIONS];
  77. int highestCards[MAX_AMOUNT_OF_PLAYERS];
  78. int playersChips[MAX_AMOUNT_OF_PLAYERS];
  79. int smallBlind;
  80. int bigBlind;
  81. int amountOfChips;
  82. bool isFirstGame;
  83. bool isFirstTimeOnThisStage;
  84. bool isRaised;
  85. bool isOnceRaised;
  86. bool isShown;
  87. bool isPreFlop;
  88. bool isFlop;
  89. bool isTurn;
  90. bool isRiver;
  91. bool isGameWithBot;
  92. bool isInAllIn;
  93. bool arePlayersCardsShown;
  94. bool isRoundEnded;
  95. int bank;
  96. int bid;
  97. int savedBid;
  98. int odds;
  99. int playerWhoRaised;
  100. int prevPlayerWhoRaised;
  101. //---------------------------------------------------------------------------
  102. __fastcall TMainForm::TMainForm(TComponent* Owner)
  103.     : TForm(Owner) {
  104. }
  105. //------------------------General Methods-----------------------------------
  106.  
  107. void resetLocalVariables() {
  108.     currPlayer = 0;
  109.     for (int i = 0; i < 4; i++)
  110.         isInGame[i] = true;
  111.     smallBlind = 0;
  112.     bigBlind = 1;
  113.     isFirstGame = true;
  114.     isFirstTimeOnThisStage = true;
  115.     isRaised = false;
  116.     isOnceRaised = false;
  117.     isShown = false;
  118.     isPreFlop = true;
  119.     isFlop = false;
  120.     isTurn = false;
  121.     isRiver = false;
  122.     isGameWithBot = false;
  123.     isInAllIn = false;
  124.     arePlayersCardsShown = true;
  125.     isRoundEnded = false;
  126.     bank = 0;
  127.     bid = 0;
  128.     odds = 0;
  129. }
  130.  
  131. void initCombinations() {
  132.     combinations[9] = "ФЛЕШ РОЯЛЬ";
  133.     combinations[8] = "СТРИТ ФЛЕШ";
  134.     combinations[7] = "КАРЕ";
  135.     combinations[6] = "ФУЛЛ ХАУС";
  136.     combinations[5] = "ФЛЕШ";
  137.     combinations[4] = "СТРИТ";
  138.     combinations[3] = "СЕТ";
  139.     combinations[2] = "ДВЕ ПАРЫ";
  140.     combinations[1] = "ПАРА";
  141.     combinations[0] = "СТАРШАЯ КАРТА";
  142. }
  143.  
  144. void createArrayOfCards() {
  145.     String cardName;
  146.     int i = 0;
  147.     int cardValue = 2;
  148.  
  149.     while (i < AMOUNT_OF_CARDS) {
  150.         for (int j = 0; j < AMOUNT_OF_SUITS; j++) {
  151.             Card card;
  152.             cardName = IntToStr(cardValue) + "_of_" + SUITS[j];
  153.             card.value = cardValue;
  154.             card.suit = SUITS[j];
  155.             cardsArr[i] = card;
  156.             i++;
  157.         }
  158.         cardValue++;
  159.     }
  160. }
  161.  
  162. void __fastcall TMainForm::FormCreate(TObject *Sender) {
  163.     Background -> Picture -> LoadFromFile("poker_table.png");
  164.     resetLocalVariables();
  165.     PlaceTableCards();
  166.     initCombinations();
  167.     createArrayOfCards();
  168.     ShowMainMenuButtons();
  169.     HideCards();
  170.     HideButtons();
  171.     HideLabels();
  172. }
  173.  
  174. void TMainForm::PlaceTableCards() {
  175.     PlaceTableCardsY();
  176.     PlaceTableCardsX();
  177. }
  178.  
  179. void TMainForm::PlaceTableCardsY() {
  180.     FirstTableCard -> Top = TABLE_CARDS_Y;
  181.     SecondTableCard -> Top = TABLE_CARDS_Y;
  182.     ThirdTableCard -> Top = TABLE_CARDS_Y;
  183.     FourthTableCard -> Top = TABLE_CARDS_Y;
  184.     FifthTableCard -> Top = TABLE_CARDS_Y;
  185. }
  186.  
  187. void TMainForm::PlaceTableCardsX() {
  188.     int leftForSecond, leftForThird, leftForFourth, leftForFifth;
  189.  
  190.     leftForSecond = FIRST_TABLE_CARD_X + GAP_BETWEEN_TABLE_CARDS + CARD_WIDTH;
  191.     leftForThird = FIRST_TABLE_CARD_X + 2 * (GAP_BETWEEN_TABLE_CARDS + CARD_WIDTH);
  192.     leftForFourth = FIRST_TABLE_CARD_X + 3 * (GAP_BETWEEN_TABLE_CARDS + CARD_WIDTH);
  193.     leftForFifth = FIRST_TABLE_CARD_X + 4 * (GAP_BETWEEN_TABLE_CARDS + CARD_WIDTH);
  194.  
  195.     FirstTableCard -> Left = FIRST_TABLE_CARD_X;
  196.     SecondTableCard -> Left = leftForSecond;
  197.     ThirdTableCard -> Left = leftForThird;
  198.     FourthTableCard -> Left = leftForFourth;
  199.     FifthTableCard -> Left = leftForFifth;
  200. }
  201.  
  202. void TMainForm::HideMainMenuButtons() {
  203.     PlayWithPeopleBtn -> Visible = false;
  204.     PlayWithBotBtn -> Visible = false;
  205.     RulesBtn -> Visible = false;
  206. }
  207.  
  208. void TMainForm::HideCards() {
  209.     FirstTableCard -> Visible = false;
  210.     SecondTableCard -> Visible = false;
  211.     ThirdTableCard -> Visible = false;
  212.     FourthTableCard -> Visible = false;
  213.     FifthTableCard -> Visible = false;
  214.     FirstHandCard -> Visible = false;
  215.     SecondHandCard -> Visible = false;
  216.     FirstBotCard -> Visible = false;
  217.     SecondBotCard -> Visible = false;
  218. }
  219.  
  220. void TMainForm::HideButtons() {
  221.     NextRoundBtn -> Visible = false;
  222.     HideCardsBtn -> Visible = false;
  223.     FoldBtn -> Visible = false;
  224.     CallBtn -> Visible = false;
  225.     RaiseBtn -> Visible = false;
  226. }
  227.  
  228. void TMainForm::HideLabels() {
  229.     ChipsTrackBar -> Visible = false;
  230.     PlayerNameLabel -> Visible = false;
  231.     ChipsLabel -> Visible = false;
  232.     BotChipsLabel -> Visible = false;
  233.     CurrChipsLabel -> Visible = false;
  234.     BankLabel -> Visible = false;
  235.     WinnerLabel -> Visible = false;
  236.     CombinationLabel -> Visible = false;
  237. }
  238.  
  239. void TMainForm::HideBotCards() {
  240.     FirstBotCard -> Visible = false;
  241.     SecondBotCard -> Visible = false;
  242. }
  243.  
  244. void hideCardsAndLabelsFormArrays() {
  245.     for (int i = 0; i < amountOfPlayers * 2; i++) {
  246.         imagesOfPlayersCards[i] -> Visible = false;
  247.         if (i < amountOfPlayers)
  248.             lablesOfPlayersNames[i] -> Visible = false;
  249.     }
  250. }
  251.  
  252. void initFlops() {
  253.     isPreFlop = true;
  254.     isFlop = false;
  255.     isTurn = false;
  256.     isRiver = false;
  257.     isFirstTimeOnThisStage = true;
  258.     isInAllIn = false;
  259. }
  260.  
  261. void generateHandCard(const int player, const int card) {
  262.     int j;
  263.     j = random(AMOUNT_OF_CARDS - 1);
  264.  
  265.     if (cardsArr[j].value != 0) {
  266.         playersCards[player - 1][card - 1] = cardsArr[j];
  267.         cardsArr[j].value = 0;
  268.         cardsArr[j].suit = "";
  269.     } else {
  270.         generateHandCard(player, card);
  271.     }
  272. }
  273.  
  274. String generateTableCard(int n) {
  275.     int j;
  276.     String generatedCard;
  277.     j = random(AMOUNT_OF_CARDS - 1);
  278.     if (cardsArr[j].value != 0) {
  279.         generatedCard = IntToStr(cardsArr[j].value) + "_of_" + cardsArr[j].suit + ".png";
  280.         tableCards[n] = cardsArr[j];
  281.         cardsArr[j].value = 0;
  282.         cardsArr[j].suit = "";
  283.     } else {
  284.         generatedCard = generateTableCard(n);
  285.     }
  286.  
  287.     return generatedCard;
  288. }
  289.  
  290. void TMainForm::ShowHandCards() {
  291.     FirstHandCard -> Visible = true;
  292.     SecondHandCard -> Visible = true;
  293. }
  294.  
  295. void TMainForm::ShowTableCards(const int amount) {
  296.     if (amount == 3) {
  297.         FirstTableCard -> Visible = true;
  298.         SecondTableCard -> Visible = true;
  299.         ThirdTableCard -> Visible = true;
  300.     } else if (amount == 4) {
  301.         FourthTableCard -> Visible = true;
  302.     } else if (amount == 5) {
  303.         FifthTableCard -> Visible = true;
  304.     }
  305. }
  306.  
  307. void TMainForm::ShowButtons() {
  308.     HideCardsBtn -> Visible = true;
  309.     FoldBtn -> Visible = true;
  310.     CallBtn -> Visible = true;
  311.     RaiseBtn -> Visible = true;
  312.     PlayerNameLabel -> Visible = true;
  313. }
  314.  
  315. void TMainForm::ShowLabels() {
  316.     PlayerNameLabel -> Visible = true;
  317.     ChipsLabel -> Visible = true;
  318.     if (isGameWithBot)
  319.         BotChipsLabel -> Visible = true;
  320.     BankLabel -> Visible = true;
  321. }
  322.  
  323. void TMainForm::EnableButtons() {
  324.     FoldBtn -> Enabled = true;
  325.     CallBtn -> Enabled = true;
  326.     RaiseBtn -> Enabled = true;
  327. }
  328.  
  329. void TMainForm::TurnOffButtons() {
  330.     FoldBtn -> Enabled = false;
  331.     CallBtn -> Enabled = false;
  332.     RaiseBtn -> Enabled = false;
  333. }
  334.  
  335. void TMainForm::ShowMainMenuButtons() {
  336.     PlayWithPeopleBtn -> Visible = true;
  337.     PlayWithBotBtn -> Visible = true;
  338.     RulesBtn -> Visible = true;
  339. }
  340.  
  341. void TMainForm::ShowBotCards() {
  342.     FirstBotCard -> Visible = true;
  343.     SecondBotCard -> Visible = true;
  344. }
  345.  
  346. void TMainForm::OpenBotCards() {
  347.     FirstBotCard -> Picture -> LoadFromFile("cards/" + IntToStr(playersCards[1][0].value) + "_of_" + playersCards[1][0].suit + ".png");
  348.     SecondBotCard -> Picture -> LoadFromFile("cards/" + IntToStr(playersCards[1][1].value) + "_of_" + playersCards[1][1].suit + ".png");
  349. }
  350.  
  351. void TMainForm::GenerateTableCards() {
  352.     FirstTableCard -> Picture -> LoadFromFile("cards/" + generateTableCard(0));
  353.     SecondTableCard -> Picture -> LoadFromFile("cards/" + generateTableCard(1));
  354.     ThirdTableCard -> Picture -> LoadFromFile("cards/" + generateTableCard(2));
  355.     FourthTableCard -> Picture -> LoadFromFile("cards/" + generateTableCard(3));
  356.     FifthTableCard -> Picture -> LoadFromFile("cards/" + generateTableCard(4));
  357.  
  358. //  FirstTableCard -> Picture -> LoadFromFile("cards/12_of_diamonds.png");
  359. //  tableCards[0].value = 12;
  360. //  tableCards[0].suit = "diamonds";
  361. //  SecondTableCard -> Picture -> LoadFromFile("cards/3_of_spades.png");
  362. //  tableCards[1].value = 3;
  363. //  tableCards[1].suit = "spades";
  364. //  ThirdTableCard -> Picture -> LoadFromFile("cards/6_of_diamonds.png");
  365. //  tableCards[2].value = 6;
  366. //  tableCards[2].suit = "diamonds";
  367. //  FourthTableCard -> Picture -> LoadFromFile("cards/10_of_diamonds.png");
  368. //  tableCards[3].value = 10;
  369. //  tableCards[3].suit = "diamonds";
  370. //  FifthTableCard -> Picture -> LoadFromFile("cards/14_of_diamonds.png");
  371. //  tableCards[4].value = 14;
  372. //  tableCards[4].suit = "diamonds";
  373. }
  374.  
  375. void TMainForm::GiveCardsToPlayer(const int player) {
  376.     generateHandCard(player, 1);
  377.     generateHandCard(player, 2);
  378.  
  379. //  playersCards[0][0].value = 11;
  380. //  playersCards[0][0].suit = "spades";
  381. //  playersCards[0][1].value = 2;
  382. //  playersCards[0][1].suit = "diamonds";
  383. //  playersCards[1][0].value = 2;
  384. //  playersCards[1][0].suit = "clubs";
  385. //  playersCards[1][1].value = 4;
  386. //  playersCards[1][1].suit = "diamonds";
  387. }
  388.  
  389. void TMainForm::PrepareChips() {
  390.     int minBlind = amountOfChips / DIVIDER_FOR_SMALL_BLIND;
  391.     int maxBlind = minBlind * 2;
  392.  
  393.     if (isFirstGame)
  394.         for (int i = 0; i < amountOfPlayers; i++) {
  395.             playersChips[i] = amountOfChips;
  396.         }
  397.     playersChips[smallBlind] -= minBlind;
  398.     playersChips[bigBlind] -= maxBlind;
  399.     bank = minBlind + maxBlind;
  400.     BankLabel -> Caption = BANK_LABEL + IntToStr(bank);
  401.     ChipsLabel -> Caption = CHIPS_LABEL + IntToStr(playersChips[0]);
  402.     BotChipsLabel -> Caption = CHIPS_LABEL + IntToStr(playersChips[1]);
  403.     ChipsTrackBar -> Min = maxBlind + 1;
  404.     CurrChipsLabel -> Caption = SELECTED_LABEL + IntToStr(maxBlind + 1);
  405.     if (isGameWithBot)
  406.         if (smallBlind == 0) {
  407.             CallBtn -> Caption = CALL_CAPTION + IntToStr(minBlind) + ")";
  408.             bid = minBlind;
  409.         } else {
  410.             CallBtn -> Caption = CHECK_CAPTION;
  411.             bid = minBlind;
  412.             CallForBot();
  413.             bid = 0;
  414.         }
  415.     else {
  416.         if (smallBlind == 0) {
  417.             CallBtn -> Caption = CALL_CAPTION + IntToStr(minBlind) + ")";
  418.             bid = minBlind;
  419.         } else if (bigBlind == 0) {
  420.             CallBtn -> Caption = CHECK_CAPTION;
  421.             bid = 0;
  422.         } else {
  423.             CallBtn -> Caption = CALL_CAPTION + IntToStr(maxBlind) + ")";
  424.             bid = maxBlind;
  425.         }
  426.     }
  427. }
  428.  
  429. void TMainForm::DistributeTableCards() {
  430.     if (!isPreFlop && isFlop)
  431.         ShowTableCards(3);
  432.     else if (!isFlop && isTurn)
  433.         ShowTableCards(4);
  434.     else if (!isTurn && isRiver)
  435.         ShowTableCards(5);
  436. }
  437.  
  438. void __fastcall TMainForm::ChipsTrackBarChange(TObject *Sender) {
  439.     CurrChipsLabel -> Caption = SELECTED_LABEL + IntToStr(ChipsTrackBar -> Position);
  440. }
  441.  
  442. void __fastcall TMainForm::BackToMenuClick(TObject *Sender) {
  443.     if (!isGameWithBot) {
  444.         hideCardsAndLabelsFormArrays();
  445.         CrownImage -> Visible = false;
  446.     }
  447.     FormCreate(Sender);
  448.     HideBotCards();
  449.     EnableButtons();
  450.     BackToMenu -> Visible = false;
  451. }
  452.  
  453. void __fastcall TMainForm::RulesBtnClick(TObject *Sender){
  454.     RulesForm -> ShowModal();
  455. }
  456.  
  457. void TMainForm::PrintWinner() {
  458.     WinnerLabel -> Caption = WINNER_LABEL + winnerName;
  459.     WinnerLabel -> Visible = true;
  460. }
  461.  
  462. void TMainForm::PrintCombination() {
  463.     CombinationLabel -> Caption = COMBINATION_LABEL + combinationName;
  464.     CombinationLabel -> Visible = true;
  465. }
  466.  
  467. void changeBlinds() {
  468.     smallBlind = (smallBlind - 1 == -1) ? amountOfPlayers - 1 : smallBlind - 1;
  469.     bigBlind = (bigBlind - 1 == -1) ? amountOfPlayers - 1 : bigBlind - 1;
  470. }
  471.  
  472. int checkIfWin() {
  473.     int counter = 0;
  474.     int index;
  475.     for (int i = 0; i < amountOfPlayers; i++) {
  476.         if (isInGame[i]) {
  477.             counter++;
  478.             index = i;
  479.         }
  480.     }
  481.     if (counter == 1)
  482.         return index;
  483.     return -1;
  484. }
  485.  
  486. //------------------------Combination Methods-----------------------------------
  487. Card findMaxSuits(const Card cards[], int n) {
  488.     Card maxSuit;
  489.     maxSuit.value = 0;
  490.     int curr = 0;
  491.     for (int i = 0; i < n; i++) {
  492.         String suit = cards[i].suit;
  493.         for (int j = 0; j < n; j++) {
  494.             if (cards[j].suit == suit) {
  495.                 curr++;
  496.             }
  497.         }
  498.         if (curr > maxSuit.value) {
  499.             maxSuit.value = curr;
  500.             maxSuit.suit = suit;
  501.         }
  502.         curr = 0;
  503.     }
  504.  
  505.     return maxSuit;
  506. }
  507.  
  508. bool isRoyalFlush(const Card cards[], int n, int index) {
  509.     int value = cards[0].value;
  510.     Card maxSuit;
  511.     int counter = 0;
  512.  
  513.     maxSuit = findMaxSuits(cards, n);
  514.  
  515.     if (maxSuit.value > 4 && value == 14) {
  516.         value = 15;
  517.         for (int i = 0; i < n; i++) {
  518.             if (cards[i].suit == maxSuit.suit && cards[i].value == value - 1) {
  519.                 counter++;
  520.                 value--;
  521.             }
  522.         }
  523.         if (counter > 4) {
  524.             highestCards[index] = value;
  525.             return true;
  526.         } else
  527.             return false;
  528.     }
  529.  
  530.     return false;
  531. }
  532.  
  533. bool isStraightFlush(const Card cards[], int n, int index) {
  534.     int value = cards[0].value;
  535.     Card maxSuit;
  536.     int counter = 0;
  537.     int k = 0;
  538.  
  539.     maxSuit = findMaxSuits(cards, n);
  540.  
  541.     while (cards[k].suit != maxSuit.suit) {
  542.         value = cards[k + 1].value;
  543.         k++;
  544.     }
  545.  
  546.     if (maxSuit.value > 4) {
  547.         value++;
  548.         for (int i = 0; i < n; i++) {
  549.             if (cards[i].suit == maxSuit.suit && cards[i].value == value - 1) {
  550.                 counter++;
  551.                 value--;
  552.             }
  553.         }
  554.         if (counter > 4) {
  555.             highestCards[index] = value;
  556.             return true;
  557.         } else
  558.             return false;
  559.     }
  560.  
  561.     return false;
  562. }
  563.  
  564. bool isFour(const Card cards[], int n, int index) {
  565.     int counter;
  566.     int i = 0;
  567.     int value = cards[0].value;
  568.     while (counter != 4 && i < n) {
  569.         counter = 0;
  570.         for (int j = 0; j < n; j++) {
  571.             if (cards[j].value == value)
  572.                 counter++;
  573.         }
  574.         i++;
  575.         value = cards[i].value;
  576.     }
  577.  
  578.     if (counter == 4) {
  579.         highestCards[index] = cards[i - 1].value;
  580.         return true;
  581.     }
  582.  
  583.     return false;
  584. }
  585.  
  586. bool isFlush(const Card cards[], int n, int index) {
  587.     Card maxSuit = findMaxSuits(cards, n);
  588.     int counter = 0;
  589.     int i = 0;
  590.     if (maxSuit.value > 4) {
  591.         while (maxSuit.suit != cards[i].suit) {
  592.             i++;
  593.         }
  594.         highestCards[index] = cards[i].value;
  595.         return true;
  596.     }
  597.     return false;
  598. }
  599.  
  600. bool isStraight(const Card cards[], int n, int index) {
  601.     int value;
  602.     int counter = 0;
  603.     int maxN = n - COMBINATION_LENGTH + 1;
  604.  
  605.     for (int i = 0; i < maxN; i++) {
  606.         value = cards[i].value;
  607.         value++;
  608.         for (int j = i; j < n; j++) {
  609.             if (cards[j].value == value - 1) {
  610.                 counter++;
  611.                 value--;
  612.             }
  613.         }
  614.         if (counter > 4) {
  615.             highestCards[index] = value + 4;
  616.             return true;
  617.         }
  618.  
  619.         counter = 0;
  620.     }
  621.  
  622.     return false;
  623. }
  624.  
  625. bool isSet(const Card cards[], int n, int index) {
  626.     int counter;
  627.     int i = 0;
  628.     int value = cards[0].value;
  629.     while (counter != 3 && i < n) {
  630.         counter = 0;
  631.         for (int j = 0; j < n; j++) {
  632.             if (cards[j].value == value)
  633.                 counter++;
  634.         }
  635.         i++;
  636.         value = cards[i].value;
  637.     }
  638.     if (counter == 3) {
  639.         highestCards[index] = cards[i - 1].value;
  640.         return true;
  641.     }
  642.  
  643.     return false;
  644. }
  645.  
  646. bool isPair(const Card cards[], int n, int index) {
  647.     int counter = 0;
  648.     int i = 0;
  649.     int value = cards[0].value;
  650.     while (counter != 2 && i < n) {
  651.         counter = 0;
  652.         for (int j = 0; j < n; j++) {
  653.             if (cards[j].value != 0 && cards[j].value == value)
  654.                 counter++;
  655.         }
  656.         i++;
  657.         value = cards[i].value;
  658.     }
  659.     if (counter == 2) {
  660.         if (highestCards[index] < cards[i - 1].value)
  661.             highestCards[index] = cards[i - 1].value;
  662.         return true;
  663.     }
  664.  
  665.     return false;
  666. }
  667.  
  668. bool isFullHouse(const Card cards[], int n, int index) {
  669.     if (isSet(cards, n, index)) {
  670.         int value = cards[0].value;
  671.         int index = 0;
  672.         bool indexIsFound = false;
  673.         int counter = 0;
  674.         int j = 0;
  675.         while (!indexIsFound) {
  676.             if (cards[j].value == value) {
  677.                 counter++;
  678.                 if (counter == 3) {
  679.                     index = j - counter + 1;
  680.                     indexIsFound = true;
  681.                 }
  682.             } else {
  683.                 counter = 1;
  684.                 value = cards[j].value;
  685.             }
  686.             j++;
  687.         }
  688.         int maxI = index + counter;
  689.         Card newCards[n];
  690.         for (int i = 0; i < n; i++)
  691.             newCards[i] = cards[i];
  692.         for (int i = index; i < maxI; i++)
  693.             newCards[i].value = 0;
  694.         if (isPair(newCards, n, index))
  695.             return true;
  696.     }
  697.  
  698.     return false;
  699. }
  700.  
  701. bool isTwoPair(const Card cards[], int n, int index) {
  702.     if (isPair(cards, n, index)) {
  703.         int value;
  704.         int counter = 0;
  705.         int i = 0;
  706.         while (counter != 2) {
  707.             value = cards[i].value;
  708.             counter = 0;
  709.             for (int j = 0; j < n; j++) {
  710.                 if (cards[j].value == value)
  711.                     counter++;
  712.             }
  713.             i++;
  714.         }
  715.         counter = 0;
  716.         i = 0;
  717.         Card newCards[n];
  718.         for (int j = 0; j < n; j++)
  719.             newCards[j] = cards[j];
  720.         while (counter != 2) {
  721.             if (newCards[i].value == value) {
  722.                 newCards[i].value = 0;
  723.                 counter++;
  724.             }
  725.             i++;
  726.         }
  727.         if (isPair(newCards, n, index))
  728.             return true;
  729.     }
  730.  
  731.     return false;
  732. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement