Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Hey guys, this is a video poker simulation with C++, here is the assignment: Vid

ID: 3626604 • Letter: H

Question

Hey guys, this is a video poker simulation with C++, here is the assignment:

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, where each coin is worth $1.00. 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 coins.

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

· Royal Flush - 2000 coins -- 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 coins -- 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 coins -- Four cards of the same value. (Obviously, each of different suits.)

· Full House - 40 coins -- A three of a kind and a pair at the same time.

· Flush - 25 coins -- All cards in your hand are the same suit.

· Straight - 20 coins -- 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 coins -- Three cards of the same value.

· Two Pair - 10 coins -- 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 coins -- Two cards in your hand are the same value. In this version, they must be Jacks or better!

· None of the Above - 0 coins



Each turn "costs" one dollar, 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 a dollar! If you bet more than one 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”

 

7. Use functions only, no class. (Must be broken down ALL into functions i.e. modularlized..what's the point if you can't reuse the code right?)

 

 

 

Here's the code after getting help from SPACTION:

 

#include <iostream>

#include <stdlib.h>

#include <time.h>

 

using namespace std;

 

bool royal(int suit[],int number[]);

bool straightFlush(int suit[],int number[]);

bool fourOfKind(int suit[],int number[]);

bool flush(int suit[],int number[]);

bool straight(int suit[],int number[]);

bool fullHouse(int suit[],int number[]);

bool threeOfKind(int suit[],int number[]);

bool twoPair(int suit[],int number[]);

bool isPair(int suit[],int number[]);

void displayCards(int suit[],int number[]);

 

 

int main()

{

    srand ( time(NULL) );

    int card[4][13];

    //4: 0=heart 1=spade 2=club 3=diamond

    //13: 0=ace,1=2,2=3,3=4,...9=10,10=jack,11=queen,12=king

 

    int suit[5];

    int number[5];

    int cards=0;

    int bet=51;

    int cash=50;

    while(cash!=0 && bet>0)

    {

        for(int i=0;i<4;i++)

        {

           for(int z=0;z<13;z++)

           {

                 card[i][z]=1;

           }

        }

        while(bet>cash || bet==0)

        {

           cout<<"You have "<<cash<<" coins. Please enter a bet between (1-"<<cash<<"):";

           cout<<"(You can also enter any negative number to quit)";

           cin>>bet;

        }

        if(bet>0)

        {

        bet*=5;

        cash-=bet;

        cards=0;

        while(cards<5)

        {

        int s,n;

        do

        {

           s=rand()%4;

           n=rand()%13;

        }

        while(card[s][n]!=1);

        card[s][n]=0;

        suit[cards]=s;

        number[cards]=n;

        cards++;

        }

        displayCards(suit,number);

        int z=2;

        for(int i=0;i<5;i++)

        {

          while(z<0 || z>1)

          {

          cout<<" Do you want to get rid of card "<<i+1<<"?(1=yes, 0=no)";

          cin>>z;

          }

          if(z==1)

          {

             int s,n;

             do

             {

               s=rand()%4;

               n=rand()%13;

             }

             while(card[s][n]!=1);

             card[s][n]=0;

             suit[i]=s;

             number[i]=n;

          }

          z=-1;

        }

        displayCards(suit,number);

 

             int temps[5];

             int tempn[5];

             int min=number[0];

             int minloc=0;

             for(int i=0;i<5;i++)

             {

             for(int z=0;z<5;z++)

             {

              if(min>number[z])

              {

                min=number[z];

                minloc=z;

              }

             }

             tempn[i]=min;

             temps[i]=suit[minloc];

             number[minloc]=20;

             suit[minloc]=20;

             min=20;

             }

             for(int i=0;i<5;i++)

             {

                suit[i]=temps[i];

                number[i]=tempn[i];

             }

 

 

        if(royal(suit,number))

        {

          cout<<" You just got a Royal Flush!!!"<<endl;

          cout<<"You've won "<<2000*bet/5<<" coins"<<endl;

          cash+=2000*bet/5;

        }

        else if(straightFlush(suit,number))

        {

          cout<<" You just got a Stright Flush!!!"<<endl;

          cout<<"You've won "<<250*bet/5<<" coins"<<endl;

          cash+=250*bet/5;

        }

        else if(fourOfKind(suit,number))

        {

          cout<<" You just got four of a kind!!!"<<endl;

          cout<<"You've won "<<125*bet/5<<" coins"<<endl;

          cash+=125*bet/5;

        }

        else if(fullHouse(suit,number))

        {

          cout<<" You just got a full house!!!"<<endl;

          cout<<"You've won "<<40*bet/5<<" coins"<<endl;

          cash+=40*bet/5;

        }

        else if(flush(suit,number))

        {

          cout<<" You just got a Royal Flush!!!"<<endl;

          cout<<"You've won "<<25*bet/5<<" coins"<<endl;

          cash+=25*bet/5;

        }

        else if(straight(suit,number))

        {

          cout<<" You just got a straight!!!"<<endl;

          cout<<"You've won "<<20*bet/5<<" coins"<<endl;

          cash+=20*bet/5;

        }

        else if(threeOfKind(suit,number))

        {

          cout<<" You just got three of a kind!!!"<<endl;

          cout<<"You've won "<<15*bet/5<<" coins"<<endl;

          cash+=15*bet/5;

        }

        else if(twoPair(suit,number))

        {

          cout<<" You just got two pair!!!"<<endl;

          cout<<"You've won "<<10*bet/5<<" coins"<<endl;

          cash+=10*bet/5;

        }

        else if(isPair(suit,number))

        {

          cout<<" You just got a pair!!!"<<endl;

          cout<<"You've won "<<5*bet/5<<" coins, breaking even"<<endl;

          cash+=5*bet/5;

        }

        else

        {

            cout<<"Sorry you didnt get anything! You've lost "<<bet<<" coins"<<endl;

        }

        bet=cash+1;

        }

    }

    cout<<" Thanks for playing! ";

}

 

