[RESOLVED] How can I shuffle a deck of cards in VB6?
I use VB6. I have looked everywhere. I have found many shuffleing routines but none tell how to use them. So I was wondering if you guys can help me in shuffling my deck of cards. It's in the attachment. Right now, it only loads each card in order form the picturebox array, but I want to be able to shuffle the deck and then use it. I know I need another array but after that I'm stuck. Please help me with this as I can't finish my project without it!
Thanks in advance.
-GOOG-
Re: How can I shuffle a deck of cards in VB6?
you need to use a random function.
I've included it in for you to show how nice I am :D ;).
VB Code:
Public Function Rand(ByVal Low As Long, _
ByVal High As Long) As Long
Rand = Int((High - Low + 1) * Rnd) + Low
End Function
This was the code used for randomising. All i did was put that and:
so it randomised the cards. What would be nice if it can shuffle up to a certain amount, like do a counter or something so when it reaches up to that bit, the card deck goes blank and the counter is set to zero. But nice idea.
I've uploaded the changes in your source code.
Re: How can I shuffle a deck of cards in VB6?
If this helps, I have written a class to control a deck of cards but its in vb.Net maybe you could have a look it might give you some ideas. :)
(link in sig - iCards)
Re: How can I shuffle a deck of cards in VB6?
you'd probably be better off using a collection to manage the deck of cards. Then you can remove them / add them easier.
MartinLiss has a shuffle sub in his BlackJack game that you probably want to look at: http://www.vbforums.com/showthread.php?t=389115
Re: How can I shuffle a deck of cards in VB6?
I wrote a let it ride game where I shuffle the cards. I put all the cards into and array and then use a very small chunk of code to just shuffle that array. Then I just call the cards like I normally would. It shuffles pretty good and I havent seen an issue.
Re: How can I shuffle a deck of cards in VB6?
That code doesn't shuffle the deck... it only gives a random card. It only picks one number between 0 and 52 there is no actual shuffling done.
Thanks anyway though.
I'll try to make heads or tails of the black jack shuffle sub.
And just because I like it: :duck:
:duck: you're the one. You make bath time lots of fun. :duck: !
Re: How can I shuffle a deck of cards in VB6?
OK Now i'm confused! :( :confused:
What do you mean by shuffling? I seem to be missing the point by miles here.
Re: How can I shuffle a deck of cards in VB6?
Quote:
Originally Posted by kregg
OK Now i'm confused! :( :confused:
What do you mean by shuffling? I seem to be missing the point by miles here.
I need to record which card is where in the deck at the beginning and remember that throughout the program... so it needs to be in an array. I thought maybe I can use what you did to randomly fill an array and thus have my own shuffling routine but it isn't working out that way.
I think maybe I tried to fill the array with the wrong information.
I should try it again.
Re: How can I shuffle a deck of cards in VB6?
the code kregg gave doesn't work, since it picks a random card out of ALL cards each time!
Shuffling needs to pick a random card out of all REMAINING cards!
So use a decreasing Upper Limit each time you use that Random Function. But there will remain one issue, the space (index) of the last card picked has to be filled in somehow.
Re: [RESOLVED] How can I shuffle a deck of cards in VB6?
I've figured it out thanks! :-)
Re: [RESOLVED] How can I shuffle a deck of cards in VB6?
the problem i forsaw when coding my deck was that i wanted to set a pointer at 52 and then decrement when i was dealing and if the cards were set up properly then a shuffle would randomize the order of the cards so that they dont come out in order, just like a deck of cards.
i decided that for historical irony i would base my shuffle on a selection sort.
using two random number gens and a temp deck i have been able to swap cards like a casino chimile shuffle.
this may seem a little complicated but if you want to know more just ask and i will povide code