Thread: Video Poker game come back!

  1. #1
    Registered User
    Join Date
    May 2007

    Video Poker game come back!

    Ok,guys!With lots of work I did,I finish the computepoints,but there are still problems here:
    my again() doesn't work;
    #include <cstdlib>
    #include <iostream>
    #include <math.h>
    #include <time.h>
    #include <string>
    #include <fstream>
    using namespace std;
    void loadDeck(string suits[4], string faceValue[13])
         ifstream in; "C:\\Dev-Cpp\\my project\\New Folder\\cards.dat");
            cout<<"Deck of cards not found, program ending"<<endl;
         for(int i=0; i<4; i++)
         for(int i=0; i<13; i++)
    void shuffle( bool cards[52], int hand[5])
         for(int i=0;i<52; i++)
            cards[i] = false;
         for(int i=0; i<5; i++)
            hand[i] = -1;
    void deal(bool card[], int hand[], int pos)
         int dealt;
         hand[pos] = dealt;
         card[dealt] = true;
    void initialDeal(bool card[], int hand[])
         for(int i=0; i<5; i++)
             deal(card, hand, i);
    void discard(bool card[], int hand[])
         char str[80];
         cout<<"Which cards would you like to discard: ";
         cin.getline(str, '\n',80);
         char * pch;
         pch = strtok (str," ,.-");
         while (pch != NULL)
            deal(card, hand, atoi(pch));
            pch = strtok (NULL, " ,.-");
    void display(int hand[], string suits[], string faceValue[])
         cout<<"The cards in your hand are: "<<endl;
         for(int i=0; i<5; i++)
            cout<<i<<".  "<<faceValue[hand[i]%13]<<" of "<<suits[hand[i]%4]<<endl;
    //          cout<<hand[i]<<endl;
    bool again()
         string ans;
         cout<<"Do you want to do this again? ";
         return (toupper(ans[0]) == 'Y');
    int computepoints(int hand[],string suits[],string faceValue[],int points,int count13[],int count4[])
          for(int j=0;j<13;j++)
          for (int  p=0;p<4;p++)
        for(int i=0;i<5;i++)
           for(int j=0;j<13;j++)
          { if(faceValue[hand[i]%13]==faceValue[j])
           for (int  p=0;p<4;p++)
           {  if(suits[hand[i]%4]==suits[p])
        for(int j=0;j<13;j++)
      { if(count13[j]==2)
         { for(int p=j+1;p<13;p++)
           cout<<"Win 2 Pair!"<<endl;
           cout<<"Good!You got A Pair!"<<endl;
        {  if(count13[j]==3)
          for(int p=j+1;p<13;p++)
            cout<<"Wow!You got A Full House!"<<endl;
            cout<<"Nice!You got A Three of a Kind!"<<endl;
            cout<<"Excellent!You got A Four of a Kind!"<<endl;
            for(int p=0;p<4;p++)
             { if((count13[0]==1)&&(count13[9]==1)&&(count13[10]==1)&&(count13[11]==1)&&(count13[12]==1))
               cout<<"Royal Flush!"<<endl;
               cout<<"Flush!"<<endl;} }
            for(int i=0;i<13;i++)
                  for(int p=0;p<4;p++)
                    cout<<"straight Flush!"<<endl;
    int main(int argc, char *argv[])
        string suits[4],faceValue[13];
        bool cards[52];
        int hand[5],points,count13[13],count4[4];
        loadDeck(suits, faceValue);
           shuffle(cards, hand);
           initialDeal(cards, hand);
           display(hand, suits, faceValue);
           discard(cards, hand);
           display(hand, suits, faceValue);
        return EXIT_SUCCESS;

    this is our project:
    Video Poker Simulation

    Acme Software, Inc, has been contracted to write a Video Poker Simulation game in basic C++ that follows the following rules:

    Basic Setting:

    The player places an initial bet between one (1) and fifty (50) coins. The player is then dealt five (5) cards and allowed to choose which cards, if any, they wish to keep. The cards that they do not wish to keep are discarded, and replacement cards are dealt so that they again have a total of five (5) cards. The computer then determines what amount they have won, if any.

    Card Ranks and Suits:

    Cards are ranked, from highest to lowest:

    · Ace

    · King

    · Queen

    · Jack

    · Ten

    · Nine

    · Eight

    · Seven

    · Six

    · Five

    · Four

    · Three

    · Two

    · Ace

    (Ace can count as either low or high. See "Royal Flush"'s scoring, below.)

    The card suits are: Hearts, Clubs, Diamonds, and Spades

    Hand Ranks:

    When you are dealt replacement cards for your discards, your new hand is evaluated. Based on what kind of hand you're holding, you'll receive a certain number of points.

    Hands are listed below, from best (highest scoring), to worst (no score):

    · Royal Flush - 2000 points

    A straight flush, with the Ace high.

    In other words, a Ten, Jack, Queen, King and Ace, all of the same suit.

    · Straight Flush - 250 points

    A straight flush.

    In other words, all five cards are consecutive and are the same suit.

    For example: Three of Clubs, Four of Clubs, Five of Clubs, Six of Clubs and Seven of Clubs.

    · Four of a Kind - 125 points

    Four cards of the same value. (Obviously, each of different suits.)

    · Full House - 40 points

    A three of a kind and a pair at the same time.

    · Flush - 25 points

    All cards in your hand are the same suit.

    · Straight - 20 points

    All five cards are consecutive.

    For example: Three of Clubs, Four of Spades, Five of Clubs, Six of Diamonds, and Seven of Hearts.

    · Three of a Kind - 15 points

    Three cards of the same value.

    · Two Pair - 10 points

    Two pairs of cards.

    In other words, two cards in your hand are the same value, and two other cards in your hand are also the same value.

    · Pair - 5 points

    Two cards in your hand are the same value. In this version, they must be Jacks or better!

    · None of the Above - 0 points

    Each turn "costs" 5 dollars, so if you get a pair, no money actually end up added to your total score. If you don't get anything, you actually lose five dollars! If you bet more than one 5 dollar coin, then the returns above are multiplied by the number of coins entered to give the actual yield. This is just how handheld and Vegas video poker games actually work!

    Project Requirements:

    Your project must meet the following specifications:

    1. Text-based display of what is in the player’s hand.
    2. Read all cards to be discarded at once
    3. Read from the command line as a program parameter the name of a file that contains the state of a previous game so that a player can resume a game at any point. Thus, your program must read and write to a file as well as verify that a file exists.
    4. Provided adequate “help” for the player on how to play the game.
    5. Score all hands correctly.
    6. Know the player’s name and be “friendly”

    Extra Credit:

    1. (100 points) Mouse and graphical input
    2. (50 points) Sound / music
    3. (50 points) "Dueces Wild" Same as above, but with each of the "Dueces" (a two) being a "Wild Card." Your program then must calculate the highest return that each two will yield the player.
    And also I want to try graphics since it is extra credit.I am sure that our professor doesn't tell us anything about it.He just introduce us wxwidgets to use.So can anyone give me some information about it?

  2. #2
    Registered User
    Join Date
    May 2007
    This is our cards.dat:
    and also :after discard cards,the system didn't response unless after you entering a number of return key.Some one told me add ignore(1000,"/n")(something like that)after,but
    it didn't work.So how to fix that?

  3. #3
    Registered User
    Join Date
    Jan 2005
    >> With lots of work I did,I finish the computepoints

    >> my again() doesn't work
    Can you be more specific?

    >> also :after discard cards,the system didn't response unless after you entering a number of return key.
    I haven't tried it myself, but since you use both getline and cin >> to read in data from the user, you have to be careful about the newline. Basically, when you use cin >> and the user types in some information, they hit <enter> to send that data to cin. The <enter> leaves a newline character ('\n') in the stream. Later, if you call getline, the getline function reads that newline and stops, since it is designed to read until the first newline it finds.

    The solution is usually to add cin.ignore() (or cin.ignore(1000, '\n')) after all calls to cin >> so that the newline at the end is ignored. You should not add a call to ignore() after calls to getline, because getline automatically removes the trailing newline.

  4. #4
    Registered User
    Join Date
    May 2007
    Daved,thank you for reply me.
    This is the detail:
    you can see I add your thing there,and when I discard cards I must enter enough return keys to get the new cards.

  5. #5
    Registered User
    Join Date
    May 2007
    And also for the computpoints,I try a lot of things and find use 13 bins!means:I make 13 bins for 13 facevalue and 4bins for 4 suits,so when I get my 5 cards,I just count how many ace(or others) I have,then from the array count13[] and count4[],if count13[i](i<13)==2,means a pair I get and so on.It is really a good idea!Ho~~~Ho~~~~Ho!

  6. #6
    Registered User
    Join Date
    Jan 2005
    It looks like you did the opposite of what I suggested. You can (usually) safely call cin.ignore() after calls to cin >>. You should not use cin.ignore() after a call to getline.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. 2D RPG Online Game Project. 30% Complete. To be released and marketed.
    By drallstars in forum Projects and Job Recruitment
    Replies: 2
    Last Post: 10-28-2006, 12:48 AM
  2. Game Engine Link Prob
    By swgh in forum Game Programming
    Replies: 2
    Last Post: 01-26-2006, 12:14 AM
  3. Poker Game need help...
    By boyracer88 in forum Game Programming
    Replies: 1
    Last Post: 11-25-2005, 01:32 PM
  4. Poker Game
    By Smiley**123 in forum Game Programming
    Replies: 6
    Last Post: 12-14-2003, 09:48 AM
  5. poker game yooo
    By datainjector in forum C Programming
    Replies: 6
    Last Post: 09-17-2002, 05:50 AM