void displayCards(int suit[],int number[])

{

     cout<<"Your hand is:"<<endl;

        for(int i=0;i<5;i++)

        {

        if(number[i]==0)

           cout<<"Ace";

        else if(number[i]>0&&number[i]<10)

           cout<<number[i]+1;

        else if(number[i]==10)

           cout<<"Jack";

        else if(number[i]==11)

           cout<<"Queen";

        else

           cout<<"King";

        cout<<" of ";

        if(suit[i]==0)

           cout<<"hearts";

        else if(suit[i]==1)

           cout<<"spades";

        else if(suit[i]==2)

           cout<<"clubs";

        else

           cout<<"diamonds";

        cout<<endl;

        }

}

 

bool royal(int suit[],int number[])

{

     bool ace=false,king=false;

     if(straight(suit,number)&&flush(suit,number))

      for(int i=0;i<5;i++)

      {

         if(number[i]==0)

           ace=true;

         else if(number[i]==12)

           king=true;

      }

     if(ace && king)

       return true;

     else

       return false;

}

bool straightFlush(int suit[],int number[])

{

     if(straight(suit,number) && flush(suit,number))

       return true;

     else

       return false;

}

bool fourOfKind(int suit[],int number[])

{

     int location;

     for(int i=1; i<5;i++)

     {

        if(number[0]!=number[i])

          location =i;

     }

     for(int i=1;i<5;i++)

     {

        if(number[0]!=number[i] && number[location]!=number[i])

          return false;

     }

     int num=0;

     int num2=0;

     for(int i=0;i<5;i++)

     {

       if(number[0]-number[i]==0)

         num++;

       else if(number[location]-number[i]==0)

         num2++;

     }

     if(num==4 || num2==4)

       return true;

     else

       return false;

}

bool flush(int suit[],int number[])

{

     for(int i=1;i<5;i++)

     {

        if(suit[i]!=suit[0])

           return false;

     }

     return true;

}

bool straight(int suit[],int number[])

