Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const int HT_ROYAL = 9;
- const int HT_STRAIGHTFLUSH = 8;
- const int HT_FLUSH = 7;
- const int HT_STRAIGHT = 6;
- const int HT_QUADS = 5;
- const int HT_FULLHOUSE = 4;
- const int HT_TRIPS = 3;
- const int HT_TWOPAIR = 2;
- const int HT_ONEPAIR = 1;
- ffc script VideoPoker{
- void run(int min_pair, int win_sfx, int lose_sfx, int holdvcard_sfx, int draw_sfx, int counter){
- //Numeric Values
- int cards[52]={1,2,3,4,5,6,7,8,9,10,11,12,13,
- 1,2,3,4,5,6,7,8,9,10,11,12,13,
- 1,2,3,4,5,6,7,8,9,10,11,12,13,
- 1,2,3,4,5,6,7,8,9,10,11,12,13,};
- //Suits
- int suits[52]={ 1,1,1,1,1,1,1,1,1,1,1,1,1,
- 2,2,2,2,2,2,2,2,2,2,2,2,2,
- 3,3,3,3,3,3,3,3,3,3,3,3,3,
- 4,4,4,4,4,4,4,4,4,4,4,4,4 };
- //cards dealt.
- bool dealt[52];
- //five first cards, and five under them.
- int deal[10] = { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1};
- int counts[13]; //Pairs, pryles, quads.
- int c[255];
- bool held[5]; //The cards that will be held.
- int hand[5]; //The final five chards after dealing.
- bool cardanims[5]; //holds what cards to 'flip'.
- int handbuf[5]; //Buffer to use for initial hand checking, to do preliminary display
- //if hand prior to discarding.
- //dealCards();
- nextHand(hand, handbuf, count, held, deal, delt, cardanims, c); //Do all hand arrangements.
- int handtype = doHandType(handbuf,cards,counts,min_pair); //Establish ther hand type.
- //This needs a buffer so that we do not use 'hand'until we do a discard phase.
- //We will check handtype again after doDraw();
- bool running = true;
- int s_hand_rank[40]; //String buffer for hand rank.
- int coins; //present number of coins.
- int betline; //number of bets
- int s_coind[7]; //string to hold ItoA for coins
- int s_bets[2]; //String to hold ItoA for bets.
- c[3] = getHandRankString(s_hand_rank, handtype); //Put the hand rank string into the buffer.
- //c[3] holds the buffer pointer.
- bool draw;
- while(running){
- bool waiting = true;
- //bool betting = true;
- //DIsplay the cards.
- //Display the current hand rank.
- //! Keys
- /// 1-5 hold or unhold card 1 to 5
- /// b = set bet amount
- /// d = draw
- while(waiting) { //Waitinf on input
- displayBetline();
- //Allow player to hold cards.
- if ( KeyPress[KEY_1] ) { if ( holdcard_sfx ) Game->PlaySound(holdcard_sfx); held[0] = !held[0]; cardanims[0] = held[0]; }
- if ( KeyPress[KEY_2] ) { if ( holdcard_sfx ) Game->PlaySound(holdcard_sfx); held[1] = !held[1]; cardanims[1] = held[1]; }
- if ( KeyPress[KEY_3] ) { if ( holdcard_sfx ) Game->PlaySound(holdcard_sfx); held[2] = !held[2]; cardanims[2] = held[2]; }
- if ( KeyPress[KEY_4] ) { if ( holdcard_sfx ) Game->PlaySound(holdcard_sfx); held[3] = !held[3]; cardanims[3] = held[3]; }
- if ( KeyPress[KEY_5] ) { if ( holdcard_sfx ) Game->PlaySound(holdcard_sfx); held[4] = !held[4]; cardanims[4] = held[4]; }
- if ( KeyPress[KEY_D] ) { if ( draw_sfx) Game->PlaySound(draw_sfx); draw = true; waiting = false; break; }
- Waitframe();
- }
- //Do the draw
- //Check what cards are held, and replace un-held cards.
- if ( draw ) {
- draw = false;
- int display_timer = 300;
- bool wait_nextgame;
- doDraw(deal, hand, held); //Update the hand.
- //Update hand evaluations.
- handtype = doHandType(hand,cards,counts,min_pair);
- c[3] = getHandRankString(s_hand_rank, handtype);
- //!do animation
- //bool cardanims[5]; //holds what cards to 'flip'.
- //flip animated cards to reveal new cards
- //clear cardanims[]
- //Show payout.
- int pay = doOdds(betline); //Calcus gthe payout.
- //Make sound.
- if ( pay > 0 && win_sfx ) Game->PlaySound(win_sfx);
- if ( pay <= 0 && lose_sfx ) Game->PlaySound(lose_sfx);
- //Award the money.
- Game->DCounter[counter] += pay; //Might not want a counter for this.
- while( display_timer-- ) {
- //Show strings.
- Waitframe();
- }
- //Pay out
- wait_nextgame = true;
- //Show Next Game Options
- while ( wait_nextgame ) {
- //Allow changing the bet amount, or exiting.
- if ( KeyPress[KEY_1] ) betline = 1;
- if ( KeyPresss[KEY_2] ) betline = 2;
- if ( KeyPress[KEY_3] ) betline = 3;
- if ( KeyPress[KEY_4] ) betline = 4;
- if ( KeyPress[KEY_5] ) betline = 5;
- displayBetline(); //Show the present bet value.
- //Press key to begin new game.
- Waitframe();
- }
- }
- Waitframe();
- }
- }
- void nextHand(int hand, int handbuf, int count, bool held, int deal, bool delt, bool cardanims, int c){
- //wipe delt
- for ( c[1] = 0; c[1] < 52; c[1]++ ) { delt[ c[1] = false; }
- //wipe the pack
- for ( c[1] = 0; c[1] < 10; c[1]++ ) { deal[ c[1] ] = -1;
- //clear the count
- for ( c[1] = 0; c[1] < 13; c[1]++ ) { count[ c[1] ] = 0; }
- for ( c[1] = 0; c[1] < 5; c[1]++ ) {
- held[ c[1] ] = false; //clear held cards
- cardanims[ c[1] ] = false; //clear card anims
- }
- //! New hand
- //Populagte the cards.
- for ( c[1] = 0; c[1] < 10; c[1]++ ) {
- do {
- c[0] = Rand(0,51);
- } while( dealt[ c[0] ] ); //If the card was dealt, choose another.
- deal[ c[q] ] = c[0]; //Put the card in the deal pack.
- dealt[ c[0] ] = true; //Mark the card dealt.
- }
- //Populate the hand wih the first five cards.
- for ( c[1] = 0; c[1] < 5; C[1] ++ ) {
- hand[ c[1] ] = deal[ [c[1] ];
- }
- for ( c[1] = 0; c[1] < 5; c[1] ++ ) { handbuf[ c[1] ] = hand[ c[1] ]; //Copy to buffer.
- } //refreshes the game for the next hand, retaining the betting values.
- }
- void leaveGame() { } //Exits.
- //Fetch a string with the hand rank text into a buffer.
- int getHandRankString(int buf, int handrank){
- int s_nopair[]="High Card";
- int s_onepair[]="One Pair";
- int s_twopair[]="Two Pair";
- int s_trips[]="Three of a Kind";
- int s_straight[]="Straight";
- int s_flush[]="Flush";
- int s_fullhouse[]="Full House";
- int s_quads[]="Four of a Kind";
- int s_straightflush[]="Straight Flush";
- int s_royal[]="Royal Flush";
- int strings[10]={ s_nopair, s_onepair, s_twopair, s_trips, s_straight,
- s_flush, s_fullhouse, s_quads, s_straightflush, s_royal};
- int ptr = strings[handrank];
- int sz = SizeOfArray(ptr);
- int q;
- for ( q = 0; q < sz; q++ ) { buf[q] = ptr[q]; }
- buf[q+1] = NULL; //Terminate the string.
- return buf; //Return the pointer to the buffer on success.
- }
- int doHandType(int hand, int cards, int counts, int min_pair){
- bool pryle; int pairs; bool onepair; bool twopairs;
- bool quads; bool flush; bool straight;
- bool broadway; bool fullhouse;
- bool straightflush;
- bool royal;
- int hand_type;
- flush = isFlush(hand,cards);
- straight = isStraight(hand,cards);
- broadway = isBroadway(hand,cards);
- if ( straight & flush ) straightflush = true;
- if ( broadway && flush ) royal = true;
- if ( !flush && !straight && !broadway ) {
- hand_type = handRand(hand, cards, counts);
- if ( hand_type == HT_ONEPAIR && min_pair > 0 ) {
- if ( !minPair(counts, min_pair) ) return 0;
- }
- }
- if ( royal ) return HT_ROYAL;
- if ( straightflush ) return HT_STRAIGHTFLUSH;
- if ( flush ) return HT_FLUSH;
- if ( straight ) return HT_STRAIGHT;
- else return hand_type; //Quads, full house, trips, two pair,
- //and one pair if ( the pair is > min_pair ) or
- //there is no min pair.
- //if ( quads ) return HT_QUADS;
- //if ( fullhouse ) return HT_FULLHOUSE;
- //if ( pryle ) return HT_TRIPS;
- //if ( twopairs ) return HT_TWOPAIR;
- //if ( onepair ) return HT_ONEPAIR;
- return 0; //Dead hand.
- }
- bool isStraight(int hand, int cards){
- int sorted[5];
- //store numeric values from cards[]
- for ( int q = 0; q < 5; q++ ) {
- sorted[q] = cards[ hand[q] ]; //The numeric values.
- }
- //Now, sort the array in a descending manner.
- sortArray(cards, 5);
- //!
- bool match;
- for ( int q = 0; q < 4; q++ ) { //Not all five.
- if ( sorted[q+1] == sorted[q] -1 ) { match = true };
- else match = false;
- }
- return match;
- }
- bool isBroadway(int hand, int cards) { //A-10 Straight
- int sorted[5];
- //store numeric values from cards[]
- for ( int q = 0; q < 5; q++ ) {
- sorted[q] = cards[ hand[q] ]; //The numeric values.
- }
- //Now, sort the array in a descending manner.
- sortArray(cards, 5);
- //!
- bool match;
- for ( int q = 0; q < 3; q++ ) { //Check the first four, and read ito the fourth only.
- if ( sorted[q+1] == sorted[q] -1 ) { match = true };
- else match = false;
- }
- if ( sorted[5] != 1 ) { match = false; } //it must be an Ace.
- return match;
- }
- bool isFlush(int hand, int suits) {
- int suit;
- bool match;
- suit = suits[ hand[0] ];
- for ( int q = 1; q < 5; q++ ) {
- if ( suits[ hand[q] ] == suit ) { match = true; }
- else match = false;
- }
- return match;
- }
- //Hand ranks using matched cards.
- int handRank(int counts){
- int pairs;
- bool pryle;
- bool quads;
- bool fullhouse;
- for ( int q = 0; q < 13; q++ ) {
- if ( counts[q] == 4 ) quads = true;
- if ( counts[q] == 3 ) pryle = true;
- if ( counts[q] == 2 ) pairs++;
- }
- if ( pryle && pairs == 1 ) return HT_FULLHOUSE;
- if ( pryle && pairs == 0 ) return HT_TRIPS;
- if ( !pryle && pairs == 2 ) return HT_TWOPAIR;
- if ( !pryle && pairs == 1 ) return HT_ONEPAIR;
- return 0;
- }
- //If only one pair, checks that the pair is at at least the minimum type.
- bool minPair(int counts, int highcard){
- int card;
- for ( card = 0; card < 13; card++ ) {
- if ( counts[q] == 2 ) { break; }
- }
- if ( card >= (highcard -1) ) return true;
- return false;
- }
- void doOdds(int handtype){
- //int odds[] = { ODDS_NOPAIR, ODDS_PAIR, ODDS_TWOPAIR, ODDS_TRIPS, ODDS_STRAIGHT, ODDS_FLUSH,
- // ODDS_FULLHOUSE, ODDS_QUADS, ODDS_STRAIGHTFLUSH, ODDS_ROYAL } ;
- int payout[] = { 0, 1, 2, 3, 4, 6, 9, 25, 50, 800 };
- return payout[handtype];
- }
- //Draw the cards. Populates the un-held slots in the present hand with the preselected cards.
- void doDraw(int deal, int held, int hand ) {
- for ( int q = 0; q < 5; q++ ) {
- if ( !held[q] ) {
- hand[q] = deal[q+5];
- }
- }
- }
- void sortArray(int array, int size) {
- if (size < 2) {return;}
- for (int i = 1; i < size; ++i) {
- int j = i;
- int j_val = array[j];
- while (j > 0) {
- if (array[j - 1] <= j_val) {break;}
- int temp = array[j - 1];
- array[j - 1] = array[j];
- array[j] = temp;
- --j;
- }
- }
- }
- void doCounts(int cards, int hand, int counts) {
- int pairs = 0;
- for (int i = 0; i < 5; ++i) {
- int rank = cards[hand[i]];
- counts[rank - 1]++;
- //if (counts[rank - 1] % 2 == 0) pairs++;
- }
- //return pairs;
- }
- }
- /*
- int countPairs(int cards, int hand) {
- int counts[13];
- int pairs = 0;
- for (int i = 0; i < 5; ++i) {
- int rank = cards[hand[i]];
- counts[rank - 1]++;
- if (counts[rank - 1] % 2 == 0) pairs++;
- }
- return pairs;
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement