|
-
Mar 21st, 2006, 12:07 AM
#1
Thread Starter
New Member
[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-
Last edited by Google; Mar 22nd, 2006 at 08:51 PM.
-
Mar 21st, 2006, 05:13 AM
#2
Fanatic Member
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 .
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.
-
Mar 21st, 2006, 06:07 AM
#3
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)
-
Mar 21st, 2006, 08:37 AM
#4
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
-
Mar 21st, 2006, 09:09 AM
#5
Fanatic Member
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.
-
Mar 21st, 2006, 01:21 PM
#6
Thread Starter
New Member
-
Mar 22nd, 2006, 01:06 PM
#7
-
Mar 22nd, 2006, 03:01 PM
#8
Thread Starter
New Member
Re: How can I shuffle a deck of cards in VB6?
 Originally Posted by kregg
OK Now i'm 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.
-
Mar 22nd, 2006, 05:12 PM
#9
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.
You're welcome to rate this post!
If your problem is solved, please use the Mark thread as resolved button
Wait, I'm too old to hurry!
-
Mar 22nd, 2006, 08:51 PM
#10
Thread Starter
New Member
Re: [RESOLVED] How can I shuffle a deck of cards in VB6?
I've figured it out thanks! :-)
-
Apr 6th, 2006, 12:15 PM
#11
New Member
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|