VB6 - Cards without repetition

malixx
10-11-2009, 02:53 AM
Hi everyone, that is visual basic 6.
I meaking a card game (poker). I have 52 cards, and how to do that is not repeated?

I have 52 cards, the cards are examples of K1, S2, P8, T6....
I split the name into 2 character
- Random letters k, s, p, t - (sl) and
- Random numbers 1-13 - (br)
When you merge the letter and number 'sl & br ."Gif"' then (like K1.gif).

This is my example, but it is not 100% sure, (some times does not make good).


Private Sub Command1_Click()
''''''''''''''''''''number''''''''''''''''''''''''
Randomize ' for number
br = (Int(Rnd * 13) + 1)
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'''''''''''''''''''''''letter''''''''''''''''''''''''
all_chars = Array("t", "k", "p", "s") 'for letters
random_index = Int(Rnd() * 4)
sl = clave & all_chars(random_index)
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

'This is test if EXIST the card or not
'-kr(i) is TextBox 1 to 11

kat = sl & br
If InStr(kr(1), kat) Or InStr(kr(2), kat) Or InStr(kr(3), kat) Or InStr(kr(4), kat) Or InStr(kr(5), kat)
Or InStr(kr(6), kat) Or InStr(kr(7), kat) Or InStr(kr(8), kat) Or InStr(kr(9), kat) Or InStr(kr(10), kat) Or InStr(kr(11), kat) Then
jj.Caption = jj.Caption & "EXIST," 'show if card exist
If br >= 13 Then 'if number > 13(card) then number is 1
kat = sl & 1
Else ' 'if number < 13 then OK
kat = sl & br + 1
End If
End If

'This is for show in Texbox kr(1 to 11)
For i = kr.LBound To kr.Ubound
If kr(i) = "" Then
kr(i).Text = kat
Exit For
End If
Next i
End Sub


it is short..
If someone knows different and better "Card check", then let me write, but it must be separately br & sl.

Thanks, Danijel

Iceplug
10-11-2009, 04:49 AM
I'm still not entirely sure what's going on, but I do see an inconsistency:
If br >= 13 Then 'if number > 13(card) then number is 1
if number > 13 ... the value of br should not be greater than 13 if your br receives a random number from 1 to 13.

However, your If statement does not use >, but >=
so when br = 13, your If statement rejects 13 and puts 1 instead - that might introduce an error.

Also, why are you adding 1 to br in the else? Does the call to Rnd already add 1?

malixx
10-11-2009, 04:59 AM
because i have 13 cards ! (number cards) (Rnd * 13), they cant be > 13 ! ( they cant exceed number 13)

mybe you have New, another idea how then i create this check?

Cerian Knight
10-11-2009, 08:44 AM
because i have 13 cards ! (number cards) (Rnd * 13), they cant be > 13 ! ( they cant exceed number 13)
I agree with Iceplug. Your code says '>= 13', which will act on 13. Anything else will have 1 added, so card 1 will become 2, it seems.

A couple of other points:
1. This code is out of context and is missing variable declarations and comments, which makes it more difficult to follow your intent.
2. Randomize should only be called once in 'Form_Load'. Subsequent repetitive calls actually produce less random results.

Here is a nice thread on shuffling an array, but you need to read the whole thing (both pages... best answer is in post 32) and check out the links in various posts:
http://www.xtremevbtalk.com/showthread.php?t=285630

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum