Sunday, August 2, 2009

Help with c card game - dealing?

Hi, i am making a card game in c for a project in college however im having difficulty in figuring out how to deal out cards. i have the deck built and able to shuffle it and all but i don't know how to do the players/dealing. any help would be great!!thank you!

Help with c card game - dealing?
use a random number generator to a pick the cards - you will have to store what cards have been dealt and pick another if it has
Reply:There are lots ways of doing this. It would help to know the type of game you are trying to implement, BJ, Poker, Old Maid, etc. Ask yourself, how are the cards dealt in real life? Then, realize this isn't real life, and you can simulate stuff. Since you already have shuffled, the order really isn't important. For example, in Old Maid where you deal all the cards out,. just divide the cards by the number of players and use a for loop to give out the first fraction and another to give next, etc. There is no real need to alternate. If it is like Black Jack and you have the deck in an array. Have a variable keep track of the number of the cards and always take from the back or highest number of the deck using the card count variable as the indexer of the array. For most part, you are just copying the cards to the player's hand. Remember, this is not real life. All you have do is mark or keep track of a removed card, not actually delete it.
Reply:Store all the cards in a Stack once they are shuffled. Then you can pop() them off the top and wella you got it.





check this out here....
Reply:You probably have the deck in some structure, as an array, a queue, ... You should make an array, queue, struct, or another structure of some kind for each player. Following this logic, you can deal...





int temp = 0;


for(int i = 0; i %26lt; SIZE_OF_DECK; i++)


{


player1[temp] = deck[i];


player2[temp] = deck[++i];


player3[temp] = deck[++i];


//a statement similar to this for each player





temp++;


}


No comments:

Post a Comment