Poker Game

This is a discussion on Poker Game within the C Programming forums, part of the General Programming Boards category; I nedd help with the dealDeck function at the end and for some reason I keep getting the same card ...

  1. #1
    Registered User
    Join Date
    Oct 2004
    Posts
    34

    Poker Game

    I nedd help with the dealDeck function at the end and for some reason I keep getting the same card number, an Ace of Hearts...
    Any help would be appreciated...Thanks

    Code:
    /* Shuffling 52 random cards and displaying the results using functions and pointers. */
    #include <stdio.h>
    #include <time.h>
    
    char faces[]={"0023456789TJQKA"};
    
    typedef enum {
    	eHearts = 3,
    	eDiamonds,
    	eClubs,
    	eSpades
    } CardSuit;
    
    typedef struct {
    	char  faceValue;
    	CardSuit  suitValue;
    } Card;
    
    /* Declaring the functions that are going to be used */
    void filldeck(Card *);
    void shuffledeck(Card *);
    void dealdeck(Card *, Card handsdelt [4][52]);
    
    /* Main used to test functions */
    void main(void) 
    {
    
    	char i;
    	Card Deck[52];
    	Card *deckptr;
    	deckptr = Deck;
    
    	filldeck(deckptr);
    
    	for(i=0;i<5;i++)
    	{
    		printf("%c-%c\n",faces[deckptr->faceValue],deckptr->suitValue);
    		
    	}
    }
    /* filldeck()
    * Description:
    * Initializes the deck. 
    *
    * Returns:
    * Void function...
    *
    * Parameters:
    * A pointer to the array of card structures. 
    *
    * Error Codes:
    * NONE
    *
    */
    
    void filldeck(Card *deckptr)
    {
    	char x;
    	char y;
    	
    	for(x=3;x<7;x++)
    	{
    		for(y=2;y<15;y++)
    		{
    			deckptr -> suitValue = x;
    			deckptr -> faceValue = y;
    		}
    		deckptr++;
    	}
    }
    /* shuffledeck()
    * Description:
    * Shuffles the deck.
    *
    * Returns:
    * Void function...
    *
    * Parameters:
    * A pointer to the array of card structures. 
    *
    * Error Codes:
    * NONE
    *
    */
    
    void shuffledeck(Card *deckptr)
    {
    	Card temp, *cardptr;
    	int i,x;
    
    	for(i=0;i<53;i++)
    	{
    		x = rand()%52;
    		cardptr = deckptr + x;
    
    		temp = *cardptr;
    		*cardptr = *deckptr;
    		*deckptr = temp;
    
    		deckptr + 1;
    	}
    
    }
    /* dealdeck()
    * Description:
    * Deals and prints the hands of cards.
    *
    * Returns:
    * Void function...
    *
    * Parameters:
    * A pointer to the array of card structures, and a 2-dimensional array
    * of card structures representing the players hands.
    *				ex:	handDelt[Number_of_Players] [Number_of_Cards]
    *
    * Error Codes:
    * NONE
    *
    */
    
    void dealdeck(Card *deckptr , Card handsDelt [4][52])
    {
    
    }

  2. #2
    Helper
    Join Date
    Jun 2004
    Posts
    255
    Quote Originally Posted by egomaster69
    I nedd help with the dealDeck function at the end and for some reason I keep getting the same card number, an Ace of Hearts...
    Any help would be appreciated...Thanks
    First of all, you should fix that...
    Code:
    main.c:26: warning: return type of `main' is not `int'
    main.c: In function `main':
    main.c:37: warning: array subscript has type `char'
    main.c: In function `shuffledeck':
    main.c:93: warning: implicit declaration of function `rand'
    main.c:100: warning: statement with no effect
    main.c: In function `dealdeck':
    main.c:121: warning: unused parameter `deckptr'
    main.c:121: warning: unused parameter `handsDelt'
    In the mean time, I will check your code more deeply...

    Ok. In main(), the pointer in unchanged in the loop. Fix that.

    Note also that the caracters 3 to 6 may represent Heart, Spade etc, or not. It depends on the system.
    Last edited by Emmanuel Delaha; 01-02-2005 at 03:13 PM.
    Emmanuel Delahaye

    "C is a sharp tool"

  3. #3
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    No need to check deeply. They don't seed rand. I suggest reading the FAQ entry on random number genneration. Or perhaps simply searching the forum. (Hint: srand)

    Quzah.
    Hope is the first step on the road to disappointment.

  4. #4
    Registered User
    Join Date
    Oct 2004
    Posts
    34
    I have fixed all of them except the rand() and the last two...I need help with the function...Thanks for some reason my compiler didn't catch those...

  5. #5
    Registered User
    Join Date
    Oct 2004
    Posts
    34
    okay i fixed the random numbers but can anyone help me with the last function...thanx

  6. #6
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    The last two should be obvious: You don't do anything in the function, and just like the warning says, those arguments aren't being used.

    The function should be easy. Just write out the steps you yourself would take to deal a hand of cards. Break each step down into smaller and smaller pieces, and then turn it into code.


    Quzah.
    Hope is the first step on the road to disappointment.

  7. #7
    Handy Andy andyhunter's Avatar
    Join Date
    Dec 2004
    Posts
    540
    What exactly are you stuck with? I don't think anyone is going to write the whole thing for you, it would defeat the purpose of trying to learn the language.
    i don't think most standard compilers support programmers with more than 4 red boxes - Misplaced

    It is my sacred duity to stand in the path of the flood of ignorance and blatant stupidity... - quzah

    Such pointless tricks ceased to be interesting or useful when we came down from the trees and started using higher level languages. - Salem

  8. #8
    Funniest man in this seat minesweeper's Avatar
    Join Date
    Mar 2002
    Posts
    801
    Not sure if you fixed it all yet but this bit:

    Code:
    for(x=3;x<7;x++)
    {
    for(y=2;y<15;y++)
    {
    deckptr -> suitValue = x;
    deckptr -> faceValue = y;
    }
    deckptr++;
    }
    only fills the deck with 4 cards.

    Have a think about how often you call deckptr++;

  9. #9
    Funniest man in this seat minesweeper's Avatar
    Join Date
    Mar 2002
    Posts
    801
    Oh, and it prints the same card 4 times cos you don't modify deckptr here:

    for(i=0;i<5;i++)
    {
    printf("%c-%c\n",faces[deckptr->faceValue],deckptr->suitValue);

    }

  10. #10
    Registered User
    Join Date
    Oct 2004
    Posts
    34
    how would i go about modifying deckptr...sorry but im just really confused right now

  11. #11
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Quote Originally Posted by minesweeper
    Not sure if you fixed it all yet but this bit:

    Code:
    for(x=3;x<7;x++)
    {
    for(y=2;y<15;y++)
    {
    deckptr -> suitValue = x;
    deckptr -> faceValue = y;
    }
    deckptr++;
    }
    only fills the deck with 4 cards.

    Have a think about how often you call deckptr++;
    Not a very good solution. Seriously, just think out how you deal cards.
    Code:
    while you haven't dealt enough cards:
        for each player:
            take one card off the pile and give it to the player
    Really, was it that confusing? That's why I said: Write down what YOU would do to deal cards.


    Quzah.
    Hope is the first step on the road to disappointment.

  12. #12
    Funniest man in this seat minesweeper's Avatar
    Join Date
    Mar 2002
    Posts
    801
    Quote Originally Posted by quzah
    Not a very good solution. Seriously, just think out how you deal cards.
    Eh? I was pointing to en error in the code he provided. I didn't provide a solution for dealing cards.

  13. #13
    Registered User
    Join Date
    Oct 2004
    Posts
    34
    okay so heres what i have and this isnt running at all rite now

    Code:
    /* Shuffling 52 random cards and displaying the results using functions
       and pointers. */
    #include <stdio.h>
    #include <stdlib.h>
    #include <time.h>
    
    char faces[]={"0023456789TJQKA"};
    
    typedef enum {
    	eHearts = 3,
    	eDiamonds,
    	eClubs,
    	eSpades
    } CardSuit;
    
    typedef struct {
    	char  faceValue;
    	CardSuit  suitValue;
    } Card;
    
    /* Declaring the functions that are going to be used */
    void filldeck(Card *);
    void shuffledeck(Card *);
    void dealdeck(Card *, Card handsdelt [4][52]);
    
    /* Main used to test functions */
    int main(void) 
    {
    	char i;
    	Card Deck[52];
    	Card *deckptr;
    	Card handsDelt[4][52];
    	deckptr = Deck;
    
    	filldeck(deckptr);
    	shuffledeck(deckptr);
    	dealdeck(deckptr , handsDelt[][52]);
    
    	return 0;
    }
    /* filldeck()
    * Description:
    * Initializes the deck. 
    *
    * Returns:
    * Void function...
    *
    * Parameters:
    * A pointer to the array of card structures. 
    *
    * Error Codes:
    * NONE
    *
    */
    void filldeck(Card *deckptr)
    {
    	char x;
    	char y;
    	
    	for(x=3;x<7;x++)
    	{
    		for(y=2;y<15;y++)
    		{
    			deckptr -> suitValue = x;
    			deckptr -> faceValue = y;
    		}
    		deckptr++;
    	}
    	return; 
    }
    /* shuffledeck()
    * Description:
    * Shuffles the deck.
    *
    * Returns:
    * Void function...
    *
    * Parameters:
    * A pointer to the array of card structures. 
    *
    * Error Codes:
    * NONE
    *
    */
    void shuffledeck(Card *deckptr)
    {
    	Card temp, *cardptr;
    	int i,x;
    
    	srand(time(NULL));
    
    	for(i=0;i<53;i++)
    	{
    		x = rand()%52;
    		cardptr = deckptr + x;
    
    		temp = *cardptr;
    		*cardptr = *deckptr;
    		*deckptr = temp;
    
    		deckptr + 1;
    	}
    	return; 
    }
    /* dealdeck()
    * Description:
    * Deals and prints the hands of cards.
    *
    * Returns:
    * Void function...
    *
    * Parameters:
    * A pointer to the array of card structures, and a 2-dimensional array
    * of card structures representing the players hands.
    *				ex:	handDelt[Number_of_Players] [Number_of_Cards]
    *
    * Error Codes:
    * NONE
    *
    */
    void dealdeck(Card *deckptr , Card handsDelt [4][52])
    {
    	int i;
    	
    	for(i=0;i<5;i++)
    	{
    		printf("%c-%c\n",faces[deckptr->faceValue],deckptr->suitValue);
    		
    	}
    	return;
    }
    Last edited by egomaster69; 01-02-2005 at 03:54 PM. Reason: removing my name from the program

  14. #14
    Helper
    Join Date
    Jun 2004
    Posts
    255
    Quote Originally Posted by egomaster69
    okay so heres what i have and this isnt running at all rite now
    Code:
    	dealdeck(deckptr , handsDelt[][52]);
    What do you meant here ? It's not C.
    Code:
    	for(x=3;x<7;x++)
    	{
    		for(y=2;y<15;y++)
    		{
    			deckptr -> suitValue = x;
    			deckptr -> faceValue = y;
    		}
    		deckptr++;
    Don't you read the advices you received? This deckptr++; is not at the right place. Shake your brain!
    Code:
    		deckptr + 1;
    What is this ?

    Do you meant
    Code:
    		deckptr++;
    Emmanuel Delahaye

    "C is a sharp tool"

  15. #15
    ---
    Join Date
    May 2004
    Posts
    1,379
    Have a look at my poker game i made a few weeks ago.
    It is very incomplete (like everything i make), but it will definitely help you out. Remember to rename the file.

    NOTE: the check_card_strength() function is not working.
    Attached Files Attached Files

Page 1 of 2 12 LastLast
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

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