Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

check my code please?

 
Rene Rad
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey everyone,

I'm writing a method to shuffle a deck and am unsure if it's executing properly. I'm not sure how to check if it is shuffling 1000 times. (using constant public static final int TIMES_TO_SHUFFLE = 1000) My instructions are in the javadoc before the code. I tried using the debugger but I kept looping in the block and am unsure how to properly use it. Here is my code...



here is the card class.

 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What I can understand from the javadoc is :
1. Take two cards (you need two random indexes)
2. Swap them (no need to use another array)
3. Repeat TIMES_TO_SHUFFLE times

If you follow these simple steps, the method should be easier to write.
 
Bert Wilkinson
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It looks like your instructions for the assignment are in the javadoc....

So, with that in mind, your shuffle method looks like it will do some shuffling, but it is not doing what the javadoc says it should. You are looping through the entire deck TIMES_TO_SHUFFLE times vice doing that many "swaps" within the deck. Hopefully that's clear and gives you some direction on where you need to tweak your code.

After you think you are close, you can put a println statement in there to compare the deck before and after a "shuffle" is called to convince yourself something is happening.
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
(Consider using loop(s) in loadDeck rather than specifying each card manually, which is rather error-prone.)

Note also that "shuffling" in code is a different operation than shuffling a physical deck of cards--shuffling 1000 times is not likely to give you a deck that's (substantially?) more random than shuffling once.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic