Welcome to Dream.In.Code
Become a C++ Expert!

Join 137,398 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 2,110 people online right now. Registration is fast and FREE... Join Now!




Card Game

 
Reply to this topicStart new topic

Card Game

//no_comment
26 Oct, 2006 - 12:45 PM
Post #1

New D.I.C Head
*

Joined: 15 Sep, 2006
Posts: 16


My Contributions
I am working on a crazy eights cards game for my c++ class project. I have initialized an array containing each of the numbers for the cards. How can i use the random number generator to simulate "shuffling" them.
User is offlineProfile CardPM
+Quote Post

Amadeus
RE: Card Game
26 Oct, 2006 - 12:50 PM
Post #2

g++ -o drink whiskey.cpp
Group Icon

Joined: 12 Jul, 2002
Posts: 12,230



Thanked: 40 times
Dream Kudos: 25
My Contributions
There are many ways to simulate a shuffle...you could have an array of cards, then run through that element by element...for each element, generate a random number between 0 and 51, put the card in that element of a second array. Or, using one array, for each element, generate a random number, then switch that element with the element at the random number position, do that a few times.

You may want to check this out as well...it is a card deck implementation.

http://archive.devx.com/sourcebank/directo...wFilter=showAll
User is offlineProfile CardPM
+Quote Post

//no_comment
RE: Card Game
26 Oct, 2006 - 01:28 PM
Post #3

New D.I.C Head
*

Joined: 15 Sep, 2006
Posts: 16


My Contributions
QUOTE(Amadeus @ 26 Oct, 2006 - 01:50 PM) *

There are many ways to simulate a shuffle...you could have an array of cards, then run through that element by element...for each element, generate a random number between 0 and 51, put the card in that element of a second array. Or, using one array, for each element, generate a random number, then switch that element with the element at the random number position, do that a few times.

You may want to check this out as well...it is a card deck implementation.

http://archive.devx.com/sourcebank/directo...wFilter=showAll


Thanks for the link, i did some research and found a few others, and I am leaning toward generating a random number and replacing that number with another element from the array. Thanks again for your suggestions
User is offlineProfile CardPM
+Quote Post

lukemsilver
RE: Card Game
30 Nov, 2006 - 03:52 PM
Post #4

New D.I.C Head
*

Joined: 30 Nov, 2006
Posts: 1


My Contributions
hey I have to do the crazy eights project for my C++ class as well. If you still have the code could you send it to me or help me with it, I'd appreciate it a lot. ***************

This post has been edited by Dark_Nexus: 30 Nov, 2006 - 05:59 PM
User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 12/5/08 03:06AM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month