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(){
- //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];
- //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.
- }
- bool held[5]; //The cards that will be held.
- int hand[5]; //The final five chards after dealing.
- //Populate the hand wih the first five cards.
- for ( c[1] = 0; c[1] < 5; C[1] ++ ) {
- hand[ c[1] ] = deal[ [c[1] ];
- }
- int handbuf[5]; //Buffer to use for initial hand checking, to do preliminary display
- //if hand prior to discarding.
- for ( c[1] = 0; c[1] < 5; c[1] ++ ) { handbuf[ c[1] ] = hand[ c[1] ]; //Copy to buffer.
- int handtype = doHandType(handbuf,cards); //Establish ther hand type.
- //This needs a buffer so that we do not use 'hand'until we do a discard phase.
- //We will heck handtype again after doDraw();
- }
- int doHandType(int hand, int cards){
- bool pryle; int pairs; bool onepair; bool twopairs;
- bool quads; bool flush; bool straight;
- bool broadway; bool fullhouse;
- bool straightflush;
- bool royal;
- 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 ) {
- quads = isQuads(hand,cards);
- if ( !quads ) {
- pryle = isPryle(hand,cards);
- //we need to mark the three matching cards in the pryle so that they are not kater counted as pairs.
- pairs = isPair(hand,cards);
- if ( pryle && pairs == 1 ) { fullhouse = true; }
- if ( !pryle ) {
- if ( pairs == 2 ) { twopair = true; }
- else if ( pairs == 1 ) { onepair = true; }
- }
- }
- }
- if ( royal ) return HT_ROYAL;
- if ( straightflush ) return HT_STRAIGHTFLUSH;
- if ( flush ) return HT_FLUSH;
- if ( straight ) return HT_STRAIGHT;
- 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;
- }
- 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;
- }
- //It is a straight flush if both isStraight and isFluah return true, and isBroadway does not.
- //it is a royal flush if both isBroadway and isFlush return true.
- bool isQuads(int hand, int cards) { //Four cards have the same numeric value
- int sorted[5]; int matched; bool m;
- //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);
- //!
- //! Match the five cards against one-another.
- //Chect the first two cards to see if they match.
- if ( cards[ hand[0] ] == cards[ hand[1] ] ) { m = true; }//Try matching from the front.
- //else { } //match fron the back.
- if ( m ) {
- for ( int q = 0; q < 4; q++ ) {
- if ( cards[ hand[q] ] == cards[ hand[q+1] ] ) { match++; }
- }
- }
- else {
- for ( int q = 4; q >= 0; q-- ) {
- if ( cards[ hand[q] ] == cards[ hand[q-1] ] ) { match++; }
- }
- }
- return ( match == 4 );
- }
- //Three cards have the same numeric value
- bool isPryle() {
- int sorted[5]; int matched; bool m;
- //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);
- //!
- //! Match the five cards against one-another.
- //Chect the first two cards to see if they match.
- if ( cards[ hand[0] ] == cards[ hand[1] ] ) { m = true; cardval = cards[ hand[0] ]; }//Try matching from the front.
- else { cardval = cards[hand[4]]; } //match fron the back.
- if ( m ) {
- for ( int q = 0; q < 4; q++ ) {
- if ( cards[ hand[q] ] == cards[ hand[q+1] ] ) { match++; }
- }
- }
- else {
- for ( int q = 4; q >= 0; q-- ) {
- if ( cards[ hand[q] ] == cards[ hand[q-1] ] ) { match++; }
- }
- }
- for ( int q = 0; q < 5; q++ ) {
- if ( cards[ hand[q] ] == cardval ) { hand[q] = -1; } //Mark the cards used to form the pryle
- //so that they are not counted in pair checking.
- }
- return ( match == 3 );
- }
- //if !isQuads && !isPryle Two cards have the same numeric value
- int isPair(int hand, int cards) {
- int pairs;
- int sorted[5];
- int matched; bool m; int q;
- //store numeric values from cards[]
- for ( q = 0; q < 5; q++ ) {
- sorted[q] = cards[ hand[q] ]; //The numeric values.
- }
- //Now, sort the array in a descending manner.
- sortArray(cards, 5);
- //!
- //Check the cards against one another.
- for ( q = 0; q < 5; q++ ) {
- for ( int w = 1; w < 5; w++ ) {
- if ( hand[q] != -1 ) { //&& hand[w] != -1 ) { //If we have not checked thse cards.
- if ( cards[ hand[q] ] == cards[ hand[w] ] ) {
- matched++;
- hand[q] = -1; //Flag abd remove the matched pair.
- hand[w] = -1;
- continue;
- }
- }
- }
- }
- return pairs;
- }
- //isPair returns the number of pairs, so isTwoPair is superfluous.
- bool isTwoPair() { } //If isPair for two numeric values and not isQuads.
- //It is a full house if both isPryle and isPair return true for two values and isQuads retrns 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 draw(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