Thread: Poker Game

  1. #1
    Registered User
    Join Date
    Dec 2003
    Posts
    4

    Poker Game

    Help…I’m trying to create a poker game but not with the standard shuffle. I have to hard code what cards I want. Then write functions to accomplish each of the following:
    Determine if the hand contains: a pair, two pairs, three of a kind, and so forth.
    Any help would be appreciated.

    Code:
    #include <iostream>
    using std::cout;
    using std::ios;
    
    #include <iomanip>
    
    using std::setw;
    using std::setiosflags;
    
    #include <cstdlib>
    
    void deal ( const int [] [13], const char *[], const char *[] );
    
    int main()
    {
    	const char *suit[ 4 ] =                               //Initialize the suit array
    	{"   Hearts", "   Diamonds","Clubs", "   Spades"};
    	const char *face[ 13 ] =                              //Initialize the face array
    	{"Ace ", "Deuce ", "Three ", "Four ", 
    	 "Five ", "Six ", "Seven ", "Eight ",
    	 "Nine ", "Ten ", "Jack ", "Queen ", "King "};
    	int deck[ 4 ][ 13 ] =   {0,0,2,3,4}  ;                             //Initialize the deck array
    	
    	deal (deck, face, suit);
    
    	return 0;
    
    
    
    }
    
    void deal ( const int wDeck [] [ 13 ], const char *wFace[],
    		    const char *wSuit[] )
    {
    	for ( int card = 1; card <= 5; card++ )
    
    		for ( int row = 0; row <= 3; row++ )
    
    			for ( int column = 0; column <=12; column++ )
    
    				if (wDeck [row] [column] == card )
    					cout << setw (10) << setiosflags (ios::right)
    					     << wFace [column] << "of"
    					     << setw (8) <<setiosflags (ios::left)
    				         << wSuit[row]
    					     << ( card % 1 == 0 ? '\n' : '\t' );
    }

  2. #2
    Registered User
    Join Date
    May 2003
    Posts
    195
    heres how i did the poker combos in my old poker console thing good luck hope it helps

    Code:
    void combo() { 
    	int ctr;
    	int i,j;
    	int pairnumber=0;
    	bool pair=false;
    	bool twopair=false;
    	bool triple=false;
    	bool quad=false;
    	bool royalstraight=false;
    	bool straight=false;
    	bool straightflush=false;
    	bool royalflush=false;
    	bool flush=false;
    	bool fullhouse=false;
    	//***************************************************SORTING
        int k ;
        int temp ;
    
        for (k=1 ; k<5 ; k++)
        {
            temp=hand[k].number;
    
            for (j=k ; (j>0) && (temp<hand[j-1].number) ; --j)
               
                hand[j].number=hand[j-1].number;
    
             hand[j].number=temp;
        }
    	//***************************************************PAIRS
    	for (i=0; i<4; i++) {
    		if (hand[i].number==hand[i+1].number) {
    			pairnumber++;
    		}
    	}
    	if (pairnumber==1)
    		pair=true;
    	if (pairnumber==2)
    		twopair=true;
    	//***************************************************TRIPLE
    	for (i=0; i<3; i++) {
    		if (hand[i].number==hand[i+1].number && hand[i].number==hand[i+2].number) {
    			triple=true;
    		}
    	}
    	//***************************************************QUAD
    	for (i=0; i<2; i++) {
    		if (hand[i].number==hand[i+1].number && hand[i].number==hand[i+2].number && hand[i].number==hand[i+3].number) {
    			quad=true;
    		}
    	}
    
    	//***************************************************STRAIGHT
    	ctr=1;
    	temp=hand[0].number;
    	for (i=1; i<5; i++) {
    		if (hand[i].number==(temp+ctr))
    			ctr++;
    	}
    //	for (i=0; i<5; i++) {                 OUTPUTTING THE CARD VALUES
    //		cout<<hand[i].number<<endl;
    //	}
    	if (ctr==5)
    		straight=true;
    	//***************************************************ROYAL STRAIGHT
    	if (hand[0].number==1 && hand[1].number==10 && hand[2].number==11 && hand[3].number==12 && hand[4].number==13)
    		royalstraight=true;
    	//***************************************************FULL HOUSE
    	if (((hand[0].number==hand[1].number) && (hand[2].number==hand[3].number && hand[2].number==hand[4].number)) || ((hand[0].number==hand[1].number && hand[2].number==hand[0].number) && (hand[3].number==hand[4].number)))
    		fullhouse=true;
    	//***************************************************FLUSH
    	temp=hand[0].suit;
    	ctr=1;
    	for (i=1; i<5; i++) {
    		if (hand[i].suit==temp)
    			ctr++;
    	}
    	if (ctr==5)
    		flush=true;
    	//***************************************************
    	if (pair && triple)
    		pair=false;
    	if (triple && twopair)
    		twopair=false;
    	if (triple && quad)
    		triple=false;
    	if (straight && flush) {
    		straight=false;
    		flush=false;
    		straightflush=true;
    	}
    	if (royalstraight && flush) {
    		royalstraight=false;
    		flush=false;
    		royalflush=true;
    	}
    	if (fullhouse)
    		triple=false;
    	if (pair)
    		cout<<"You got a pair!"<<endl;
    	if (twopair)
    		cout<<"You got two pairs!"<<endl;
    	if (triple)
    		cout<<"You got a triple!"<<endl;
    	if (quad)
    		cout<<"You got a quadruple!"<<endl;
    	if (straight)
    		cout<<"You got a straight!"<<endl;
    	if (flush)
    		cout<<"You got a flush!"<<endl;
    	if (straightflush)
    		cout<<"You got a straight-flush!"<<endl;
    	if (royalstraight)
    		cout<<"You got a royal straight!"<<endl;
    	if (royalflush)
    		cout<<"You got a royal flush!"<<endl;
    	if (fullhouse)
    		cout<<"You got a fullhouse!"<<endl;
    }

  3. #3
    Registered User
    Join Date
    Dec 2003
    Posts
    4
    Thank you for the reply but when I ran your program it came up with 102 errors.

  4. #4
    Registered User
    Join Date
    May 2003
    Posts
    195
    Its not a program, its just a section of my code...

    I don't have winzip so i cant upload my code right now sorry

  5. #5
    Registered User
    Join Date
    Dec 2003
    Posts
    4
    Ok, I finally figured out how to hard code the cards in but now I'm trying to output the info using the counter. I tried using something similiar to your code above but I just can't seem to figure it out. I'm very green at programming....any help would be welcomed. Here is what I have.
    Code:
    #include <iostream>
    using std::cout;
    using std::endl;
    using std::ios;
    
    #include <iomanip>
    
    using std::setw;
    using std::setiosflags;
    
    #include <cstdlib>
    
    void deal ( const int [] [13], const char *[], const char *[] );
    void check ( const int [][13] );
    void output (const int [][13] );
    
    int main()
    {
    	const char *suit[ 4 ] =                               //Initialize the suit array
    	{"   Hearts", "   Diamonds","Clubs", "   Spades"};
    	const char *face[ 13 ] =                              //Initialize the face array
    	{"Ace ", "Deuce ", "Three ", "Four ", 
    	 "Five ", "Six ", "Seven ", "Eight ",
    	 "Nine ", "Ten ", "Jack ", "Queen ", "King "};
    	int deck[ 4 ][ 13 ] = {0};                            //Initialize the deck array
    
    	deck [0][0] = 1;                                      //Hard code
        deck [0][1] = 2;
    	deck [1][9] = 3;
        deck [2][10] = 4;
    	deck [3][11] = 5;
    
    	deal (deck, face, suit);
    
    	return 0;
    
    }
    
    void deal ( const int wDeck [] [ 13 ], const char *wFace[],
    		    const char *wSuit[] )
    {
    	for ( int card = 1; card <= 5; card++ )
    
    		for ( int row = 0; row <= 3; row++ )
    
    			for ( int column = 0; column <=12; column++ )
    
    				if (wDeck [row] [column] == card )
    					cout << setw (10) << setiosflags (ios::right)
    					     << wFace [column] << "of"
    					     << setw (8) <<setiosflags (ios::left)
    				         << wSuit[row]
    					     << ( card % 1 == 0 ? '\n' : '\t' );
    }
    
    void check ( const int wDeck[][13] )
    {
    	int pairs=0;
    	int triple=0;
    	int quad=0;
    
    	for (int column = 0; column <= 12; column++ )
    	{
    		int counter = 0;
    
    		for (int row = 0; row <4; row++ )
    		{
    			if (wDeck[row][column] != 0 )
    				counter++;
                
    			if (counter == 2)
    				pairs++;
    
    			if(counter ==3)
    				triple++;
    
    			if(counter ==4)
    				quad++;
    				pairs++;
    		}
    	}
    }

  6. #6
    Registered User
    Join Date
    May 2003
    Posts
    195
    Im gonna download winzip and post my full code so you can compile it and stuff. Then i bet it will be a lot easier for you to understand the output and everything.


    Basically its like this: Display() is the function for outputting. As you see, just make the shape of the card first, then output the numbers using a for loop

    Code:
    #include <iostream.h> //standard cout/cin library
    #include <iomanip.h>  //set width command
    #include <windows.h>  //clearscreen
    #include <conio.h>    //getch()
    #include <ctype.h>    //add it cause it's cool
    #include <time.h>     //random numbers every time you run the program
    #include <stdio.h>    //once again cause its cool and the name is unpronounceable
    #include <colors.h>   //self made header for colors and setting position for the cursor
    
    //cannot have doubles of cards
    struct card{
    	int number;
    	char suit;
    	bool select;
    };
    //primenumbers how to pronounce vase  tonights show headlines
    //army website+nba db+hbmud
    //happy hacker
    //presidence etc.............................. magic square maze
    void display();					//displays the cards that you draw
    void choosecards(int & input);  //choose the cards you want to drop
    void redraw();					//redraws cards for you after drop
    void combo();					//tests to see what your hand won
    
    int money, bet;		//unimplemented yet
    int suit;			//the random suit foreach card
    bool samecard;		//unimpletmented yet
    card hand[5];		//you card array
    int i;				//counter variable i
    int selectorpos=6;	//the selector's position (selector to choose what cards to drop)
    
    void main() {
    	int input;									//what key user presses
    	srand(time(NULL));							//sets random cards every game
    	InitColor();								//starts the color header
    	SetColor(WHITE);							//sets the card colors to white
    	money=1000;									//unimplemented
    	for (i=0; i<5; i++)							//sets all of the cards to "don't drop"
    		hand[i].select=false;
    	for (i=0; i<5; i++) {						//generates a random card out of 13 cards
    			hand[i].number=rand()%13+1;			//out of 4 suits
    			suit=rand()%4+1;
    //			cin>>suit;
    			switch(suit) {						//gives according symbol for suits
    			case 1: hand[i].suit='\3'; break;
    			case 2: hand[i].suit='\4'; break;
    			case 3: hand[i].suit='\5'; break;
    			case 4: hand[i].suit='\6'; break;
    		}
    	}
    //	cin>>hand[0].number;						//Only for testing purposes
    //	cin>>hand[1].number;
    //	cin>>hand[2].number;
    //	cin>>hand[3].number;
    //	cin>>hand[4].number;
    
    	display();
    	choosecards(input);
    	while (input!=13) {
    		choosecards(input);
    	}
    	combo();
    }
    void display() {
    	system("cls");
    	cout<<"                       [ P O K E R ]\n\n";
    	cout<<"ÚÄÄÄÄÄÄÄÄÄÄÂÄÄÄÄÄÄÄÄÄÄÂÄÄÄÄÄÄÄÄÄÄÂÄÄÄÄÄÄÄÄÄÄÂÄÄÄÄÄÄÄÄÄÄ¿"<<endl; //displays the top row
    	cout<<"³"<<setw(11)<<"³"<<setw(11)<<"³"<<setw(11)<<"³"<<setw(11)<<"³"<<setw(11)<<"³"<<endl;
    	for (int i=0; i<5; i++) { //prints the number for every card
    		cout<<"³";
    		if(hand[i].number==1) {
    			cout<<setw(8)<<"A"<<hand[i].suit<<" ";
    		}else if(hand[i].number<=10) {
    			cout<<setw(8)<<hand[i].number<<hand[i].suit<<" ";
    		}else if(hand[i].number==11){
    			cout<<setw(8)<<"J"<<hand[i].suit<<" ";
    		}else if(hand[i].number==12){
    			cout<<setw(8)<<"Q"<<hand[i].suit<<" ";
    		}else if(hand[i].number==13){
    			cout<<setw(8)<<"K"<<hand[i].suit<<" ";
    		}
    	}
    	cout<<"³"<<endl;
    	for(i=0;i<8;i++){
    		cout<<"³"<<setw(11)<<"³"<<setw(11)<<"³"<<setw(11)<<"³"<<setw(11)<<"³"<<setw(11)<<"³"<<endl;
    	}
    	for(i=0;i<5;i++) {
    		cout<<"³";
    		if(hand[i].number==1) {
    			cout<<" A"<<hand[i].suit<<setw(8);
    		}else if(hand[i].number<=9) {
    			cout<<" "<<hand[i].number<<hand[i].suit<<setw(8);
    		}else if(hand[i].number==10) {
    			cout<<" "<<hand[i].number<<hand[i].suit<<setw(7);
    		}else if(hand[i].number==11){
    			cout<<" J"<<hand[i].suit<<setw(8);
    		}else if(hand[i].number==12){
    			cout<<" Q"<<hand[i].suit<<setw(8);
    		}else if(hand[i].number==13){
    			cout<<" K"<<hand[i].suit<<setw(8);
    		}
    	}
    	cout<<"³"<<endl;
    	cout<<"ÀÄÄÄÄÄÄÄÄÄÄÁÄÄÄÄÄÄÄÄÄÄÁÄÄÄÄÄÄÄÄÄÄÁÄÄÄÄÄÄÄÄÄÄÁÄÄÄÄÄÄÄÄÄÄÙ"<<endl<<endl;
    }
    
    void choosecards(int & input) {
    	
    	SetPosXYAndColor(selectorpos,16,"^",WHITE);
    
    	if (hand[0].select==true) 
    		SetPosXYAndColor(6,17,"^",WHITE);
    	if (hand[1].select==true) 
    		SetPosXYAndColor(17,17,"^",WHITE);
    	if (hand[2].select==true) 
    		SetPosXYAndColor(28,17,"^",WHITE);
    	if (hand[3].select==true) 
    		SetPosXYAndColor(39,17,"^",WHITE);
    	if (hand[4].select==true) 
    		SetPosXYAndColor(50,17,"^",WHITE);
    	
    	input=getch();
    
    	if (input==75)
    		selectorpos-=11;
    	if (input==77)
    		selectorpos+=11;
    	if (selectorpos<6)
    		selectorpos=50;
    	if (selectorpos>50)
    		selectorpos=6;
    	if (input==32) {
    		switch (selectorpos) {
    		case 6:  hand[0].select=true; break;
    		case 17: hand[1].select=true; break; 
    		case 28: hand[2].select=true; break; 
    		case 39: hand[3].select=true; break; 
    		case 50: hand[4].select=true; break; 
    		}
    	}
    	if (input==13) {
    		system("cls");
    		redraw();		
    	}
    
    	system("cls");
    	display();
    }
    void redraw() {
    	for (int i=0; i<5; i++) {
    		if (hand[i].select==true) {
    			hand[i].number=rand()%13+1;
    			suit=rand()%4+1;
    			switch(suit) {
    			case 1: hand[i].suit='\3'; break;
    			case 2: hand[i].suit='\4'; break;
    			case 3: hand[i].suit='\5'; break;
    			case 4: hand[i].suit='\6'; break;
    			}
    		}
    	}
    	display();
    }
    
    void combo() { 
    	int ctr;
    	int i,j;
    	int pairnumber=0;
    	bool pair=false;
    	bool twopair=false;
    	bool triple=false;
    	bool quad=false;
    	bool royalstraight=false;
    	bool straight=false;
    	bool straightflush=false;
    	bool royalflush=false;
    	bool flush=false;
    	bool fullhouse=false;
    	//***************************************************SORTING
        int k ;
        int temp ;
    
        for (k=1 ; k<5 ; k++)
        {
            temp=hand[k].number;
    
            for (j=k ; (j>0) && (temp<hand[j-1].number) ; --j)
               
                hand[j].number=hand[j-1].number;
    
             hand[j].number=temp;
        }
    	//***************************************************PAIRS
    	for (i=0; i<4; i++) {
    		if (hand[i].number==hand[i+1].number) {
    			pairnumber++;
    		}
    	}
    	if (pairnumber==1)
    		pair=true;
    	if (pairnumber==2)
    		twopair=true;
    	//***************************************************TRIPLE
    	for (i=0; i<3; i++) {
    		if (hand[i].number==hand[i+1].number && hand[i].number==hand[i+2].number) {
    			triple=true;
    		}
    	}
    	//***************************************************QUAD
    	for (i=0; i<2; i++) {
    		if (hand[i].number==hand[i+1].number && hand[i].number==hand[i+2].number && hand[i].number==hand[i+3].number) {
    			quad=true;
    		}
    	}
    
    	//***************************************************STRAIGHT
    	ctr=1;
    	temp=hand[0].number;
    	for (i=1; i<5; i++) {
    		if (hand[i].number==(temp+ctr))
    			ctr++;
    	}
    //	for (i=0; i<5; i++) {                 OUTPUTTING THE CARD VALUES
    //		cout<<hand[i].number<<endl;
    //	}
    	if (ctr==5)
    		straight=true;
    	//***************************************************ROYAL STRAIGHT
    	if (hand[0].number==1 && hand[1].number==10 && hand[2].number==11 && hand[3].number==12 && hand[4].number==13)
    		royalstraight=true;
    	//***************************************************FULL HOUSE
    	if (((hand[0].number==hand[1].number) && (hand[2].number==hand[3].number && hand[2].number==hand[4].number)) || ((hand[0].number==hand[1].number && hand[2].number==hand[0].number) && (hand[3].number==hand[4].number)))
    		fullhouse=true;
    	//***************************************************FLUSH
    	temp=hand[0].suit;
    	ctr=1;
    	for (i=1; i<5; i++) {
    		if (hand[i].suit==temp)
    			ctr++;
    	}
    	if (ctr==5)
    		flush=true;
    	//***************************************************
    	if (pair && triple)
    		pair=false;
    	if (triple && twopair)
    		twopair=false;
    	if (triple && quad)
    		triple=false;
    	if (straight && flush) {
    		straight=false;
    		flush=false;
    		straightflush=true;
    	}
    	if (royalstraight && flush) {
    		royalstraight=false;
    		flush=false;
    		royalflush=true;
    	}
    	if (fullhouse)
    		triple=false;
    	if (pair)
    		cout<<"You got a pair!"<<endl;
    	if (twopair)
    		cout<<"You got two pairs!"<<endl;
    	if (triple)
    		cout<<"You got a triple!"<<endl;
    	if (quad)
    		cout<<"You got a quadruple!"<<endl;
    	if (straight)
    		cout<<"You got a straight!"<<endl;
    	if (flush)
    		cout<<"You got a flush!"<<endl;
    	if (straightflush)
    		cout<<"You got a straight-flush!"<<endl;
    	if (royalstraight)
    		cout<<"You got a royal straight!"<<endl;
    	if (royalflush)
    		cout<<"You got a royal flush!"<<endl;
    	if (fullhouse)
    		cout<<"You got a fullhouse!"<<endl;
    }
    	//GET THE ORDER OF SUITS IN POKEr + ORDER OF HANDS IN POKER
    	//MAKE ACES + ANOTHER CARD WILD
    //void determinesuit(int ) {

  7. #7
    Registered User
    Join Date
    Dec 2003
    Posts
    4
    Thank you kneegrow...Happy Holidays!!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help!For poker game simulation
    By tx1988 in forum C++ Programming
    Replies: 24
    Last Post: 05-25-2007, 09:59 PM
  2. Try my game
    By LuckY in forum A Brief History of Cprogramming.com
    Replies: 14
    Last Post: 09-15-2004, 11:58 AM
  3. HELP!wanting to make full screen game windowed
    By rented in forum Game Programming
    Replies: 3
    Last Post: 06-11-2004, 04:19 AM
  4. My Maze Game --- A Few Questions
    By TechWins in forum Game Programming
    Replies: 18
    Last Post: 04-24-2002, 11:00 PM
  5. world of problems with poker game
    By blight2c in forum C++ Programming
    Replies: 5
    Last Post: 04-21-2002, 08:00 PM