|
-
Apr 8th, 2002, 05:50 PM
#1
Thread Starter
New Member
How to display randomly 52 cards between 4 players?
I have 4 players and I need to give randomly 52 cards to all four of them (13 cards per each player). Does anyone have an idea of a perfect algorithm.
-
Apr 8th, 2002, 06:42 PM
#2
Hyperactive Member
I don't know how much of a help this is, but you can get Cards32.dll from Microsoft (it's free ). I have never personally used it, but I have seen some other programs that use it (the code that is), and it doesn't seem that hard. It can even generate playing cards (if that's what you want!).
It was used in games like Microsoft Solitaire.
-
Apr 8th, 2002, 08:39 PM
#3
PowerPoster
This is air code, so it might need a tweak or two, but it should get you close
VB Code:
Sub DealCards
dim i as integer
dim j as integer
dim k as integer
dim Card(51) as integer ' 52 cards
dim fFound as Boolean
dim Player(3, 12) as integer ' 4 players, 13 cards each
dim iRnd as integer
for i=0 to 12
for j = 0 to 3
Do
fFound = False ' reset flag
iRnd = int(rnd * 52)
for k = 0 to 51
if Card(k) then
fFound=true ' Set flag
Exit For
End if
next k
if not ffound then
Card(iRnd) = 1
Player(j, i) = Card(iRnd)
Exit Do
end if
Loop
Next j
Next i
-
Apr 9th, 2002, 07:39 AM
#4
PowerPoster
makes sense to me and it's sounds a lot better than what I did. I'll try your way next time I need to do something similar
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
|