Advertisement
ZoriaRPG

ZScript: Video Poker v5

May 12th, 2017
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 18.04 KB | None | 0 0
  1. //! Video Poker in ZScript
  2.  
  3. //User Interface
  4. const int VPUI_FONT         = 0; //General UI font and colour.
  5. const int VPUI_HOLD_COLOUR      = 0x01; //White
  6. const int VPUI_HOLD_BG_COLOUR       = 0; //Red, box behind 'HOLD' text.
  7.  
  8. const int VPUI_BACKGROUND_COLOUR = 0x0F; //Should be green.
  9. const int VPUI_FELT_WIDTH = 250;
  10. const int VPUI_FELT_HEIGHT = 170;
  11. const int VPUI_FELT_X = 4;
  12. const int VPUI_FELT_Y = 4;
  13.  
  14. //Card Dimensions and Properties
  15. const int VP_CARD_HOLD_SPACING = 3; //Space between card bottom and 'HOLD' indicator.
  16.  
  17. const int VP_CARD_LAYER = 3; //Layer for drawing card objects to the screen.
  18. const int VP_CARD_WIDTH = 40;
  19. const int VP_CARD_HEIGHT = 60;
  20. const int VP_CARD_SPACING = 8; //Space between cards.
  21. const int VP_CARD_COLOUR = 0x01; //White
  22. const int VP_CARD_SHADOW = 0x0F; //Black
  23. const int VP_CARD_OPACITY = 128; //Opaque
  24. const int VP_CARD_SHADOW_OPACITY = 64; //Trans
  25.  
  26. const int VP_CARD_BASE_X = 10;
  27. const int VP_CARD_BASE_Y = 20;
  28.  
  29. const int VP_CARD_SHADOW_Y_OFFSET = 5;
  30. const int VP_CARD_SHADOW_X_OFFSET = 3;
  31. const int VP_CARD_SCALE = 1;
  32.  
  33. //Card Display (Text)
  34.     //Display of characters over the cards, for 2-10 and A-K-Q-J.
  35. const int VP_CARD_CHAR_X_OFFSET = 18;   //offset from card left/top edges
  36. const int VP_CARD_CHAR_Y_OFFSET = 24;
  37. const int VP_CARD_CHAR_FONT = 1;  //font for glyphs
  38. const int VP_CARD_CHAR_BG_COLOUR = 0; //background colour of glyphs. Normally 0.
  39. const int VP_CARD_CHAR_WIDTH = -1; //Glyph scale: This only works in 2.54+
  40. const int VP_CARD_CHAR_HEIGHT = -1;
  41. const int VP_CARD_CHAR_OPACITY = 128;
  42.  
  43. //Hand Types
  44. const int HT_ROYAL = 9;
  45. const int HT_STRAIGHTFLUSH = 8;
  46. const int HT_FLUSH = 7;
  47. const int HT_STRAIGHT = 6;
  48. const int HT_QUADS = 5;
  49. const int HT_FULLHOUSE = 4;
  50. const int HT_TRIPS = 3;
  51. const int HT_TWOPAIR = 2;
  52. const int HT_ONEPAIR = 1;
  53.  
  54. //Settings
  55. const int MAX_SHUFFLE_FRAMES = 600;
  56.    
  57.    
  58. //String Display
  59. const int BETS_LAYER        = 4;
  60. const int BETS_X        = 5; //Where to display the number of bets on the UI.
  61. const int BETS_Y        = -16;
  62. const int BETS_FONT     = 1;
  63. const int BETS_COLOUR       = 1;
  64. const int BETS_BG_COLOUR    = 0;
  65. const int BETS_FORMAT       = 0;
  66.  
  67. //Suit Colours
  68. const int CARD_SUIT_HEARTS_COLOUR   = 1; //Red
  69. const int CARD_SUIT_DIAMONDS_COLOUR     = 1; //Blue
  70. const int CARD_SUIT_SPADES_COLOUR   = 1; //Black
  71. const int CARD_SUIT_CLUBS_COLOUR    = 1; //Green
  72.  
  73.  
  74. ffc script VideoPoker{
  75.     void run(int min_pair, int win_sfx, int lose_sfx, int holdvcard_sfx, int draw_sfx, int counter){
  76.         //c[5] used for fault timer
  77.        
  78.         int fault; //If the shuffle becomes stuck.
  79.        
  80.         //Numeric Values
  81.         int cards[52]={1,2,3,4,5,6,7,8,9,10,11,12,13,
  82.             1,2,3,4,5,6,7,8,9,10,11,12,13,
  83.             1,2,3,4,5,6,7,8,9,10,11,12,13,
  84.             1,2,3,4,5,6,7,8,9,10,11,12,13,};
  85.         //Suits
  86.         int suits[52]={ 1,1,1,1,1,1,1,1,1,1,1,1,1,
  87.                 2,2,2,2,2,2,2,2,2,2,2,2,2,
  88.                 3,3,3,3,3,3,3,3,3,3,3,3,3,
  89.                 4,4,4,4,4,4,4,4,4,4,4,4,4 };
  90.         //cards dealt.
  91.         bool dealt[52];
  92.         //five first cards, and five under them.
  93.         int deal[10] = { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1};
  94.         int counts[13]; //Pairs, pryles, quads.
  95.         int c[255];
  96.        
  97.         bool held[5]; //The cards that will be held.
  98.         int hand[5]; //The final five chards after dealing.
  99.         bool cardanims[5]; //holds what cards to 'flip'.
  100.         int handbuf[5]; //Buffer to use for initial hand checking, to do preliminary display
  101.         //if hand prior to discarding.
  102.        
  103.         //X and Y of each of the five cards.
  104.         int cardpositions[5] = {
  105.            
  106.             VP_CARD_BASE_X,
  107.             VP_CARD_BASE_X+((VP_CARD+WIDTH+VP_CARD_SPACING)*1),
  108.             VP_CARD_BASE_X+((VP_CARD+WIDTH+VP_CARD_SPACING)*2),
  109.             VP_CARD_BASE_X+((VP_CARD+WIDTH+VP_CARD_SPACING)*3),
  110.             VP_CARD_BASE_X+((VP_CARD+WIDTH+VP_CARD_SPACING)*4)};
  111.            
  112.  
  113.        
  114.         //dealCards();
  115.         fault = nextHand(hand, handbuf, count, held, deal, delt, cardanims, c); //Do all hand arrangements.
  116.        
  117.         if ( fault >= MAX_SHUFFLE_FRAMES ) {
  118.             //do machine error
  119.         }
  120.        
  121.         int handtype = doHandType(handbuf,cards,counts,min_pair); //Establish ther hand type.
  122.         //This needs a buffer so that we do not use 'hand'until we do a discard phase.
  123.        
  124.         //We will check handtype again after doDraw();
  125.        
  126.         bool running = true;
  127.         int s_hand_rank[40]; //String buffer for hand rank.
  128.            
  129.         int coins; //present number of coins.
  130.         int betline; //number of bets
  131.         int s_coind[7]; //string to hold ItoA for coins
  132.         int s_bets[2]; //String to hold ItoA for bets.
  133.            
  134.         c[3] = getHandRankString(s_hand_rank, handtype); //Put the hand rank string into the buffer.
  135.             //c[3] holds the buffer pointer.
  136.        
  137.         bool draw;  
  138.        
  139.        
  140.    
  141.         while(running){
  142.             bool waiting = true;
  143.             //bool betting = true;
  144.            
  145.            
  146.             //DIsplay the cards.
  147.            
  148.             //Display the current hand rank.
  149.            
  150.             //! Keys
  151.             /// 1-5 hold or unhold card 1 to 5
  152.             /// b = set bet amount
  153.             /// d = draw
  154.            
  155.            
  156.             //!
  157.            
  158.             //DISPLAY THE CARDS
  159.             drawCards(cardpositions, hand, cards, suits); //Display the cards
  160.            
  161.             //DISPLAY WHICH ARE HELD
  162.             drawHeld(cardpositions, held);
  163.            
  164.             //! This might be better as an if statement.
  165.             while(waiting) { //Waiting on input
  166.                
  167.                 displayBetline(); //display the present number of bets.
  168.                 drawCards(cardpositions, hand, cards, suits); //Display the cards.
  169.                
  170.                 //Allow player to hold cards.
  171.                
  172.                 if ( KeyPress[KEY_1] ) { if ( holdcard_sfx ) Game->PlaySound(holdcard_sfx); held[0] = !held[0]; cardanims[0] = held[0]; }
  173.                 if ( KeyPress[KEY_2] ) { if ( holdcard_sfx ) Game->PlaySound(holdcard_sfx); held[1] = !held[1]; cardanims[1] = held[1]; }
  174.                 if ( KeyPress[KEY_3] ) { if ( holdcard_sfx ) Game->PlaySound(holdcard_sfx); held[2] = !held[2]; cardanims[2] = held[2]; }
  175.                 if ( KeyPress[KEY_4] ) { if ( holdcard_sfx ) Game->PlaySound(holdcard_sfx); held[3] = !held[3]; cardanims[3] = held[3]; }
  176.                 if ( KeyPress[KEY_5] ) { if ( holdcard_sfx ) Game->PlaySound(holdcard_sfx); held[4] = !held[4]; cardanims[4] = held[4]; }
  177.                
  178.                 if ( KeyPress[KEY_D] ) { if ( draw_sfx) Game->PlaySound(draw_sfx); draw = true; waiting = false;  break; }
  179.                
  180.                 drawHeld(cardpositions, held); //Draw 'HOLD'string at card locations.
  181.                
  182.                 Waitframe();
  183.             }
  184.            
  185.             //Do the draw
  186.            
  187.             //Check what cards are held, and replace un-held cards.
  188.                
  189.             if ( draw ) {
  190.                 draw = false;
  191.                 int display_timer = 300;
  192.                 bool wait_nextgame;
  193.                 doDraw(deal, hand, held); //Update the hand.
  194.                 //Update hand evaluations.
  195.                 handtype = doHandType(hand,cards,counts,min_pair);
  196.                 c[3] = getHandRankString(s_hand_rank, handtype);
  197.                
  198.                 //!do animation
  199.                 //bool cardanims[5]; //holds what cards to 'flip'.
  200.                 //flip animated cards to reveal new cards
  201.                 //clear cardanims[]
  202.                
  203.                 //Show payout.
  204.                
  205.                 int pay = doOdds(betline); //Calculates the payout.
  206.                
  207.                
  208.                 //Make sound.
  209.                
  210.                 if ( pay > 0 && win_sfx ) Game->PlaySound(win_sfx);
  211.                 if ( pay <= 0 && lose_sfx ) Game->PlaySound(lose_sfx);
  212.                
  213.                 //Award the money.
  214.                
  215.                 Game->DCounter[counter] += pay; //Might not want a counter for this.
  216.                
  217.                 while( display_timer-- ) {
  218.                     //Show strings.
  219.                     Waitframe();
  220.                 }
  221.                
  222.                 //Pay out
  223.                
  224.                 wait_nextgame = true;
  225.                
  226.                 //Show Next Game Options
  227.                 while ( wait_nextgame ) {
  228.                     //Allow changing the bet amount, or exiting.
  229.                    
  230.                     if ( KeyPress[KEY_1] ) { betline = 1; setBets(betline, s_bets); }
  231.                     if ( KeyPress[KEY_2] ) { betline = 2; setBets(betline, s_bets); }
  232.                     if ( KeyPress[KEY_3] ) { betline = 3; setBets(betline, s_bets); }
  233.                     if ( KeyPress[KEY_4] ) { betline = 4; setBets(betline, s_bets); }
  234.                     if ( KeyPress[KEY_5] ) { betline = 5; setBets(betline, s_bets); }
  235.                    
  236.                    
  237.                    
  238.                     displayBetline(); //Show the present bet value.
  239.                    
  240.                     //Press key to begin new game.
  241.                     Waitframe();
  242.                 }  
  243.                 fault = nextHand(hand, handbuf, count, held, deal, delt, cardanims, c); //Do all hand arrangements.
  244.        
  245.                 if ( fault >= MAX_SHUFFLE_FRAMES ) {
  246.                     //do machine error
  247.                 }
  248.                
  249.             }
  250.            
  251.        
  252.             Waitframe();
  253.         }
  254.        
  255.                
  256.                
  257.        
  258.     }
  259.    
  260.     //Shuffles deck and populates ten-card hand.
  261.     //The hand is selected from a frame of ten cards from the shuffled pack,
  262.     //with the first entity on that frame randomised, and wrapping around if
  263.     //it reaches the array boundary.
  264.         //! This 10-card frame is an extra randomisation factor to minimise digital RNG favourability.
  265.     bool getCards(int deck, int hand){
  266.         int q = Rand(0,51); //Find the entry point of the frame.
  267.         int w = q+10; int h;
  268.         shuffle(deck);
  269.         for ( ; q < w; q++ ) { //Grab a frame of ten cards at random from the shuffled deck.
  270.             if ( q <= 51 ) { hand[h] = deck[q]; h++; } //Populate the hand.
  271.             if ( q >= 52 ) {
  272.                 q -= 52; h-= 52; //Wrap around
  273.                 hand[h] = deck[q]; h++; //Finish populating the hand.
  274.             }
  275.         }
  276.         return true; //boolean so that we can do:
  277.                 //  bool running = getCards(deck,hand);
  278.     }
  279.        
  280.     void drawCards(int cardpositions, int hand, int cards, int suits){
  281.         int q;
  282.         int markings[13]={'A', '2', '3', '4', '5', '6', '7', '8', '9', 'T', 'J', 'Q', 'K'};
  283.         int suitcolours[4] = { CARD_SUIT_SPADES_COLOUR, CARD_SUIT_HEARTS_COLOUR, CARD_SUIT_DIAMONDS_COLOUR, CARD_SUIT_CLUBS_COLOUR };
  284.         for ( q = 0; q < 5; q++ ) {
  285.             //Shadows
  286.             Screen->Rectangle(VP_CARD_LAYER, cardpositions[q]+VP_CARD_SHADOW_X_OFFSET, VP_CARD_BASE_Y+VP_CARD_SHADOW_Y_OFFSET,
  287.                 cardpositions[q]+VP_CARD_WIDTH+VP_CARD_SHADOW_X_OFFSET, VP_CARD_BASE_Y+VP_CARD_HEIGHT+VP_CARD_SHADOW_Y_OFFSET,
  288.                 VP_CARD_SHADOW, VP_CARD_SCALE, 0, 0, 0, true, VP_CARD_SHADOW_OPACITY);
  289.                 //Card background
  290.             Screen->Rectangle(VP_CARD_LAYER, cardpositions[q], VP_CARD_BASE_Y, VP_CARD_BASE_Y+VP_CARD_WIDTH,
  291.                     cardpositions[q+1]+VP_CARD_HEIGHT, VP_CARD_COLOUR, VP_CARD_SCALE, 0, 0, 0, true, VP_CARD_OPACITY);
  292.            
  293.            
  294.             //Card pips and markers.
  295.            
  296.             //Pips
  297.             //...to add.
  298.            
  299.             //Markers
  300.             Screen->DrawCharacter(VP_CARD_LAYER, cardpositions[q]+VP_CARD_CHAR_X_OFFSET, VP_CARD_BASE_Y+VP_CARD_CHAR_Y_OFFSET,
  301.                 VP_CARD_CHAR_FONT, suitcolours[ suits[ hand[q] ] ], VP_CARD_CHAR_BG_COLOUR, VP_CARD_CHAR_WIDTH,
  302.                 VP_CARD_CHAR_HEIGHT, markings[ cards[ hand[q] ] ], VP_CARD_CHAR_OPACITY);
  303.            
  304.         }
  305.     }
  306.  
  307.     void drawHeld(cardpositions, held){
  308.         int s_hold[]="HOLD";
  309.         for ( int q = 0; q < 10; q+= 2 ){
  310.             //carspositions q = x, q+1 = y
  311.             Screen->DrawString(VP_CARD_LAYER+1, cardpositions[q], cardpositions[q+1]+VP_CARD_HEIGHT+VP_CARD_HOLD_SPACING, VPUI_FONT, VPUI_HOLD_COLOUR,
  312.             VPUI_HOLD_BG_COLOUR, 0, s_hold, OP_OPAQUE);
  313.         }
  314.     }
  315.    
  316.     int nextHand(int hand, int handbuf, int count, bool held, int deal, bool delt, bool cardanims, int c){
  317.        
  318.         c[5] = 0; //fault timer.
  319.        
  320.         //wipe delt
  321.         for ( c[1] = 0; c[1] < 52; c[1]++ ) { delt[ c[1] = false; }
  322.        
  323.         //wipe the pack
  324.         for ( c[1] = 0; c[1] < 10; c[1]++ ) { deal[ c[1] ] = -1; }
  325.            
  326.         //clear the count
  327.         for ( c[1] = 0; c[1] < 13; c[1]++ ) { count[ c[1] ] = 0; }
  328.        
  329.         for ( c[1] = 0; c[1] < 5; c[1]++ ) {
  330.             held[ c[1] ] = false; //clear held cards
  331.             cardanims[ c[1] ] = false; //clear card anims
  332.         }
  333.        
  334.         //! New hand
  335.         //Populagte the cards.
  336.         for ( c[1] = 0; c[1] < 10; c[1]++ ) {
  337.             do {
  338.                 c[0] = Rand(0,51);
  339.                 c[5]++; //fault timer
  340.                
  341.                 //If we take too long to shuffe, raise a fault.
  342.                 if ( c[5] > MAX_SHUFFLE_FRAMES ) { return c[5]; }
  343.                
  344.             } while( dealt[ c[0] ] ); //If the card was dealt, choose another.
  345.             deal[ c[q] ] = c[0]; //Put the card in the deal pack.
  346.             dealt[ c[0] ] = true; //Mark the card dealt.
  347.         }
  348.    
  349.         //Populate the hand wih the first five cards.
  350.         for ( c[1] = 0; c[1] < 5; C[1] ++ ) {
  351.             hand[ c[1] ] = deal[ [c[1] ];
  352.         }
  353.        
  354.        
  355.         for ( c[1] = 0; c[1] < 5; c[1] ++ ) { handbuf[ c[1] ] = hand[ c[1] ]; //Copy to buffer.
  356.        
  357.  
  358.         } //refreshes the game for the next hand, retaining the betting values.
  359.         return 0;
  360.        
  361.        
  362.     }
  363.     int leaveGame() {
  364.         int s_leavegame[]="Äre you sure that you wish to quit?";
  365.         int surety;
  366.         //Are you sure?
  367.        
  368.         if ( KeyPress[KEY_Y] ) surety = 1;
  369.         if ( KeyPress[KEY_N] ) surety = -1;
  370.         return surety;
  371.     }
  372.    
  373.     void setBets(int bets, int s_bets){
  374.         ItoA(bets,s_bets);
  375.     }
  376.        
  377.     void displayBetline(int bets, int s_bets){
  378.         Screen->DrawString(BETS_LAYER, BETS_X, BETS_Y, BETS_FONT, BETS_COLOUR, BETS_BG_COLOUR, BETS_FORMAT,
  379.         s_bets, OP_OPAQUE);
  380.     }
  381.    
  382.     //Fetch a string with the hand rank text into a buffer.
  383.     int getHandRankString(int buf, int handrank){
  384.         int s_nopair[]="High Card";
  385.         int s_onepair[]="One Pair";
  386.         int s_twopair[]="Two Pair";
  387.         int s_trips[]="Three of a Kind";
  388.         int s_straight[]="Straight";
  389.         int s_flush[]="Flush";
  390.         int s_fullhouse[]="Full House";
  391.         int s_quads[]="Four of a Kind";
  392.         int s_straightflush[]="Straight Flush";
  393.         int s_royal[]="Royal Flush";
  394.        
  395.         int strings[10]={   s_nopair, s_onepair, s_twopair, s_trips, s_straight,
  396.                     s_flush, s_fullhouse, s_quads, s_straightflush, s_royal};
  397.        
  398.         int ptr = strings[handrank];
  399.         int sz = SizeOfArray(ptr);
  400.         int q;
  401.         for ( q = 0; q < sz; q++ ) { buf[q] = ptr[q]; }
  402.         buf[q+1] = NULL; //Terminate the string.
  403.         return buf; //Return the pointer to the buffer on success.
  404.     }
  405.    
  406.     int doHandType(int hand, int cards, int counts, int min_pair){
  407.         bool pryle; int pairs; bool onepair; bool twopairs;
  408.         bool quads;  bool flush; bool straight;
  409.         bool broadway; bool fullhouse;
  410.         bool straightflush;
  411.         bool royal;
  412.        
  413.         int hand_type;
  414.  
  415.         flush = isFlush(hand,cards);
  416.         straight = isStraight(hand,cards);
  417.         broadway = isBroadway(hand,cards);
  418.         if ( straight & flush ) straightflush = true;
  419.         if ( broadway && flush ) royal = true;
  420.        
  421.         if ( !flush && !straight && !broadway ) {
  422.             hand_type = handRand(hand, cards, counts);
  423.             if ( hand_type == HT_ONEPAIR && min_pair > 0 ) {
  424.                 if ( !minPair(counts, min_pair) ) return 0;
  425.             }
  426.         }
  427.         if ( royal ) return HT_ROYAL;
  428.         if ( straightflush ) return HT_STRAIGHTFLUSH;
  429.         if ( flush ) return HT_FLUSH;
  430.         if ( straight ) return HT_STRAIGHT;
  431.        
  432.         else return hand_type; //Quads, full house, trips, two pair,
  433.                     //and one pair if ( the pair is > min_pair ) or
  434.                     //there is no min pair.
  435.        
  436.         //if ( quads ) return HT_QUADS;
  437.         //if ( fullhouse ) return HT_FULLHOUSE;
  438.         //if ( pryle ) return HT_TRIPS;
  439.         //if ( twopairs ) return HT_TWOPAIR;
  440.         //if ( onepair ) return HT_ONEPAIR;
  441.         return 0; //Dead hand.
  442.     }
  443.        
  444.     bool isStraight(int hand, int cards){
  445.  
  446.         int sorted[5];
  447.        
  448.         //store numeric values from cards[]
  449.         for ( int q = 0; q < 5; q++ ) {
  450.             sorted[q] = cards[ hand[q] ]; //The numeric values.
  451.         }
  452.  
  453.         //Now, sort the array in a descending manner.
  454.         sortArray(cards, 5);
  455.         //!
  456.            
  457.         bool match;
  458.        
  459.         for ( int q = 0; q < 4; q++ ) { //Not all five.
  460.             if ( sorted[q+1] == sorted[q] -1 ) { match = true };
  461.             else match = false;
  462.         }
  463.         return match;
  464.        
  465.     }
  466.     bool isBroadway(int hand, int cards) { //A-10 Straight
  467.         int sorted[5];
  468.        
  469.         //store numeric values from cards[]
  470.         for ( int q = 0; q < 5; q++ ) {
  471.             sorted[q] = cards[ hand[q] ]; //The numeric values.
  472.         }
  473.  
  474.         //Now, sort the array in a descending manner.
  475.         sortArray(cards, 5);
  476.         //!
  477.            
  478.         bool match;
  479.        
  480.         for ( int q = 0; q < 3; q++ ) { //Check the first four, and read ito the fourth only.
  481.             if ( sorted[q+1] == sorted[q] -1 ) { match = true };
  482.             else match = false;
  483.         }
  484.         if ( sorted[5] != 1 ) { match = false; } //it must be an Ace.
  485.         return match;
  486.        
  487.     }
  488.     bool isFlush(int hand, int suits) {
  489.         int suit;
  490.         bool match;
  491.         suit = suits[ hand[0] ];
  492.         for ( int q = 1; q < 5; q++ ) {
  493.             if ( suits[ hand[q] ] == suit ) { match = true; }
  494.             else match = false;
  495.         }
  496.         return match;
  497.        
  498.     }
  499.    
  500.     //Hand ranks using matched cards.
  501.     int handRank(int counts){
  502.         int pairs;
  503.         bool pryle;
  504.         bool quads;
  505.         bool fullhouse;
  506.         for ( int q = 0; q < 13; q++ ) {
  507.             if ( counts[q] == 4 ) quads = true;
  508.             if ( counts[q] == 3 ) pryle = true;
  509.             if ( counts[q] == 2 ) pairs++;
  510.         }
  511.         if ( pryle && pairs == 1 ) return HT_FULLHOUSE;
  512.         if ( pryle && pairs == 0 ) return HT_TRIPS;
  513.         if ( !pryle && pairs == 2 ) return HT_TWOPAIR;
  514.         if ( !pryle && pairs == 1 ) return HT_ONEPAIR;
  515.         return 0;
  516.     }
  517.    
  518.     //If only one pair, checks that the pair is at at least the minimum type.
  519.     bool minPair(int counts, int highcard){
  520.         int card;
  521.         for ( card = 0; card < 13; card++ ) {
  522.             if ( counts[q] == 2 ) { break; }
  523.         }
  524.         if ( card >= (highcard -1) ) return true;
  525.         return false;
  526.     }
  527.        
  528.     void doOdds(int handtype){
  529.         //int odds[] = {    ODDS_NOPAIR, ODDS_PAIR, ODDS_TWOPAIR, ODDS_TRIPS, ODDS_STRAIGHT, ODDS_FLUSH,
  530.         //      ODDS_FULLHOUSE, ODDS_QUADS, ODDS_STRAIGHTFLUSH, ODDS_ROYAL } ;
  531.        
  532.         int payout[] = { 0, 1, 2, 3, 4, 6, 9, 25, 50, 800 };
  533.         return payout[handtype];
  534.     }
  535.  
  536.     //Draw the cards. Populates the un-held slots in the present hand with the preselected cards.
  537.     void doDraw(int deal, int held, int hand ) {
  538.         for ( int q = 0; q < 5; q++ ) {
  539.             if ( !held[q] ) {
  540.                 hand[q] = deal[q+5];
  541.             }
  542.         }
  543.     }
  544.    
  545.     void sortArray(int array, int size) {
  546.         if (size < 2) {return;}
  547.  
  548.         for (int i = 1; i < size; ++i) {
  549.             int j = i;
  550.             int j_val = array[j];
  551.             while (j > 0) {
  552.                 if (array[j - 1] <= j_val) {break;}
  553.                 int temp = array[j - 1];
  554.                 array[j - 1] = array[j];
  555.                 array[j] = temp;
  556.                 --j;
  557.             }
  558.         }
  559.     }
  560.    
  561.     void doCounts(int cards, int hand, int counts) {
  562.         int pairs = 0;
  563.         for (int i = 0; i < 5; ++i) {
  564.             int rank = cards[hand[i]];
  565.             counts[rank - 1]++;
  566.             //if (counts[rank - 1] % 2 == 0) pairs++;
  567.         }
  568.         //return pairs;
  569.     }
  570.    
  571.     //Shuffles a 52 card array 'deck[]'.
  572.     void shuffle(int deck) {
  573.         int q; int w; int swap;
  574.         for ( q = 51; q > 1; q-- ) {
  575.             x = rand(q+1);
  576.             if ( q == w ) continue;
  577.             swap = deck[q];
  578.             deck[q] = deck[w];
  579.             deck[w] = swap;
  580.         }
  581.     }
  582.    
  583.    
  584. }
  585.  
  586. /*
  587. int countPairs(int cards, int hand) {
  588.  int counts[13];
  589.  int pairs = 0;
  590.  for (int i = 0; i < 5; ++i) {
  591.   int rank = cards[hand[i]];
  592.   counts[rank - 1]++;
  593.   if (counts[rank - 1] % 2 == 0) pairs++;
  594.  }
  595.  return pairs;
  596. }
  597.  
  598.  
  599. void shuffle(){
  600. for (int i = 51; i > 0; --i) {
  601.   int j = Rand(i + 1);
  602.   int x = list[i];
  603.   list[i] = list[j];
  604.   list[j] = x;
  605. }
  606. }
  607.  
  608. //Shuffles a 52 card array 'deck[]'.
  609.     void shuffle(int deck) {
  610.         int q; int w; int swap;
  611.         for ( q = 51; q > 1; q-- ) {
  612.         x = rand(q);
  613.         if ( q == w ) continue;
  614.         swap = deck[q];
  615.         deck[q] = deck[w];
  616.         deck[w] = swap;
  617.     }
  618.    
  619. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement