473,480 Members | 1,914 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Created two of the same Card Deck class - when I shuffle each deck I get the SAME res

13 New Member
Hey everyone,



I created a theDeck class that creates a 52 card int List. Inside of this class I have a ShuffleCards method.



I simply want 2 seperate decks that I can then shuffle and then count a few cards out of each deck.


THUS returning two portions of two decks holding different cards. SOUNDS simple...but when I write the code below as I would think SHOULD work, I get two EXACT matching partial decks!



Can I get some guidance?



public Form1()

{

InitializeComponent();



this.deck1.ShuffleInPlace(deck1.getallCards());

this.deck2.ShuffleInPlace(deck2.getallCards());

for (i = 0; i < 20; i++)

{

prtlDeck1.Add(deck1.getCard(i));

prtlDeck2.Add(deck2.getCard(i));

}


}
Jul 5 '07 #1
4 1479
vanc
211 Recognized Expert New Member
The usual problem with this situation is that you're using ArrayList (if I guess right). ArrayList keeps all reference of things, not a separate copy of the objects. So you should be noticed about the way you add a reference of a separate copy of object.
You can debug and observe the changing when you add and remove or change items in those two ArrayLists.
To get a separate copy of and object not just a reference you can use Shallow copy method of that object. You can use Clone() method in similar way.

If this is not your problem, give me a yell.

cheer.
Jul 6 '07 #2
tvance929
13 New Member
I am using just a generic LIST and I dont think they have the Clone() method.
Jul 6 '07 #3
Plater
7,872 Recognized Expert Expert
I would say it is a seed issue for random number production.
I would guess that what the shuffle does is select a random card from the deck and push it onto an array, repeating the proccess until no cards are left. Then returning the new collection in the new order.
If there is no random number seed it will produce the same random number every time?
Jul 6 '07 #4
TRScheel
638 Recognized Expert Contributor
I would say it is a seed issue for random number production.
I would guess that what the shuffle does is select a random card from the deck and push it onto an array, repeating the proccess until no cards are left. Then returning the new collection in the new order.
If there is no random number seed it will produce the same random number every time?
If he uses random() it will seed with time unless a seed is pushed through as a variable. It might be helpful though if he exposes how he is generating the 'shuffling'.
Jul 6 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

23
12901
by: JC | last post by:
I am very new to programming and learning on my own. Why do I keep getting duplicate values using this code? I want to shuffle a deck of 52 cards. The logic seems right to me. Randomize For...
7
3070
by: Ken Smith | last post by:
I have a little video poker game I created in Javascript. It uses Tables and inner html stuff - for example: (psudo-code) imagePicked=random card image (2h.gif);...
18
2200
by: DaveLessnau | last post by:
I'm trying to learn C on my own and, apparently, my brain went on vacation somewhere. I just can't figure out how to parse the following function call: "void fillDeck( Card * const wDeck, const...
8
5535
by: ericvw | last post by:
How would I shuffle a static array of 52 cards that you input an integer, n, into a function and it takes the first n cards as the left segment and the remaining as the right. Then it shuffles...
0
2991
by: Limpor | last post by:
Hello, I am new to learning java, and i am trying to build the class for a calculation card game, unfortunately i can't get the public Card top() and Card takeTop() method in the Stock class. Can...
6
1860
by: JNeko | last post by:
Hello all, awesome site! I guess I am technically not a beginner in JAVA, but from my code you would not realize it! I don’t expect anyone to help me with this, but I figure I might as well as try...
5
1935
by: codie | last post by:
I got my code to work be the print out go's down on a angle is there anyway to stop this from happing. P.S sorry for taking up your time class Card: suitList = rankList = ...
3
2289
by: Fiona1200 | last post by:
Please help me..i have to write a code in java for a card game as follows. there are 4 players each with 4 decks of cards. each deck has four zeros - four seven as follows...
2
3329
by: rubyhuang | last post by:
the problem is A standard pack of cards can be represented as an array of 52 integers with each number representing a standard card. Thus: 0 1 2 3 4 5 6 7 8 9 10 11 12.....39 40 41 42 43 44 45 46...
0
7048
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7050
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7091
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6743
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
6966
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5344
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
2999
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1303
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
185
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.