Jump to content
  • Advertisement
Sign in to follow this  
vinb

How would you represent a deck of cards?

This topic is 4994 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm experimenting with making a blackjack game and I'm not sure how I want to represent the deck of cards in a class. I was thinking either an array of 52 Card objects which have a suit and a value property. I'm sure a lot of you have done a card game before and I was just wondering what more experienced people have done in the past. Thanks.

Share this post


Link to post
Share on other sites
Advertisement
As a std::deque<Card>, obviously. [smile]

And you might be happy to hear that C++ does have a shuffling function, called std::random_shuffle in the <algorithm> header.

Share this post


Link to post
Share on other sites
I actually looked at this just a few weeks ago. =)

The most natural approach would obviously be to use a std::deque of cards.

A card would then have a value and a suit.

You might not want to limit your "deck" class to 52 cards, but rather an arbitrary number of cards for blackjack where you can play with for instance 4 normal "decks" packed into one.

You then fill a deck using the rules of the current game.

Atleast that was the approach I planned on using, lemme know if it works out =)

Edit: doh, Fruny beat me to it =)

Share this post


Link to post
Share on other sites
I figured if I asked I could avoid making a call to wheel.reinvent(). Are there any other useful things like this that might pertain to card games? I wanted to try a few of them before getting into graphics and stuff.

Share this post


Link to post
Share on other sites
Quote:
Original post by vinb
I figured if I asked I could avoid making a call to wheel.reinvent(). Are there any other useful things like this that might pertain to card games? I wanted to try a few of them before getting into graphics and stuff.

A wise choice. I'd suggest you implement a text version first, just to try your implementation out. =)

Share this post


Link to post
Share on other sites
Quote:
Original post by DEVLiN
You might not want to limit your "deck" class to 52 cards, but rather an arbitrary number of cards for blackjack where you can play with for instance 4 normal "decks" packed into one.

You then fill a deck using the rules of the current game.


Interesting. I was actually thinking of using an array of Deck objects to handle that. That way the user could set a difficulty level of choosing how many decks to play with. But for games that don't use a standard deck size, that approach would work in both situations and I wouldn't have to mess with it. I'll post the code when I'm done. Oh, that reminds me, is this the proper area of the site to post code? You know, just to share. Or is there another place to do that? I tried it a couple of times and I'm not sure how useful it was to anyone.

Share this post


Link to post
Share on other sites
Quote:
Original post by Fruny
As a std::deque<Card>, obviously. [smile]


Booooo... bad joke. (So why can't I stop grinning?) [smile]

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!