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;
- const int MAX_SHUFFLE_FRAMES = 600;
- //String Display
- const int BETS_LAYER = 2;
- const int BETS_X = 5;
- const int BETS_Y = -16;
- const int BETS_FONT = 1;
- const int BETS_COLOUR = 1;
- const int BETS_BG_COLOUR = 0;
- const int BETS_FORMAT = 0;
- //Card Display (Text)
- //Suit Colours
- const int CARD_SUIT_HEARTS_COLOUR = 1;
- const int CARD_SUIT_DIAMONDS_COLOUR = 1;
- const int CARD_SUIT_SPADES_COLOUR = 1;
- const int CARD_SUIT_CLUBS_COLOUR = 1;
- const int VP_CARD_LAYER = 5;
- const int VPUI_FONT = 0; //General UI font and colour.
- const int VPUI_HOLD_COLOUR = 1;
- const int VPUI_HOLD_BG_COLOUR = 0;
- ffc script VideoPoker{
- void run(int min_pair, int win_sfx, int lose_sfx, int holdvcard_sfx, int draw_sfx, int counter){
- //c[5] used for fault timer
- int fault; //If the shuffle becomes stuck.
- //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.
- int cardpositions[10]; //X and Y of each of the five cards.
- //dealCards();
- fault = nextHand(hand, handbuf, count, held, deal, delt, cardanims, c); //Do all hand arrangements.
- if ( fault >= MAX_SHUFFLE_FRAMES ) {
- //do machine error
- }
- 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
- //!
- //DISPLAY THE CARDS
- //DISPLAY WHICH ARE HELD
- //! This might be better as an if statement.
- while(waiting) { //Waitinf on input
- displayBetline(); //display the present number of bets.
- //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; }
- drawHeld(cardpositions, held); //Draw 'HOLD'string at card locations.
- 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); //Calculates the 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; setBets(betline, s_bets); }
- if ( KeyPress[KEY_2] ) { betline = 2; setBets(betline, s_bets); }
- if ( KeyPress[KEY_3] ) { betline = 3; setBets(betline, s_bets); }
- if ( KeyPress[KEY_4] ) { betline = 4; setBets(betline, s_bets); }
- if ( KeyPress[KEY_5] ) { betline = 5; setBets(betline, s_bets); }
- displayBetline(); //Show the present bet value.
- //Press key to begin new game.
- Waitframe();
- }
- fault = nextHand(hand, handbuf, count, held, deal, delt, cardanims, c); //Do all hand arrangements.
- if ( fault >= MAX_SHUFFLE_FRAMES ) {
- //do machine error
- }
- }
- Waitframe();
- }
- }
- void drawHeld(cardpositions, held){
- int s_hold[]="HOLD";
- for ( int q = 0; q < 10; q+= 2 ){
- //carspositions q = x, q+1 = y
- Screen->DrawString(VP_CARD_LAYER+1, cardpositions[q], cardpositions[q+1], VPUI_FONT, VPUI_HOLD_COLOUR,
- VPUI_HOLD_BG_COLOUR, 0, s_hold, OP_OPAQUE);
- }
- }
- int nextHand(int hand, int handbuf, int count, bool held, int deal, bool delt, bool cardanims, int c){
- c[5] = 0; //fault timer.
- //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);
- c[5]++; //fault timer
- //If we take too long to shuffe, raise a fault.
- if ( c[5] > MAX_SHUFFLE_FRAMES ) { return c[5]; }
- } 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.
- return 0;
- }
- int leaveGame() {
- int s_leavegame[]="Äre you sure that you wish to quit?";
- int surety;
- //Are you sure?
- if ( KeyPress[KEY_Y] ) surety = 1;
- if ( KeyPress[KEY_N] ) surety = -1;
- return surety;
- }
- void setBets(int bets, int s_bets){
- ItoA(bets,s_bets);
- }
- void displayBetline(int bets, int s_bets){
- Screen->DrawString(BETS_LAYER, BETS_X, BETS_Y, BETS_FONT, BETS_COLOUR, BETS_BG_COLOUR, BETS_FORMAT,
- s_bets, OP_OPAQUE);
- }
- //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;
- }
- //Shuffles a 52 card array 'deck[]'.
- void shuffle(int deck) {
- int q; int w; int swap;
- for ( q = 51; q > 1; q-- ) {
- x = rand(q+1);
- if ( q == w ) continue;
- swap = deck[q];
- deck[q] = deck[w];
- deck[w] = swap;
- }
- }
- }
- /*
- 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;
- }
- void shuffle(){
- for (int i = 51; i > 0; --i) {
- int j = Rand(i + 1);
- int x = list[i];
- list[i] = list[j];
- list[j] = x;
- }
- }
- //Shuffles a 52 card array 'deck[]'.
- void shuffle(int deck) {
- int q; int w; int swap;
- for ( q = 51; q > 1; q-- ) {
- x = rand(q);
- if ( q == w ) continue;
- swap = deck[q];
- deck[q] = deck[w];
- deck[w] = swap;
- }
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement