Video Poker game come back!

This is a discussion on Video Poker game come back! within the C++ Programming forums, part of the General Programming Boards category; Ok,guys!With lots of work I did,I finish the computepoints,but there are still problems here: my again() doesn't work; Code: #include ...

  1. #1
    Registered User
    Join Date
    May 2007
    Posts
    67

    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;
    Code:
    #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; 
         in.open("C:\\Dev-Cpp\\my project\\New Folder\\cards.dat");
         if(in.fail())
         {
            in.close();
            cout<<"Deck of cards not found, program ending"<<endl;
            exit(1);
         }
         for(int i=0; i<4; i++)
             in>>suits[i];     
         for(int i=0; i<13; i++)
            in>>faceValue[i];     
             in.close();
    }
    
    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;
         while(card[dealt=rand()%52]);
         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;
         cout<<endl;
    }
    
    
    bool again()
    {
         string ans;
         cout<<"Do you want to do this again? ";
         cin>>ans;
         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++)
           count13[j]=0;
    
          for (int  p=0;p<4;p++)
           count4[p]=0;
    
    
        for(int i=0;i<5;i++)
        {
           for(int j=0;j<13;j++)
          { if(faceValue[hand[i]%13]==faceValue[j])
              count13[j]+=1;}
    
           for (int  p=0;p<4;p++)
           {  if(suits[hand[i]%4]==suits[p])
                count4[p]++;}
                
         }
        for(int j=0;j<13;j++)
      { if(count13[j]==2)
         { for(int p=j+1;p<13;p++)
           {if(count13[p]==2)
           cout<<"Win 2 Pair!"<<endl;
           else
           cout<<"Good!You got A Pair!"<<endl;
           break;}}
        {  if(count13[j]==3)
          for(int p=j+1;p<13;p++)
          {if(count13[p]==2) 
            cout<<"Wow!You got A Full House!"<<endl;
            else
            cout<<"Nice!You got A Three of a Kind!"<<endl;
            break;}}
           if(count13[j]==4)
          {
            cout<<"Excellent!You got A Four of a Kind!"<<endl;
            for(int p=0;p<4;p++)
           {
            if(count4[p]==5)
             { if((count13[0]==1)&&(count13[9]==1)&&(count13[10]==1)&&(count13[11]==1)&&(count13[12]==1))
               cout<<"Royal Flush!"<<endl;
               else
               cout<<"Flush!"<<endl;} }
            for(int i=0;i<13;i++)
            {
               if(count13[i]==1&&count13[i+1]==1&&count13[i+2]==1&&count13[i+3]==1&&count13[i+4]==1)
               {
                  for(int p=0;p<4;p++)
                   {if(count4[p]==5)
                    cout<<"straight Flush!"<<endl;
                    else
                    cout<<"Straight!"<<endl;}}}
                 
    }}}
                       
    int main(int argc, char *argv[])
    {
        string suits[4],faceValue[13];
        bool cards[52];
        int hand[5],points,count13[13],count4[4];
        srand(time(NULL));
        loadDeck(suits, faceValue);
        do
        {
           shuffle(cards, hand);
           initialDeal(cards, hand);
           display(hand, suits, faceValue);
           discard(cards, hand);
           display(hand, suits, faceValue);
           computepoints(hand,suits,faceValue,points,count13,count4);
        }while(again());
        system("PAUSE");
        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
    Posts
    67
    This is our cards.dat:
    Spades
    Hearts
    Clubs
    Diamonds
    Ace
    Two
    Three
    Four
    Five
    Six
    Seven
    Eight
    Nine
    Ten
    Jack
    Queen
    King
    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
    Posts
    7,318
    >> With lots of work I did,I finish the computepoints
    Great!

    >> 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
    Posts
    67
    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.
    Attached Images Attached Images   

  5. #5
    Registered User
    Join Date
    May 2007
    Posts
    67
    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
    Posts
    7,318
    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-25-2006, 11:14 PM
  3. Poker Game need help...
    By boyracer88 in forum Game Programming
    Replies: 1
    Last Post: 11-25-2005, 12:32 PM
  4. Poker Game
    By Smiley**123 in forum Game Programming
    Replies: 6
    Last Post: 12-14-2003, 08:48 AM
  5. poker game yooo
    By datainjector in forum C Programming
    Replies: 6
    Last Post: 09-17-2002, 05:50 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21