Results 1 to 4 of 4

Thread: How to display randomly 52 cards between 4 players?

  1. #1

    Thread Starter
    New Member
    Join Date
    Mar 2002
    Location
    Ottawa
    Posts
    4

    Angry 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.
    Vick

  2. #2
    Hyperactive Member
    Join Date
    Apr 2002
    Location
    Toronto, Ontario
    Posts
    280
    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.

  3. #3
    PowerPoster cafeenman's Avatar
    Join Date
    Mar 2002
    Location
    Florida
    Posts
    2,819
    This is air code, so it might need a tweak or two, but it should get you close

    VB Code:
    1. Sub DealCards
    2. dim i as integer
    3. dim j as integer
    4. dim k as integer
    5. dim Card(51) as integer ' 52 cards
    6. dim fFound as Boolean
    7. dim Player(3, 12) as integer ' 4 players, 13 cards each
    8. dim iRnd as integer
    9.  
    10. for i=0 to 12
    11.    for j = 0 to 3
    12.         Do
    13.             fFound = False ' reset flag
    14.             iRnd = int(rnd * 52)
    15.             for k = 0 to 51
    16.                 if Card(k) then
    17.                     fFound=true ' Set flag
    18.                     Exit For
    19.                 End if
    20.              next k
    21.              if not ffound then
    22.                  Card(iRnd) = 1
    23.                  Player(j, i) = Card(iRnd)
    24.                  Exit Do
    25.              end if
    26.         Loop
    27.     Next j
    28. Next i

  4. #4
    PowerPoster cafeenman's Avatar
    Join Date
    Mar 2002
    Location
    Florida
    Posts
    2,819
    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
  •  



Click Here to Expand Forum to Full Width