/* Almost Video Poker, written in standard Decaf, inspired by: * http://en.wikipedia.org/wiki/Video_poker * * Author: Jeremy W. Black */ /* A linear congruential generator inspired by: * http://en.wikipedia.org/wiki/Linear_congruential_generator. * * seed = (a*seed +c) % m * * m is the modulus * a is the multiplier * c is the increment * * 0 < m * 0 <= a < m * 0 <= c < m * 0 <= seed < m */ class Random{ int a; int c; int m; int seed; /* Intializes the Random object using all prime numbers and gets a seed from * the user. */ void initRandom(){ /* Use all prime numbers which satisfy the above constraints such that * a*(m-1)+c < 2^32-1. */ m = 124987; a = 12743; c = 52673; /* Get the seed from the user. */ Print("Please enter a number to be used as the random seed: "); seed = ReadInteger() % m; } /* Returns the next random integer. */ int getRandomInt(){ seed = (a*seed + c) % m; return seed; } } /* A playing card. */ class Card{ int value; int suit; string textValueLeft; string textValueRight; string textSuit; /* Initializes the Card object using a supplied value and suit. Using the * supplied value and suit, also sets strings for use in printing. */ void initCard(int value_, int suit_){ value = value_; suit = suit_; /* Set the left and right value strings. */ if(value == 2){ textValueLeft = "2 "; textValueRight = " 2"; } else if(value == 3){ textValueLeft = "3 "; textValueRight = " 3"; } else if(value == 4){ textValueLeft = "4 "; textValueRight = " 4"; } else if(value == 5){ textValueLeft = "5 "; textValueRight = " 5"; } else if(value == 6){ textValueLeft = "6 "; textValueRight = " 6"; } else if(value == 7){ textValueLeft = "7 "; textValueRight = " 7"; } else if(value == 8){ textValueLeft = "8 "; textValueRight = " 8"; } else if(value == 9){ textValueLeft = "9 "; textValueRight = " 9"; } else if(value == 10){ textValueLeft = "10"; textValueRight = "10"; } else if(value == 11){ textValueLeft = "J "; textValueRight = " J"; } else if(value == 12){ textValueLeft = "Q "; textValueRight = " Q"; } else if(value == 13){ textValueLeft = "K "; textValueRight = " K"; } else if(value == 14){ textValueLeft = "A "; textValueRight = " A"; } /* Set the suit string. */ if(suit == 0) textSuit = " Spades "; else if(suit == 1) textSuit = " Hearts "; else if(suit == 2) textSuit = "Diamonds"; else if(suit == 3) textSuit = " Clubs "; } /* Returns the value of the card. */ int getValue(){ return value; } /* Returns the suit of the card. */ int getSuit(){ return suit; } /* Prints the specified line for the card. * * A card prints as follows (12 characters wide, 9 rows): * * +----------+ * | | * | | * | of | * | | * | | * | | * | | * +----------+ */ void printLine(int line){ if(line == 0) Print("+----------+"); else if(line == 1) Print("| ", textValueLeft, " |"); else if(line == 2) Print("| |"); else if(line == 3) Print("| of |"); else if(line == 4) Print("| |"); else if(line == 5) Print("| ", textSuit, " |"); else if(line == 6) Print("| |"); else if(line == 7) Print("| ", textValueRight, " |"); else if(line == 8) Print("+----------+"); } } /* A deck of 52 cards with 4 suits and 13 cards per suit as follows: * * Suits: 0 - Spades * 1 - Hearts * 2 - Diamonds * 3 - Clubs * * Values: 2-10 - 2-10 * 11 - Jack * 12 - Queen * 13 - King * 14 - Ace (can also "look" like a 1) */ class Deck{ Card[] cards; Random random; int dealPointer; /* Initializes the Deck object with a specified Random object. * * A deck of cards consists of 4 suits, with 13 cards per suit. */ void initDeck(Random random_){ int suit; /* Populate the cards array. */ cards = NewArray(52, Card); for(suit=0; suit<4; suit=suit+1){ int value; for(value=2; value<15; value=value+1){ cards[suit*13 + (value-2)] = New(Card); cards[suit*13 + (value-2)].initCard(value, suit); } } random = random_; /* Start dealing from a random point within the deck. */ dealPointer = random.getRandomInt() % 52; } /* Shuffles the deck by exchanging card positions. */ void shuffle(){ int i; /* Run through this loop 3000 times to get a good shuffle. */ for(i=0; i<3000; i=i+1){ int indexCard1; int indexCard2; Card tempCard; indexCard1 = random.getRandomInt() % 52; indexCard2 = random.getRandomInt() % 52; tempCard = cards[indexCard1]; cards[indexCard1] = cards[indexCard2]; cards[indexCard2] = tempCard; } /* Randomize the deal pointer as well. */ dealPointer = random.getRandomInt() % 52;; } /* Deals a card from the deal pointer and increments the deal pointer. */ Card deal(){ Card dealtCard; dealtCard = cards[dealPointer]; dealPointer = (dealPointer + 1) % 52; return dealtCard; } } /* An object to handling running the game. */ class Game{ Deck deck; Random random; Card[] hand; int credits; int gameType; int[][] paySchedule; bool[] heldCards; /* Initializes the Game object. */ void initGame(){ int i; /* Create the Random object. */ random = New(Random); random.initRandom(); /* Create the Deck object. */ deck = New(Deck); deck.initDeck(random); /* Allocate the hand. */ hand = NewArray(5, Card); heldCards = NewArray(5, bool); /* Start with 100 credits. */ credits = 100; /* Create the pay schedule. */ paySchedule = NewArray(5, int[]); for(i=0; i<5; i=i+1) paySchedule[i] = NewArray(13, int); } bool startGame(){ int i; /* Get the game type. */ getGameType(); /* Set the pay schedule. */ if(gameType == 1) setPayScheduleJacksOrBetter(); else if(gameType == 2) setPayScheduleTensOrBetter(); else if(gameType == 3) setPayScheduleDeucesWild(); else if(gameType == 4) setPayScheduleDoubleBonus(); else if(gameType == 5) setPayScheduleDoubleDoubleBonus(); else return false; return true; } void getGameType(){ gameType = 0; Print("\n\nGame Types:\n"); Print(" 1) Jacks or Better\n"); Print(" 2) Tens or Better\n"); Print(" 3) Deuces Wild\n"); Print(" 4) Double Bonus\n"); Print(" 5) Double Double Bonus\n"); Print(" 6) Quit\n"); Print("\n"); while((gameType < 1) || (gameType > 5)){ Print("Please enter a number for the game type: "); gameType = ReadInteger(); if(gameType == 6) break; } } /* Sets the entities in the pay schedule array for Jacks or Better as follows: * * +-----------------+----------+-----------+-----------+-----------+-----------+ * | Hand | 1 credit | 2 credits | 3 credits | 4 credits | 5 credits | * +-----------------+----------+-----------+-----------+-----------+-----------+ * 0 | Royal Flush | 250 | 500 | 750 | 1000 | 4000 | * 1 | Straight Flush | 50 | 100 | 150 | 200 | 250 | * 2 | Four of a Kind | 25 | 50 | 75 | 100 | 125 | * 3 | Full House | 9 | 18 | 27 | 36 | 45 | * 4 | Flush | 6 | 12 | 18 | 24 | 30 | * 5 | Straight | 4 | 8 | 12 | 16 | 20 | * 6 | Three of a Kind | 3 | 6 | 9 | 12 | 15 | * 7 | Two Pair | 2 | 4 | 6 | 8 | 10 | * 8 | Jacks or Better | 1 | 2 | 3 | 4 | 5 | * +-----------------+----------+-----------+-----------+-----------------------+ */ void setPayScheduleJacksOrBetter(){ /* Print the pay schedule. */ Print("\n\nJacks or Better\n\n Pay Schedule:\n\n"); Print(" +-----------------+----------+-----------+-----------+-----------+-----------+\n"); Print(" | Hand | 1 credit | 2 credits | 3 credits | 4 credits | 5 credits |\n"); Print(" +-----------------+----------+-----------+-----------+-----------+-----------+\n"); Print(" | Royal Flush | 250 | 500 | 750 | 1000 | 4000 |\n"); Print(" | Straight Flush | 50 | 100 | 150 | 200 | 250 |\n"); Print(" | Four of a Kind | 25 | 50 | 75 | 100 | 125 |\n"); Print(" | Full House | 9 | 18 | 27 | 36 | 45 |\n"); Print(" | Flush | 6 | 12 | 18 | 24 | 30 |\n"); Print(" | Straight | 4 | 8 | 12 | 16 | 20 |\n"); Print(" | Three of a Kind | 3 | 6 | 9 | 12 | 15 |\n"); Print(" | Two Pair | 2 | 4 | 6 | 8 | 10 |\n"); Print(" | Jacks or Better | 1 | 2 | 3 | 4 | 5 |\n"); Print(" +-----------------+----------+-----------+-----------+-----------------------+\n"); Print("\n\n"); /* Royal Flush. */ paySchedule[0][0] = 250; paySchedule[1][0] = 500; paySchedule[2][0] = 750; paySchedule[3][0] = 1000; paySchedule[4][0] = 4000; /* Straight Flush. */ paySchedule[0][1] = 50; paySchedule[1][1] = 100; paySchedule[2][1] = 150; paySchedule[3][1] = 200; paySchedule[4][1] = 250; /* Four of a Kind. */ paySchedule[0][2] = 25; paySchedule[1][2] = 50; paySchedule[2][2] = 75; paySchedule[3][2] = 100; paySchedule[4][2] = 125; /* Full House. */ paySchedule[0][3] = 9; paySchedule[1][3] = 18; paySchedule[2][3] = 27; paySchedule[3][3] = 36; paySchedule[4][3] = 45; /* Flush. */ paySchedule[0][4] = 6; paySchedule[1][4] = 12; paySchedule[2][4] = 18; paySchedule[3][4] = 24; paySchedule[4][4] = 30; /* Straight. */ paySchedule[0][5] = 4; paySchedule[1][5] = 8; paySchedule[2][5] = 12; paySchedule[3][5] = 16; paySchedule[4][5] = 20; /* Three of a Kind. */ paySchedule[0][6] = 3; paySchedule[1][6] = 6; paySchedule[2][6] = 9; paySchedule[3][6] = 12; paySchedule[4][6] = 15; /* Two Pair. */ paySchedule[0][7] = 2; paySchedule[1][7] = 4; paySchedule[2][7] = 6; paySchedule[3][7] = 8; paySchedule[4][7] = 10; /* Jacks or Better. */ paySchedule[0][8] = 1; paySchedule[1][8] = 2; paySchedule[2][8] = 3; paySchedule[3][8] = 4; paySchedule[4][8] = 5; } /* Sets the entities in the pay schedule array for Tens or Better as follows: * * +-----------------+----------+-----------+-----------+-----------+-----------+ * | Hand | 1 credit | 2 credits | 3 credits | 4 credits | 5 credits | * +-----------------+----------+-----------+-----------+-----------+-----------+ * 0 | Royal Flush | 250 | 500 | 750 | 1000 | 4000 | * 1 | Straight Flush | 50 | 100 | 150 | 200 | 250 | * 2 | Four of a Kind | 25 | 50 | 75 | 100 | 125 | * 3 | Full House | 6 | 12 | 18 | 24 | 30 | * 4 | Flush | 5 | 10 | 15 | 20 | 25 | * 5 | Straight | 4 | 8 | 12 | 16 | 20 | * 6 | Three of a Kind | 3 | 6 | 9 | 12 | 15 | * 7 | Two Pair | 2 | 4 | 6 | 8 | 10 | * 8 | Tens or Better | 1 | 2 | 3 | 4 | 5 | * +-----------------+----------+-----------+-----------+-----------------------+ */ void setPayScheduleTensOrBetter(){ /* Print the pay schedule. */ Print("\n\nTens or Better\n\n Pay Schedule:\n\n"); Print(" +-----------------+----------+-----------+-----------+-----------+-----------+\n"); Print(" | Hand | 1 credit | 2 credits | 3 credits | 4 credits | 5 credits |\n"); Print(" +-----------------+----------+-----------+-----------+-----------+-----------+\n"); Print(" | Royal Flush | 250 | 500 | 750 | 1000 | 4000 |\n"); Print(" | Straight Flush | 50 | 100 | 150 | 200 | 250 |\n"); Print(" | Four of a Kind | 25 | 50 | 75 | 100 | 125 |\n"); Print(" | Full House | 6 | 12 | 18 | 24 | 30 |\n"); Print(" | Flush | 5 | 10 | 15 | 20 | 25 |\n"); Print(" | Straight | 4 | 8 | 12 | 16 | 20 |\n"); Print(" | Three of a Kind | 3 | 6 | 9 | 12 | 15 |\n"); Print(" | Two Pair | 2 | 4 | 6 | 8 | 10 |\n"); Print(" | Tens or Better | 1 | 2 | 3 | 4 | 5 |\n"); Print(" +-----------------+----------+-----------+-----------+-----------------------+\n"); Print("\n\n"); /* Royal Flush. */ paySchedule[0][0] = 250; paySchedule[1][0] = 500; paySchedule[2][0] = 750; paySchedule[3][0] = 1000; paySchedule[4][0] = 4000; /* Straight Flush. */ paySchedule[0][1] = 50; paySchedule[1][1] = 100; paySchedule[2][1] = 150; paySchedule[3][1] = 200; paySchedule[4][1] = 250; /* Four of a Kind. */ paySchedule[0][2] = 25; paySchedule[1][2] = 50; paySchedule[2][2] = 75; paySchedule[3][2] = 100; paySchedule[4][2] = 125; /* Full House. */ paySchedule[0][3] = 6; paySchedule[1][3] = 12; paySchedule[2][3] = 18; paySchedule[3][3] = 24; paySchedule[4][3] = 30; /* Flush. */ paySchedule[0][4] = 5; paySchedule[1][4] = 10; paySchedule[2][4] = 15; paySchedule[3][4] = 20; paySchedule[4][4] = 25; /* Straight. */ paySchedule[0][5] = 4; paySchedule[1][5] = 8; paySchedule[2][5] = 12; paySchedule[3][5] = 16; paySchedule[4][5] = 20; /* Three of a Kind. */ paySchedule[0][6] = 3; paySchedule[1][6] = 6; paySchedule[2][6] = 9; paySchedule[3][6] = 12; paySchedule[4][6] = 15; /* Two Pair. */ paySchedule[0][7] = 2; paySchedule[1][7] = 4; paySchedule[2][7] = 6; paySchedule[3][7] = 8; paySchedule[4][7] = 10; /* Tens or Better. */ paySchedule[0][8] = 1; paySchedule[1][8] = 2; paySchedule[2][8] = 3; paySchedule[3][8] = 4; paySchedule[4][8] = 5; } /* Sets the entities in the pay schedule array for Deuces Wild as follows: * * +---------------------+----------+-----------+-----------+-----------+-----------+ * | Hand | 1 credit | 2 credits | 3 credits | 4 credits | 5 credits | * +---------------------+----------+-----------+-----------+-----------+-----------+ * 0 | Natural Royal Flush | 300 | 600 | 900 | 1200 | 4000 | * 1 | Four Deuces | 200 | 400 | 600 | 800 | 1000 | * 2 | Wild Royal Flush | 25 | 50 | 75 | 100 | 125 | * 3 | Five of a Kind | 15 | 30 | 45 | 60 | 75 | * 4 | Straight Flush | 9 | 18 | 27 | 36 | 45 | * 5 | Four of a Kind | 5 | 10 | 15 | 20 | 25 | * 6 | Full House | 3 | 6 | 9 | 12 | 15 | * 7 | Flush | 2 | 4 | 6 | 8 | 10 | * 8 | Straight | 2 | 4 | 6 | 8 | 10 | * 9 | Three of a Kind | 1 | 2 | 3 | 4 | 5 | * +---------------------+----------+-----------+-----------+-----------------------+ */ void setPayScheduleDeucesWild(){ /* Print the pay schedule. */ Print("\n\nDeuces Wild\n\n Pay Schedule:\n\n"); Print(" +---------------------+----------+-----------+-----------+-----------+-----------+\n"); Print(" | Hand | 1 credit | 2 credits | 3 credits | 4 credits | 5 credits |\n"); Print(" +---------------------+----------+-----------+-----------+-----------+-----------+\n"); Print(" | Natural Royal Flush | 300 | 600 | 900 | 1200 | 4000 |\n"); Print(" | Four Deuces | 200 | 400 | 600 | 800 | 1000 |\n"); Print(" | Wild Royal Flush | 25 | 50 | 75 | 100 | 125 |\n"); Print(" | Five of a Kind | 15 | 30 | 45 | 60 | 75 |\n"); Print(" | Straight Flush | 9 | 18 | 27 | 36 | 45 |\n"); Print(" | Four of a Kind | 5 | 10 | 15 | 20 | 25 |\n"); Print(" | Full House | 3 | 6 | 9 | 12 | 15 |\n"); Print(" | Flush | 2 | 4 | 6 | 8 | 10 |\n"); Print(" | Straight | 2 | 4 | 6 | 8 | 10 |\n"); Print(" | Three of a Kind | 1 | 2 | 3 | 4 | 5 |\n"); Print(" +---------------------+----------+-----------+-----------+-----------------------+\n"); Print("\n\n"); /* Natural Royal Flush. */ paySchedule[0][0] = 300; paySchedule[1][0] = 600; paySchedule[2][0] = 900; paySchedule[3][0] = 1200; paySchedule[4][0] = 4000; /* Four Deuces. */ paySchedule[0][1] = 200; paySchedule[1][1] = 400; paySchedule[2][1] = 600; paySchedule[3][1] = 800; paySchedule[4][1] = 1000; /* Wild Royal Flush. */ paySchedule[0][2] = 25; paySchedule[1][2] = 50; paySchedule[2][2] = 75; paySchedule[3][2] = 100; paySchedule[4][2] = 125; /* Five of a Kind. */ paySchedule[0][3] = 15; paySchedule[1][3] = 30; paySchedule[2][3] = 45; paySchedule[3][3] = 60; paySchedule[4][3] = 75; /* Straight Flush. */ paySchedule[0][4] = 9; paySchedule[1][4] = 18; paySchedule[2][4] = 27; paySchedule[3][4] = 36; paySchedule[4][4] = 45; /* Four of a Kind. */ paySchedule[0][5] = 5; paySchedule[1][5] = 10; paySchedule[2][5] = 15; paySchedule[3][5] = 20; paySchedule[4][5] = 25; /* Full House. */ paySchedule[0][6] = 3; paySchedule[1][6] = 6; paySchedule[2][6] = 9; paySchedule[3][6] = 12; paySchedule[4][6] = 15; /* Flush. */ paySchedule[0][7] = 2; paySchedule[1][7] = 4; paySchedule[2][7] = 6; paySchedule[3][7] = 8; paySchedule[4][7] = 10; /* Straight. */ paySchedule[0][8] = 2; paySchedule[1][8] = 4; paySchedule[2][8] = 6; paySchedule[3][8] = 8; paySchedule[4][8] = 10; /* Three of a Kind. */ paySchedule[0][9] = 1; paySchedule[1][9] = 2; paySchedule[2][9] = 3; paySchedule[3][9] = 4; paySchedule[4][9] = 5; } /* Sets the entities in the pay schedule array for Double Bonus as follows: * * +-----------------+----------+-----------+-----------+-----------+-----------+ * | Hand | 1 credit | 2 credits | 3 credits | 4 credits | 5 credits | * +-----------------+----------+-----------+-----------+-----------+-----------+ * 0 | Royal Flush | 250 | 500 | 750 | 1000 | 4000 | * 1 | Straight Flush | 50 | 100 | 150 | 200 | 250 | * 2 | Four Aces | 160 | 320 | 480 | 640 | 800 | * 3 | Four 2-4 | 80 | 160 | 240 | 320 | 400 | * 4 | Four 5-K | 50 | 100 | 150 | 200 | 250 | * 5 | Full House | 10 | 20 | 30 | 40 | 50 | * 6 | Flush | 7 | 14 | 21 | 28 | 35 | * 7 | Straight | 5 | 10 | 15 | 20 | 25 | * 8 | Three of a Kind | 3 | 6 | 9 | 12 | 15 | * 9 | Two Pair | 1 | 2 | 3 | 4 | 5 | * 10 | Jacks or Better | 1 | 2 | 3 | 4 | 5 | * +-----------------+----------+-----------+-----------+-----------------------+ */ void setPayScheduleDoubleBonus(){ /* Print the pay schedule. */ Print("\n\nDouble Bonus\n\n Pay Schedule:\n\n"); Print(" +-----------------+----------+-----------+-----------+-----------+-----------+\n"); Print(" | Hand | 1 credit | 2 credits | 3 credits | 4 credits | 5 credits |\n"); Print(" +-----------------+----------+-----------+-----------+-----------+-----------+\n"); Print(" | Royal Flush | 250 | 500 | 750 | 1000 | 4000 |\n"); Print(" | Straight Flush | 50 | 100 | 150 | 200 | 250 |\n"); Print(" | Four Aces | 160 | 320 | 480 | 640 | 800 |\n"); Print(" | Four 2-4 | 80 | 160 | 240 | 320 | 400 |\n"); Print(" | Four 5-K | 50 | 100 | 150 | 200 | 250 |\n"); Print(" | Full House | 10 | 20 | 30 | 40 | 50 |\n"); Print(" | Flush | 7 | 14 | 21 | 28 | 35 |\n"); Print(" | Straight | 5 | 10 | 15 | 20 | 25 |\n"); Print(" | Three of a Kind | 3 | 6 | 9 | 12 | 15 |\n"); Print(" | Two Pair | 1 | 2 | 3 | 4 | 5 |\n"); Print(" | Jacks or Better | 1 | 2 | 3 | 4 | 5 |\n"); Print(" +-----------------+----------+-----------+-----------+-----------------------+\n"); Print("\n\n"); /* Royal Flush. */ paySchedule[0][0] = 250; paySchedule[1][0] = 500; paySchedule[2][0] = 750; paySchedule[3][0] = 1000; paySchedule[4][0] = 4000; /* Straight Flush. */ paySchedule[0][1] = 50; paySchedule[1][1] = 100; paySchedule[2][1] = 150; paySchedule[3][1] = 200; paySchedule[4][1] = 250; /* Four Aces. */ paySchedule[0][2] = 160; paySchedule[1][2] = 320; paySchedule[2][2] = 480; paySchedule[3][2] = 640; paySchedule[4][2] = 800; /* Four 2-4. */ paySchedule[0][3] = 80; paySchedule[1][3] = 160; paySchedule[2][3] = 240; paySchedule[3][3] = 320; paySchedule[4][3] = 400; /* Four 5-K. */ paySchedule[0][4] = 50; paySchedule[1][4] = 100; paySchedule[2][4] = 150; paySchedule[3][4] = 200; paySchedule[4][4] = 250; /* Full House. */ paySchedule[0][5] = 10; paySchedule[1][5] = 20; paySchedule[2][5] = 30; paySchedule[3][5] = 40; paySchedule[4][5] = 50; /* Flush. */ paySchedule[0][6] = 7; paySchedule[1][6] = 14; paySchedule[2][6] = 21; paySchedule[3][6] = 28; paySchedule[4][6] = 35; /* Straight. */ paySchedule[0][7] = 5; paySchedule[1][7] = 10; paySchedule[2][7] = 15; paySchedule[3][7] = 20; paySchedule[4][7] = 25; /* Three of a Kind. */ paySchedule[0][8] = 3; paySchedule[1][8] = 6; paySchedule[2][8] = 9; paySchedule[3][8] = 12; paySchedule[4][8] = 15; /* Two Pair. */ paySchedule[0][9] = 1; paySchedule[1][9] = 2; paySchedule[2][9] = 3; paySchedule[3][9] = 4; paySchedule[4][9] = 5; /* Jacks or Better. */ paySchedule[0][10] = 1; paySchedule[1][10] = 2; paySchedule[2][10] = 3; paySchedule[3][10] = 4; paySchedule[4][10] = 5; } /* Sets the entities in the pay schedule array for Double Double Bonus as follows: * * +------------------+----------+-----------+-----------+-----------+-----------+ * | Hand | 1 credit | 2 credits | 3 credits | 4 credits | 5 credits | * +------------------+----------+-----------+-----------+-----------+-----------+ * 0 | Royal Flush | 250 | 500 | 750 | 1000 | 4000 | * 1 | Straight Flush | 50 | 100 | 150 | 200 | 250 | * 2 | Four Aces w/ 2-4 | 400 | 800 | 1200 | 1600 | 2000 | * 3 | Four 2-4 w/ A-4 | 160 | 320 | 480 | 640 | 800 | * 4 | Four Aces | 160 | 320 | 480 | 640 | 800 | * 5 | Four 2-4 | 80 | 160 | 240 | 320 | 400 | * 6 | Four 5-K | 50 | 100 | 150 | 200 | 250 | * 7 | Full House | 10 | 20 | 30 | 40 | 50 | * 8 | Flush | 7 | 14 | 21 | 28 | 35 | * 9 | Straight | 5 | 10 | 15 | 20 | 25 | * 10 | Three of a Kind | 3 | 6 | 9 | 12 | 15 | * 11 | Two Pair | 1 | 2 | 3 | 4 | 5 | * 12 | Jacks or Better | 1 | 2 | 3 | 4 | 5 | * +------------------+----------+-----------+-----------+-----------------------+ */ void setPayScheduleDoubleDoubleBonus(){ /* Print the pay schedule. */ Print("\n\nDouble Double Bonus\n\n Pay Schedule:\n\n"); Print(" +------------------+----------+-----------+-----------+-----------+-----------+\n"); Print(" | Hand | 1 credit | 2 credits | 3 credits | 4 credits | 5 credits |\n"); Print(" +------------------+----------+-----------+-----------+-----------+-----------+\n"); Print(" | Royal Flush | 250 | 500 | 750 | 1000 | 4000 |\n"); Print(" | Straight Flush | 50 | 100 | 150 | 200 | 250 |\n"); Print(" | Four Aces w/ 2-4 | 400 | 800 | 1200 | 1600 | 2000 |\n"); Print(" | Four 2-4 w/ A-4 | 160 | 320 | 480 | 640 | 800 |\n"); Print(" | Four Aces | 160 | 320 | 480 | 640 | 800 |\n"); Print(" | Four 2-4 | 80 | 160 | 240 | 320 | 400 |\n"); Print(" | Four 5-K | 50 | 100 | 150 | 200 | 250 |\n"); Print(" | Full House | 10 | 20 | 30 | 40 | 50 |\n"); Print(" | Flush | 7 | 14 | 21 | 28 | 35 |\n"); Print(" | Straight | 5 | 10 | 15 | 20 | 25 |\n"); Print(" | Three of a Kind | 3 | 6 | 9 | 12 | 15 |\n"); Print(" | Two Pair | 1 | 2 | 3 | 4 | 5 |\n"); Print(" | Jacks or Better | 1 | 2 | 3 | 4 | 5 |\n"); Print(" +------------------+----------+-----------+-----------+-----------------------+\n"); Print("\n\n"); /* Royal Flush. */ paySchedule[0][0] = 250; paySchedule[1][0] = 500; paySchedule[2][0] = 750; paySchedule[3][0] = 1000; paySchedule[4][0] = 4000; /* Straight Flush. */ paySchedule[0][1] = 50; paySchedule[1][1] = 100; paySchedule[2][1] = 150; paySchedule[3][1] = 200; paySchedule[4][1] = 250; /* Four Aces w/2-4. */ paySchedule[0][2] = 400; paySchedule[1][2] = 800; paySchedule[2][2] = 1200; paySchedule[3][2] = 1600; paySchedule[4][2] = 2000; /* Four 2-4 w/ A-4. */ paySchedule[0][3] = 160; paySchedule[1][3] = 320; paySchedule[2][3] = 480; paySchedule[3][3] = 640; paySchedule[4][3] = 800; /* Four Aces. */ paySchedule[0][4] = 160; paySchedule[1][4] = 320; paySchedule[2][4] = 480; paySchedule[3][4] = 640; paySchedule[4][4] = 800; /* Four 2-4. */ paySchedule[0][5] = 80; paySchedule[1][5] = 160; paySchedule[2][5] = 240; paySchedule[3][5] = 320; paySchedule[4][5] = 400; /* Four 5-K. */ paySchedule[0][6] = 50; paySchedule[1][6] = 100; paySchedule[2][6] = 150; paySchedule[3][6] = 200; paySchedule[4][6] = 250; /* Full House. */ paySchedule[0][7] = 10; paySchedule[1][7] = 20; paySchedule[2][7] = 30; paySchedule[3][7] = 40; paySchedule[4][7] = 50; /* Flush. */ paySchedule[0][8] = 7; paySchedule[1][8] = 14; paySchedule[2][8] = 21; paySchedule[3][8] = 28; paySchedule[4][8] = 35; /* Straight. */ paySchedule[0][9] = 5; paySchedule[1][9] = 10; paySchedule[2][9] = 15; paySchedule[3][9] = 20; paySchedule[4][9] = 25; /* Three of a Kind. */ paySchedule[0][10] = 3; paySchedule[1][10] = 6; paySchedule[2][10] = 9; paySchedule[3][10] = 12; paySchedule[4][10] = 15; /* Two Pair. */ paySchedule[0][11] = 1; paySchedule[1][11] = 2; paySchedule[2][11] = 3; paySchedule[3][11] = 4; paySchedule[4][11] = 5; /* Jacks or Better. */ paySchedule[0][12] = 1; paySchedule[1][12] = 2; paySchedule[2][12] = 3; paySchedule[3][12] = 4; paySchedule[4][12] = 5; } /* Plays a hand. */ bool playHand(){ int bet; int winnings; int card; int line; int cardsToHold; /* Get the bet. */ bet = getBet(); credits = credits - bet; if(bet == 0) return false; Print("\n"); /* Deal the hand. */ for(card=0; card<5; card=card+1) hand[card] = deck.deal(); /* Print the hand. */ printHand(); Print("\n"); /* Get user input on which cards to hold. */ Print("Enter the cards you would like to hold as a continuous string.\n"); for(card=0; card<5; card=card+1) heldCards[card] = false; cardsToHold = -1; while(cardsToHold == -1){ int cardToBeHeld; Print("12345 holds all cards and 0 or no input holds no cards: "); cardsToHold = ReadInteger(); while(cardsToHold != 0){ cardToBeHeld = cardsToHold % 10; cardsToHold = cardsToHold/10; if((cardToBeHeld < 0) || (cardToBeHeld > 5)){ Print("Illegal card number ", cardToBeHeld, "\n"); cardsToHold = -1; break; } else if(cardToBeHeld > 0) heldCards[cardToBeHeld-1] = true; } } Print("\n"); /* Deal replacement cards, if necessary. */ for(card=0; card<5; card=card+1) if(!heldCards[card]) hand[card] = deck.deal(); /* Print the hand. */ printHand(); /* Check results. */ Print("\n"); if(gameType == 1) winnings = checkHandJacksOrBetter(bet); else if(gameType == 2) winnings = checkHandTensOrBetter(bet); else if(gameType == 3) winnings = checkHandDeucesWild(bet); else if(gameType == 4) winnings = checkHandDoubleBonus(bet); else if(gameType == 5) winnings = checkHandDoubleDoubleBonus(bet); Print("\n\n"); /* Update credits. */ credits = credits + winnings; /* Clear held cards. */ for(card=0; card<5; card=card+1) heldCards[card] = false; return true; } /* Prompts the user for a bet and returns the value, once valid. */ int getBet(){ int minBet; int maxBet; int bet; if(credits <= 0) return 0; minBet = 1; if(credits < 5) maxBet = credits; else maxBet = 5; bet = -1; Print("Current credits: ", credits, "\n"); while((bet < 0) || (bet > maxBet)){ Print("Please enter a wager between ", minBet, " and ", maxBet); Print(" or 0 to go back to the menu", ": "); bet = ReadInteger(); } return bet; } /* Sorts the hand by value, lowest to highest. */ void sortHand(){ Card tempCard; int i; for(i=1; i<5; i=i+1) if(hand[0].getValue() > hand[i].getValue()){ tempCard = hand[0]; hand[0] = hand[i]; hand[i] = tempCard; } for(i=2; i<5; i=i+1) if(hand[1].getValue() > hand[i].getValue()){ tempCard = hand[1]; hand[1] = hand[i]; hand[i] = tempCard; } for(i=3; i<5; i=i+1) if(hand[2].getValue() > hand[i].getValue()){ tempCard = hand[2]; hand[2] = hand[i]; hand[i] = tempCard; } for(i=4; i<5; i=i+1) if(hand[3].getValue() > hand[i].getValue()){ tempCard = hand[3]; hand[3] = hand[i]; hand[i] = tempCard; } } /* Returns true if the hand has a 10, Jack, Queen, King, and Ace, all of the * same suit. */ bool isRoyalFlush(int numDeuces){ if(numDeuces < 0) return false; else if(numDeuces == 0){ if((hand[0].getValue() == 10) && isStraight(0) && isFlush(0)) return true; else return false; } else if(numDeuces == 1){ if((hand[1].getValue() > 9) && isStraight(1) && isFlush(1)) return true; else return false; } else if(numDeuces == 2){ if((hand[2].getValue() > 9) && isStraight(2) && isFlush(2)) return true; else return false; } else if(numDeuces == 3){ if((hand[3].getValue() > 9) && isStraight(3) && isFlush(3)) return true; else return false; } else return true; } /* Returns true if the hand has five cards of the same value. */ bool isFiveOfAKind(int numDeuces){ if(numDeuces < 1) return false; else if(numDeuces == 1){ if(hand[1].getValue() == hand[4].getValue()) return true; else return false; } else if(numDeuces == 2){ if(hand[2].getValue() == hand[4].getValue()) return true; else return false; } else if(numDeuces == 3){ if(hand[3].getValue() == hand[4].getValue()) return true; else return false; } else return true; } /* Returns true if the hand has four cards of the same value. */ bool isFourOfAKind(int numDeuces){ if(numDeuces < 0) return false; else if(numDeuces == 0){ if((hand[0].getValue() == hand[3].getValue()) || (hand[1].getValue() == hand[4].getValue())) return true; else return false; } else if(numDeuces == 1){ if((hand[1].getValue() == hand[3].getValue()) || (hand[2].getValue() == hand[4].getValue())) return true; else return false; } else if(numDeuces == 2){ if((hand[2].getValue() == hand[3].getValue()) || (hand[3].getValue() == hand[4].getValue())) return true; else return false; } else return true; } /* Returns true if the hand has two cards of one value and three cards of * another value. */ bool isFullHouse(int numDeuces){ if(numDeuces < 0) return false; else if(numDeuces == 0){ if(isTwoPair(0) && isThreeOfAKind(0)) return true; else return false; } else if(numDeuces == 1){ if(isTwoPair(0)) return true; else return false; } else if(numDeuces == 2){ if(isTwoPair(0) || isThreeOfAKind(0)) return true; else return false; } else return true; } /* Returns true if the hand has all cards of the same suit. */ bool isFlush(int numDeuces){ if(numDeuces < 0) return false; else if(numDeuces == 0){ if((hand[0].getSuit() == hand[1].getSuit()) && (hand[0].getSuit() == hand[2].getSuit()) && (hand[0].getSuit() == hand[3].getSuit()) && (hand[0].getSuit() == hand[4].getSuit())) return true; else return false; } else if(numDeuces == 1){ if((hand[1].getSuit() == hand[2].getSuit()) && (hand[1].getSuit() == hand[3].getSuit()) && (hand[1].getSuit() == hand[4].getSuit())) return true; else return false; } else if(numDeuces == 2){ if((hand[2].getSuit() == hand[3].getSuit()) && (hand[2].getSuit() == hand[4].getSuit())) return true; else return false; } else if(numDeuces == 3){ if(hand[3].getSuit() == hand[4].getSuit()) return true; else return false; } else return true; } /* Returns true if the hand has all cards in consecutive order. */ bool isStraight(int numDeuces){ if(numDeuces < 0) return false; else if(numDeuces == 0){ if((hand[1].getValue() == (hand[0].getValue() + 1)) && (hand[2].getValue() == (hand[0].getValue() + 2)) && (hand[3].getValue() == (hand[0].getValue() + 3)) && (hand[4].getValue() == (hand[0].getValue() + 4))) return true; else if((hand[1].getValue() == (hand[0].getValue() + 1)) && (hand[2].getValue() == (hand[0].getValue() + 2)) && (hand[3].getValue() == (hand[0].getValue() + 3)) && (hand[4].getValue() == 14) && (hand[0].getValue() == 2)) return true; else return false; } else if(numDeuces == 1){ if(hand[1].getValue() == hand[2].getValue()) return false; else if(hand[2].getValue() == hand[3].getValue()) return false; else if(hand[3].getValue() == hand[4].getValue()) return false; else if((hand[4].getValue() - hand[1].getValue()) < 5) return true; else if((hand[4].getValue() == 14) && (hand[3].getValue() < 6) && (hand[2].getValue() < 6) && (hand[1].getValue() < 6)) return true; else return false; } else if(numDeuces == 2){ if(hand[2].getValue() == hand[3].getValue()) return false; else if(hand[3].getValue() == hand[4].getValue()) return false; else if((hand[4].getValue() - hand[2].getValue()) < 5) return true; else if((hand[4].getValue() == 14) && (hand[3].getValue() < 6) && (hand[2].getValue() < 6)) return true; else return false; } else if(numDeuces == 3){ if(hand[3].getValue() == hand[4].getValue()) return false; else if((hand[4].getValue() - hand[3].getValue()) < 5) return true; else if((hand[4].getValue() == 14) && (hand[3].getValue() < 6)) return true; else return false; } else return true; } /* Returns true if the hand has three cards of the same value. */ bool isThreeOfAKind(int numDeuces){ if(numDeuces < 0) return false; else if(numDeuces == 0){ if((hand[0].getValue() == hand[2].getValue()) || (hand[1].getValue() == hand[3].getValue()) || (hand[2].getValue() == hand[4].getValue())) return true; else return false; } else if(numDeuces == 1){ if(hand[1].getValue() == hand[2].getValue()) return true; else if(hand[2].getValue() == hand[3].getValue()) return true; else if(hand[3].getValue() == hand[4].getValue()) return true; else return false; } else return true; } /* Returns true if the hand has two cards of the one value and two cards of * a another value. */ bool isTwoPair(int numDeuces){ int firstPairValue; if(numDeuces < 0) return false; else if(numDeuces == 0){ if(hand[0].getValue() == hand[1].getValue()) firstPairValue = hand[0].getValue(); else if(hand[1].getValue() == hand[2].getValue()) firstPairValue = hand[1].getValue(); else return false; if((hand[2].getValue() == hand[3].getValue()) && (hand[2].getValue() != firstPairValue)) return true; else if((hand[3].getValue() == hand[4].getValue()) && (hand[3].getValue() != firstPairValue)) return true; else return false; } else if(numDeuces == 1){ if(isFourOfAKind(0)) return false; else if(hand[1].getValue() == hand[2].getValue()) return true; else if(hand[2].getValue() == hand[3].getValue()) return true; else if(hand[3].getValue() == hand[4].getValue()) return true; else return false; } else return true; } /* Returns true if the hand has two cards of the same value that is higher * than the specified value. */ bool isPairOfValueOrBetter(int lowWinValue, int numDeuces){ if(numDeuces < 0) return false; else if(numDeuces == 0){ if((hand[0].getValue() == hand[1].getValue()) && hand[0].getValue() >= lowWinValue) return true; else if((hand[1].getValue() == hand[2].getValue()) && hand[1].getValue() >= lowWinValue) return true; else if((hand[2].getValue() == hand[3].getValue()) && hand[2].getValue() >= lowWinValue) return true; else if((hand[3].getValue() == hand[4].getValue()) && hand[3].getValue() >= lowWinValue) return true; else return false; } else if(numDeuces == 1){ if(hand[4].getValue() >= lowWinValue) return true; else return false; } else return true; } /* Checks the hand against the Jacks or Better rules and returns the winnings * based on the specified bet. */ int checkHandJacksOrBetter(int bet){ bool royalFlush; bool fourOfAKind; bool fullHouse; bool flush; bool straight; bool threeOfAKind; bool twoPair; bool jacksOrBetter; /* Sort the hand before doing any checking, it simplifies the checking. */ sortHand(); royalFlush = isRoyalFlush(0); fourOfAKind = isFourOfAKind(0); fullHouse = isFullHouse(0); flush = isFlush(0); straight = isStraight(0); threeOfAKind = isThreeOfAKind(0); twoPair = isTwoPair(0); jacksOrBetter = isPairOfValueOrBetter(11, 0); /* Process the checks starting with the best hands. */ if(royalFlush){ Print("Royal Flush! Won: ", paySchedule[bet-1][0], " credits\n"); return paySchedule[bet-1][0]; } else if(straight && flush){ Print("Straigh Flush! Won: ", paySchedule[bet-1][1], " credits\n"); return paySchedule[bet-1][1]; } else if(fourOfAKind){ Print("Four of a Kind! Won: ", paySchedule[bet-1][2], " credits\n"); return paySchedule[bet-1][2]; } else if(fullHouse){ Print("Full House! Won: ", paySchedule[bet-1][3], " credits\n"); return paySchedule[bet-1][3]; } else if(flush){ Print("Flush! Won: ", paySchedule[bet-1][4], " credits\n"); return paySchedule[bet-1][4]; } else if(straight){ Print("Straight! Won: ", paySchedule[bet-1][5], " credits\n"); return paySchedule[bet-1][5]; } else if(threeOfAKind){ Print("Three of a Kind! Won: ", paySchedule[bet-1][6], " credits\n"); return paySchedule[bet-1][6]; } else if(twoPair){ Print("Two Pair! Won: ", paySchedule[bet-1][7], " credits\n"); return paySchedule[bet-1][7]; } else if(jacksOrBetter){ Print("Jacks or Better! Won: ", paySchedule[bet-1][8], " credits\n"); return paySchedule[bet-1][8]; } else return 0; } /* Checks the hand against the Tens or Better rules and returns the winnings * based on the specified bet. */ int checkHandTensOrBetter(int bet){ bool royalFlush; bool fourOfAKind; bool fullHouse; bool flush; bool straight; bool threeOfAKind; bool twoPair; bool tensOrBetter; /* Sort the hand before doing any checking, it simplifies the checking. */ sortHand(); royalFlush = isRoyalFlush(0); fourOfAKind = isFourOfAKind(0); fullHouse = isFullHouse(0); flush = isFlush(0); straight = isStraight(0); threeOfAKind = isThreeOfAKind(0); twoPair = isTwoPair(0); tensOrBetter = isPairOfValueOrBetter(10, 0); /* Process the checks starting with the best hands. */ if(royalFlush){ Print("Royal Flush! Won: ", paySchedule[bet-1][0], " credits\n"); return paySchedule[bet-1][0]; } else if(straight && flush){ Print("Straigh Flush! Won: ", paySchedule[bet-1][1], " credits\n"); return paySchedule[bet-1][1]; } else if(fourOfAKind){ Print("Four of a Kind! Won: ", paySchedule[bet-1][2], " credits\n"); return paySchedule[bet-1][2]; } else if(fullHouse){ Print("Full House! Won: ", paySchedule[bet-1][3], " credits\n"); return paySchedule[bet-1][3]; } else if(flush){ Print("Flush! Won: ", paySchedule[bet-1][4], " credits\n"); return paySchedule[bet-1][4]; } else if(straight){ Print("Straight! Won: ", paySchedule[bet-1][5], " credits\n"); return paySchedule[bet-1][5]; } else if(threeOfAKind){ Print("Three of a Kind! Won: ", paySchedule[bet-1][6], " credits\n"); return paySchedule[bet-1][6]; } else if(twoPair){ Print("Two Pair! Won: ", paySchedule[bet-1][7], " credits\n"); return paySchedule[bet-1][7]; } else if(tensOrBetter){ Print("Tens or Better! Won: ", paySchedule[bet-1][8], " credits\n"); return paySchedule[bet-1][8]; } else return 0; } /* Checks the hand against the Deuces Wild rules and returns the winnings * based on the specified bet. */ int checkHandDeucesWild(int bet){ bool royalFlush; bool fiveOfAKind; bool fourOfAKind; bool fullHouse; bool flush; bool straight; bool threeOfAKind; int numDeuces; int i; /* Count the number of deuces. */ numDeuces = 0; for(i=0; i<5; i=i+1) if(hand[i].getValue() == 2) numDeuces = numDeuces + 1; /* Sort the hand before doing any checking, it simplifies the checking. */ sortHand(); royalFlush = isRoyalFlush(numDeuces); fiveOfAKind = isFiveOfAKind(numDeuces); fourOfAKind = isFourOfAKind(numDeuces); fullHouse = isFullHouse(numDeuces); flush = isFlush(numDeuces); straight = isStraight(numDeuces); threeOfAKind = isThreeOfAKind(numDeuces); /* Process the checks starting with the best hands. */ if(royalFlush && (numDeuces == 0)){ Print("Natural Royal Flush! Won: ", paySchedule[bet-1][0], " credits\n"); return paySchedule[bet-1][0]; } else if(numDeuces == 4){ Print("Four Deuces! Won: ", paySchedule[bet-1][1], " credits\n"); return paySchedule[bet-1][1]; } else if(royalFlush){ Print("Wild Royal Flush! Won: ", paySchedule[bet-1][2], " credits\n"); return paySchedule[bet-1][2]; } else if(fiveOfAKind){ Print("Five of a Kind! Won: ", paySchedule[bet-1][3], " credits\n"); return paySchedule[bet-1][3]; } else if(straight && flush){ Print("Straight Flush! Won: ", paySchedule[bet-1][4], " credits\n"); return paySchedule[bet-1][4]; } else if(fourOfAKind){ Print("Four of a Kind! Won: ", paySchedule[bet-1][5], " credits\n"); return paySchedule[bet-1][5]; } else if(fullHouse){ Print("Full House! Won: ", paySchedule[bet-1][6], " credits\n"); return paySchedule[bet-1][6]; } else if(flush){ Print("Flush! Won: ", paySchedule[bet-1][7], " credits\n"); return paySchedule[bet-1][7]; } else if(straight){ Print("Straight! Won: ", paySchedule[bet-1][8], " credits\n"); return paySchedule[bet-1][8]; } else if(threeOfAKind){ Print("Three of a Kind! Won: ", paySchedule[bet-1][9], " credits\n"); return paySchedule[bet-1][9]; } else return 0; } /* Checks the hand against the Double Bonus rules and returns the winnings * based on the specified bet. */ int checkHandDoubleBonus(int bet){ bool royalFlush; bool fourAces; bool four2to4; bool four5toK; bool fullHouse; bool flush; bool straight; bool threeOfAKind; bool twoPair; bool jacksOrBetter; /* Sort the hand before doing any checking, it simplifies the checking. */ sortHand(); royalFlush = isRoyalFlush(0); fullHouse = isFullHouse(0); flush = isFlush(0); straight = isStraight(0); threeOfAKind = isThreeOfAKind(0); twoPair = isTwoPair(0); jacksOrBetter = isPairOfValueOrBetter(11, 0); fourAces = isFourOfAKind(0) && ((hand[2].getValue() == 14) || four2to4 = isFourOfAKind(0) && (hand[2].getValue() >= 2) && (hand[2].getValue() <= 4)); four5toK = isFourOfAKind(0) && (hand[2].getValue() >= 5) && (hand[2].getValue() <= 13); /* Process the checks starting with the best hands. */ if(royalFlush){ Print("Royal Flush! Won: ", paySchedule[bet-1][0], " credits\n"); return paySchedule[bet-1][0]; } else if(straight && flush){ Print("Straigh Flush! Won: ", paySchedule[bet-1][1], " credits\n"); return paySchedule[bet-1][1]; } else if(fourAces){ Print("Four Aces! Won: ", paySchedule[bet-1][2], " credits\n"); return paySchedule[bet-1][2]; } else if(four2to4){ Print("Four 2-4! Won: ", paySchedule[bet-1][3], " credits\n"); return paySchedule[bet-1][3]; } else if(four5toK){ Print("Four 5-K! Won: ", paySchedule[bet-1][4], " credits\n"); return paySchedule[bet-1][4]; } else if(fullHouse){ Print("Full House! Won: ", paySchedule[bet-1][5], " credits\n"); return paySchedule[bet-1][5]; } else if(flush){ Print("Flush! Won: ", paySchedule[bet-1][6], " credits\n"); return paySchedule[bet-1][6]; } else if(straight){ Print("Straight! Won: ", paySchedule[bet-1][7], " credits\n"); return paySchedule[bet-1][7]; } else if(threeOfAKind){ Print("Three of a Kind! Won: ", paySchedule[bet-1][8], " credits\n"); return paySchedule[bet-1][8]; } else if(twoPair){ Print("Two Pair! Won: ", paySchedule[bet-1][9], " credits\n"); return paySchedule[bet-1][9]; } else if(jacksOrBetter){ Print("Jacks or Better! Won: ", paySchedule[bet-1][10], " credits\n"); return paySchedule[bet-1][10]; } else return 0; } /* Checks the hand against the Double Double Bonus rules and returns the * winnings based on the specified bet. */ int checkHandDoubleDoubleBonus(int bet){ bool royalFlush; bool fourAcesAnd2to4; bool four2to4AndAto4; bool fourAces; bool four2to4; bool four5toK; bool fullHouse; bool flush; bool straight; bool threeOfAKind; bool twoPair; bool jacksOrBetter; /* Sort the hand before doing any checking, it simplifies the checking. */ sortHand(); royalFlush = isRoyalFlush(0); fullHouse = isFullHouse(0); flush = isFlush(0); straight = isStraight(0); threeOfAKind = isThreeOfAKind(0); twoPair = isTwoPair(0); jacksOrBetter = isPairOfValueOrBetter(11, 0); fourAces = isFourOfAKind(0) && ((hand[2].getValue() == 14) || four2to4 = isFourOfAKind(0) && (hand[2].getValue() >= 2) && (hand[2].getValue() <= 4)); four5toK = isFourOfAKind(0) && (hand[2].getValue() >= 5) && (hand[2].getValue() <= 13); fourAcesAnd2to4 = fourAces && (hand[2].getValue() >= 2) && (hand[2].getValue() <= 4); four2to4AndAto4 = four2to4 && ((hand[4].getValue() == 14) || (hand[0].getValue() == 2) || (hand[0].getValue() == 3) || (hand[0].getValue() == 4)); /* Process the checks starting with the best hands. */ if(royalFlush){ Print("Royal Flush! Won: ", paySchedule[bet-1][0], " credits\n"); return paySchedule[bet-1][0]; } else if(straight && flush){ Print("Straigh Flush! Won: ", paySchedule[bet-1][1], " credits\n"); return paySchedule[bet-1][1]; } else if(fourAcesAnd2to4){ Print("Four Aces w/ 2-4! Won: ", paySchedule[bet-1][2], " credits\n"); return paySchedule[bet-1][2]; } else if(four2to4AndAto4){ Print("Four 2-4 w/ A-4! Won: ", paySchedule[bet-1][3], " credits\n"); return paySchedule[bet-1][3]; } else if(fourAces){ Print("Four Aces! Won: ", paySchedule[bet-1][4], " credits\n"); return paySchedule[bet-1][4]; } else if(four2to4){ Print("Four 2-4! Won: ", paySchedule[bet-1][5], " credits\n"); return paySchedule[bet-1][5]; } else if(four5toK){ Print("Four 5-K! Won: ", paySchedule[bet-1][6], " credits\n"); return paySchedule[bet-1][6]; } else if(fullHouse){ Print("Full House! Won: ", paySchedule[bet-1][7], " credits\n"); return paySchedule[bet-1][7]; } else if(flush){ Print("Flush! Won: ", paySchedule[bet-1][8], " credits\n"); return paySchedule[bet-1][8]; } else if(straight){ Print("Straight! Won: ", paySchedule[bet-1][9], " credits\n"); return paySchedule[bet-1][9]; } else if(threeOfAKind){ Print("Three of a Kind! Won: ", paySchedule[bet-1][10], " credits\n"); return paySchedule[bet-1][10]; } else if(twoPair){ Print("Two Pair! Won: ", paySchedule[bet-1][11], " credits\n"); return paySchedule[bet-1][11]; } else if(jacksOrBetter){ Print("Jacks or Better! Won: ", paySchedule[bet-1][12], " credits\n"); return paySchedule[bet-1][12]; } else return 0; } /* Prints the hand. */ void printHand(){ int line; int card; /* Print headers. */ Print(" "); for(card=0; card<5; card=card+1) if(heldCards[card]) Print(" HELD ", " "); else Print(" ", card+1, " ", " "); Print("\n"); for(line=0; line<9; line=line+1){ Print(" "); for(card=0; card<5; card=card+1){ hand[card].printLine(line); Print(" "); } Print("\n"); } } /* Plays the game. */ void play(){ bool keepPlaying; bool playGame; playGame = startGame(); while(playGame){ keepPlaying = true; while(keepPlaying){ deck.shuffle(); keepPlaying = playHand(); } if(credits <= 0){ Print("Out of credits!\n"); return; } else playGame = startGame(); } } } /* Entrant point of the program, creates a Game object and hands control off to * it. */ void main(){ Game game; /* Print a welcome message. */ Print("\n\nWelcome to Almost Video Poker!\n\n\n"); game = New(Game); game.initGame(); game.play(); /* Print a closing message. */ Print("\n\nThanks for playing Almost Video Poker!\n\n\n"); }