{

     if(number[0]!=0)

     {

        for(int i=0;i<4;i++)

        {

           if(number[i]+1!=number[i+1])

             return false;

        }

        return true;

     }

     else

     {

         bool in=true;

         for(int i=0;i<4;i++)

         {

            if(number[i]+1!=number[i+1])

              in=false;

         }

         if(in)

           return true;

         else

         {

            if(number[0]==0 && number[1]==9 && number[2]==10 && number[3]==11 && number[4]==12)

              return true;

            else

              return false;

         }

     }

}

bool fullHouse(int suit[],int number[])

{

     int location;

     for(int i=1; i<5;i++)

     {

        if(number[0]!=number[i])

          location =i;

     }

     for(int i=1;i<5;i++)

     {

        if(number[0]!=number[i] && number[location]!=number[i])

          return false;

     }

     int num=0;

     int num2=0;

     for(int i=0;i<5;i++)

     {

       if(number[0]-number[i]==0)

         num++;

       else if(number[location]-number[i]==0)

         num2++;

     }

     if((num==3 && num2==2) || (num==2 && num2==3))

       return true;

     else

       return false;

}

bool threeOfKind(int suit[],int number[])

{

     int location, location2;

     for(int i=1; i<5;i++)

     {

        if(number[0]!=number[i])

          location =i;

     }

     for(int i=1;i<5;i++)

     {

        if(number[0]!=number[i] && number[location]!=number[i])

          location2=i;

     }

     int num=0;

     int num2=0;

     int num3=0;

     for(int i=0;i<5;i++)

     {

       if(number[0]-number[i]==0)

         num++;

       else if(number[location]-number[i]==0)

         num2++;

       else if(number[location2]-number[i]==0)

         num3++;

     }

     if(num==3 || num2==3 || num3==3)

       return true;

     else

       return false;

}

bool twoPair(int suit[],int number[])

{

     int location, location2, location3;

     for(int i=1; i<5;i++)

     {

        if(number[0]!=number[i])

          location =i;

     }

     for(int i=1;i<5;i++)

     {

        if(number[0]!=number[i] && number[location]!=number[i])

          location2=i;

     }

     for(int i=1;i<5;i++)

     {

        if(number[0]!=number[i] && number[location]!=number[i] && number[location2]!=number[i])

          location3=i;

     }

     int num=0;

     int num2=0;

     int num3=0;

     int num4=0;

     for(int i=0;i<5;i++)

     {

       if(number[0]-number[i]==0)

         num++;

       else if(number[location]-number[i]==0)

         num2++;

       else if(number[location2]-number[i]==0)

         num3++;

       else if(number[location3]-number[i]==0)

         num4++;

     }

     if((num==2 && (num2==2 || num3==2 || num4==2))|| (num2==2 && (num3==2 || num4==2)) || (num3==2 && num4==2))

       return true;

     else

       return false;

}

bool isPair(int suit[],int number[])

{

     int location,loc2,loc3;

     for(int i=1; i<5;i++)

     {

        if(number[0]!=number[i])

          location =i;

     }

     for(int i=1; i<5;i++)

     {

        if(number[0]!=number[i] && number[location]!=number[i])

          loc2 =i;

     }

     for(int i=1; i<5;i++)

     {

        if(number[0]!=number[i] && number[location]!=number[i]&&number[loc2]!=number[i])

          loc3=i;

     }

     for(int i=1;i<5;i++)

     {

        if(number[0]!=number[i] && number[location]!=number[i]&&number[loc2]!=number[i] && number[loc3]!=number[i])

          return false;

     }

     return true;

}

 


 

What I need help with (@ Spaction):

 

1. Modularize the code, that is, break them all into functions, i.e. the "int main()" part.

 

2. The game must be able to load/save, refer to requirements #3

 

3. The scoring must be correct. (the code given needs correcting)

Explanation / Answer

http://oron.com/numyw68gi73a/PokerGame.cc.html The file is in the link, i couldnt finish it all, i tried doing the load/save and it just literally blew up in my face for about 3 hours. Well, im done, if you want to rate the one it would be greatly appreciated, on this one it doesnt matter, something would be nice, but unfortunately i couldnt finish it 100%, the only difference with this one is some commented code for the save and load and the addition of a play again feature. Hope this helps, and now im off to sleep