Very simple card game

Hi,
For my college assignment, I choose to make a very simple card game in which there would be four players [ 1 Human and 3 Comps ]
Each get 13 cards each, game ends in 4 hands, each one gets to start one hand, and the player with the highest number of tricks wins.

I'll think of upgrading this to something cooler if time permits

I just have 'planned' the coding so far and I wan't to share it with you, please correct me if you think you should or you have better ideas.

I'm planning to make a class 'players' with variables like Name, tricks, position, and a 13sized array for the cards, and will contain the play().

In the global area, there will be four 13sized arrays for each suit
Eg: char spades[13]={S2,S3,S4,S5,S6,S7,S8,S9,S10,S_J,S_Q,S_K,S_A}

Now can anyone just guide me as in to

1] how to get the cards into player's cards array randomly
and
2] If a player starts with a suit then how to code to stop a player from playing an illegal suit
and lastly
3] How to code to decide which of the cards is the largest and wins the trick since the data-type is char ?
I don't know exactly how to do it but what about using the rand() fuction?

You would need to limit it so that it can only output numbers between 0 - 53, these being the numbers within the deck of cards.

If the order of arrays went Hearts, Spades, Clubs, Diamonds, a 2 of hearts would go to the player if the rand() function output a 0 (or 1 if you play with aces low). and a 2 of spades would go if the output was 13 (or 14 if aces low)

then to make sure duplicate cards are not throw, use another array that has like all the cards thrown, then before the card is thrown you use an if() and check again the array.

I have no idea on how to do it, but that would be a way to investigate. Check out the TUT on the rand() function. It can be found here:

http://www.cplusplus.com/reference/clibrary/cstdlib/rand.html

I am sure someone else will give you a better solution, but I thought I may have a good idea... HAHAHA me with a good idea!!! I make myself laugh!!!!
Actually, for doing something like that, I would put all 52 (not 54) cards into a single array.. then loop 52 times, each time getting a random number between 0 and the number of cards minus one, copy that element to a new array and remove it from the first. (thus lowering the number of cards by one, and shifting all cards after down one)

That would be literally like shuffling the deck.
I've been playing with my own version of the BlackJack game (inspired by QWERTYman's tread in the Lounge), and the way I did it was to define several classes.

A "Card" class, which does nothing but represent a card (including overloaded insertion and extraction operators for I/O).

A "Hand" class, which is really a vector <Card> with a few extra methods (like value() to get the value of the hand and blackjack() to indicate whether or not the hand is a blackjack).

A "Deck" class which dispenses cards randomly (via the deal() method) and keeps track of which cards are in the deck, etc.

This has made it particularly easy to manipulate the game. Each round, every player who hits gets a new card deal()t from the shoe deck and appended to their hand, then each player is tested for blackjack, bust, etc., and winnings are updated, etc.

I think such an organization would be beneficial to your problem and would make each of your questions trivial to fix. Your "Players" class would correspond to my "Hand" class.

Just some food for thought.
Topic archived. No new replies allowed.