Results 1 to 3 of 3

Thread: Hold'em

  1. #1

    Thread Starter
    New Member
    Join Date
    Nov 2011
    Posts
    1

    Hold'em

    I've a made a Texas Hold'em game but am having a little trouble. I have it dealing random cards from the deck, however I'm not sure how to stop it from dealing the same card twice.
    (Here's what I have. s1, s2, s3 are the card images)

    Code:
     Dim x As Integer
            Dim card(52) As Object
            Dim x, y, z As Integer
            Randomize()
    
    card(0) = My.Resources.s1
    card(1) = My.Resources.s2
    card(2) = My.Resources.s3
    card(3) = My.Resources.s4
    card(4) = My.Resources.s5
    
     For x = 0 To 51 * Rnd() Step 1
                piccard1.Image = card(x)
            Next
            For y = 0 To 51 * Rnd() Step 2
                piccard2.Image = card(y)
            Next
            For z = 0 To 51 * Rnd() Step 3
                picflop1.Image = card(z)
            Next
    Like I said, this works but it will deal the same card. Although I like having pocket aces, I perfer they not be the same suit.
    I'm sure it's something simple, but I'm fairly new to VB. Any input would be appreciated.


    [Code tags added by moderator]

  2. #2
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    3,961

    Re: Hold'em

    Quote Originally Posted by Starke View Post
    I've a made a Texas Hold'em game but am having a little trouble. I have it dealing random cards from the deck, however I'm not sure how to stop it from dealing the same card twice.
    (Here's what I have. s1, s2, s3 are the card images)

    Code:
     Dim x As Integer
            Dim card(52) As Object
            Dim x, y, z As Integer
            Randomize()
    
    card(0) = My.Resources.s1
    card(1) = My.Resources.s2
    card(2) = My.Resources.s3
    card(3) = My.Resources.s4
    card(4) = My.Resources.s5
    
     For x = 0 To 51 * Rnd() Step 1
                piccard1.Image = card(x)
            Next
            For y = 0 To 51 * Rnd() Step 2
                piccard2.Image = card(y)
            Next
            For z = 0 To 51 * Rnd() Step 3
                picflop1.Image = card(z)
            Next
    Like I said, this works but it will deal the same card. Although I like having pocket aces, I perfer they not be the same suit.
    I'm sure it's something simple, but I'm fairly new to VB. Any input would be appreciated.


    [Code tags added by moderator]
    i think the problem is how you use the rnd() function.
    heres something that maybe can help you(at least i hope):
    Code:
    Function Random(Lowerbound As Long, Upperbound As Long)
    Randomize
    Random = Int(Rnd * Upperbound) + Lowerbound
    End Function
    VB6 2D Sprite control

    To live is difficult, but we do it.

  3. #3
    Elite Hacker Jacob Roman's Avatar
    Join Date
    Aug 2004
    Location
    Miami Beach, FL
    Posts
    5,349

    Re: Hold'em

    Heres a program I whipped up that'll shuffle the cards. Should be easy enough for ya to understand.

    vb Code:
    1. Option Explicit
    2.  
    3. Dim Card_Number(1 To 52) As Integer
    4. Dim Deck(1 To 52) As String
    5.  
    6. Private Sub Setup_Deck()
    7.  
    8.     Deck(1) = "A-S"
    9.     Deck(2) = "2-S"
    10.     Deck(3) = "3-S"
    11.     Deck(4) = "4-S"
    12.     Deck(5) = "5-S"
    13.     Deck(6) = "6-S"
    14.     Deck(7) = "7-S"
    15.     Deck(8) = "8-S"
    16.     Deck(9) = "9-S"
    17.     Deck(10) = "10-S"
    18.     Deck(11) = "J-S"
    19.     Deck(12) = "Q-S"
    20.     Deck(13) = "K-S"
    21.    
    22.     Deck(14) = "A-C"
    23.     Deck(15) = "2-C"
    24.     Deck(16) = "3-C"
    25.     Deck(17) = "4-C"
    26.     Deck(18) = "5-C"
    27.     Deck(19) = "6-C"
    28.     Deck(20) = "7-C"
    29.     Deck(21) = "8-C"
    30.     Deck(22) = "9-C"
    31.     Deck(23) = "10-C"
    32.     Deck(24) = "J-C"
    33.     Deck(25) = "Q-C"
    34.     Deck(26) = "K-C"
    35.    
    36.     Deck(27) = "A-D"
    37.     Deck(28) = "2-D"
    38.     Deck(29) = "3-D"
    39.     Deck(30) = "4-D"
    40.     Deck(31) = "5-D"
    41.     Deck(32) = "6-D"
    42.     Deck(33) = "7-D"
    43.     Deck(34) = "8-D"
    44.     Deck(35) = "9-D"
    45.     Deck(36) = "10-D"
    46.     Deck(37) = "J-D"
    47.     Deck(38) = "Q-D"
    48.     Deck(39) = "K-D"
    49.    
    50.     Deck(40) = "A-H"
    51.     Deck(41) = "2-H"
    52.     Deck(42) = "3-H"
    53.     Deck(43) = "4-H"
    54.     Deck(44) = "5-H"
    55.     Deck(45) = "6-H"
    56.     Deck(46) = "7-H"
    57.     Deck(47) = "8-H"
    58.     Deck(48) = "9-H"
    59.     Deck(49) = "10-H"
    60.     Deck(50) = "J-H"
    61.     Deck(51) = "Q-H"
    62.     Deck(52) = "K-H"
    63.    
    64.  
    65. End Sub
    66.  
    67. Private Sub ShuffleCard_Number()
    68.    
    69.     Dim CardCount As Integer 'This will be my loop counter
    70.     Dim CardVal As Integer 'This will get assigned the random value
    71.    
    72.     CardCount = 1 'Resets card count to 1
    73.    
    74.     Do While CardCount < 53 'This sets every slot in Card_Number to -1
    75.         Card_Number(CardCount) = -1 'so that later I can tell if the slot is empty
    76.         CardCount = CardCount + 1 'or not
    77.     Loop
    78.    
    79.     CardCount = 1 'Resets card count to 1
    80.    
    81.     Do While CardCount < 53 'Loop until every slot is full
    82. 10        CardVal = Int((52 * Rnd) + 1) 'Set CardVal = to a random number
    83.         If Card_Number(CardVal) = -1 Then 'Take random slot and see if there is a card
    84.             'in it yet. If there isn't it will be = to -1
    85.             'if there is it will be equal to a different
    86.             'value.
    87.             Card_Number(CardVal) = CardCount 'There isn't so put current card in that slot
    88.             CardCount = CardCount + 1 'Increment my card count
    89.            
    90.             Else: GoTo 10 'There is so start again from the beginning
    91.         End If
    92.     Loop 'Do it all again if < 53
    93. End Sub
    94.  
    95. Private Sub Command1_Click()
    96.  
    97.     Me.Cls
    98.     ShuffleCard_Number
    99.     Print Deck(Card_Number(1)), Deck(Card_Number(2)), Deck(Card_Number(3)), Deck(Card_Number(4)), Deck(Card_Number(5))
    100.  
    101. End Sub
    102.  
    103. Private Sub Form_Load()
    104.    
    105.     Me.Show
    106.     Me.AutoRedraw = True
    107.     Randomize
    108.     Setup_Deck
    109.  
    110. End Sub

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