Advertisement
ZoriaRPG

ZScript: Video Poker v6

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