Thread: Shuffling a deck?

  1. #16
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    Quote Originally Posted by Neo1 View Post
    Try and run the code then
    Observing that the output of a program looks correct, is never proof of anything :-)

  2. #17
    The larch
    Join Date
    May 2006
    Posts
    3,573
    I am going to use this code for a console based BlackJack game, and i am using the DeckSize variable to keep track of how many cards are left in the deck after i draw the top one, that is also why i didn't declare it as a constant.
    OK then. But since you still need the magic 52 in many places, having a static const that represents the size of the whole deck wouldn't hurt.

    About the time_t variable: The code i used is just something i basically copied from the FAQ on this site, i figured there would be nothing wrong with it then. I'll make sure i get rid of it though.
    I meant you can use it as a local variable where you need it. But don't make it a data member of the class. When you hold a real deck of cards in your hand, do you somehow feel that Seconds is a part of it?...
    I might be wrong.

    Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.
    Quoted more than 1000 times (I hope).

  3. #18
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    Quote Originally Posted by anon View Post
    OK then. But since you still need the magic 52 in many places, having a static const that represents the size of the whole deck wouldn't hurt.
    Do you really think the size of a deck of cards is going to change? If it's standard Blackjack, how could it ever be played except with a standard deck?

    I hardly think that 52 is a "magic" number in a program which plays a card game. Making it a macro or constant might imply that it could be changed to some other value.

  4. #19
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    But you can easily make a typo and have an array of size 5 that the compiler never catches. Its not a big deal but I would probably use the constant not the literal.

    >> Daved may be referring to the fact that if (i + 1) in above statement is not a factor of RAND_MAX, the results tend to be biased but I don't think it would make that much difference here.
    No, I wasn't referring to that. I agree that such an issue is not important for a toy application. I was referring to potential for something like the 3,4,5 thing mentioned, and basically saying what you said, the index calculation is way too complicated.

    However, if you did want to make a real game that people play and make or bet real money with, then you would of course have to use a totally different and much more advanced random number generation scheme. There was an online poker site many years ago that tried to write a random shuffling algorithm like this that they thought was correct. Turns out it had tons of flaws and some guys were able to write a program that knew everybody's cards as they were playing.

  5. #20
    Tropical Coder Darryl's Avatar
    Join Date
    Mar 2005
    Location
    Cayman Islands
    Posts
    503
    Quote Originally Posted by brewbuck View Post
    Do you really think the size of a deck of cards is going to change? If it's standard Blackjack, how could it ever be played except with a standard deck?

    I hardly think that 52 is a "magic" number in a program which plays a card game. Making it a macro or constant might imply that it could be changed to some other value.
    You could be playing Casino style where they use up to 8 decks.

  6. #21
    Registered User
    Join Date
    Feb 2006
    Posts
    312
    Quote Originally Posted by brewbuck View Post
    Do you really think the size of a deck of cards is going to change? If it's standard Blackjack, how could it ever be played except with a standard deck?

    I hardly think that 52 is a "magic" number in a program which plays a card game. Making it a macro or constant might imply that it could be changed to some other value.
    "Do you really think the amount of memory we'll need is ever going to be greater than 640KB...?"
    One of the wonderful things about change, is that its so often unpredictable

    by the way, have you never played a game which uses the Jokers? That would make your deck a size of 54..


    Besides, even if it were a number which couldn't change (such as PI, or Gravity on planet earth) as others have mentioned, leaving literals lying around your code is undesirable.
    .. Another good example is NULL, which is always 0, however, when defining a null pointer, which one would you use..?

  7. #22
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    >> Another good example is NULL, which is always 0, however, when defining a null pointer, which one would you use..?

    0

    http://www.research.att.com/~bs/bs_faq2.html#null

  8. #23
    Registered User manofsteel972's Avatar
    Join Date
    Mar 2004
    Posts
    317
    Just curious, when would you use (void*)0 or is that equivalent to 0? I did some googling but only found more confliciting discussions. Could someone explain the differences if any?
    "Knowledge is proud that she knows so much; Wisdom is humble that she knows no more."
    -- Cowper

    Operating Systems=Slackware Linux 9.1,Windows 98/Xp
    Compilers=gcc 3.2.3, Visual C++ 6.0, DevC++(Mingw)

    You may teach a person from now until doom's day, but that person will only know what he learns himself.

    Now I know what doesn't work.

    A problem is understood by solving it, not by pondering it.

    For a bit of humor check out xkcd web comic http://xkcd.com/235/

  9. #24
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    >> when would you use (void*)0 or is that equivalent to 0?
    In C?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Question about engine design.
    By Shamino in forum Game Programming
    Replies: 9
    Last Post: 01-29-2008, 10:53 AM
  2. Blackjack
    By Tommo in forum C Programming
    Replies: 10
    Last Post: 06-20-2007, 08:07 PM
  3. Deck Shuffle
    By pjharris in forum C++ Programming
    Replies: 51
    Last Post: 01-06-2006, 04:59 PM
  4. Problem with deck class.
    By SlyMaelstrom in forum C++ Programming
    Replies: 3
    Last Post: 12-13-2005, 06:00 PM
  5. Replies: 2
    Last Post: 11-07-2003, 12:21 AM