Quote:
Originally Posted by tinyy
sorry if this isnt the right area im more of a reader than a poster in this forum...
Hmmm im struggling to work out the code for 3 of a kind in my yahtzee game, i think that if i can work this out i can sort my everest of the full house code!
can someone tell me where ive gone astray?
Public dice_value_array(4) As Integer
Case "lblThreeOfAKind"
dice_value_array(0) = CInt(dice1)
dice_value_array(1) = CInt(dice2)
dice_value_array(2) = CInt(dice3)
dice_value_array(3) = CInt(dice4)
dice_value_array(4) = CInt(dice5)
Dim count As Integer = 0
For i As Integer = 0 To 5
For j As Integer = 1 To 6
If dice_value_array(i) = dice_value_array(j) Then
count += 1
End If
Next
If (count >= 3) Then
score += 20
threeof = score
Label9.Text = threeof.ToString
lblThreeOfAKind.Enabled = False
End If
Next
any help would be great cos i think im a stones throw away from insanity!

Now the first problem i see is that
For i As Integer = 0 To 5
For j As Integer = 1 To 6
when you declared
Public dice_value_array(4) As Integer
If dice_value_array(i) = dice_value_array(j) Then
count += 1
Here would be my solution:
Code:
Public dice_value_array(4)
dice_value_array(0) = CInt(dice1)
dice_value_array(1) = CInt(dice2)
dice_value_array(2) = CInt(dice3)
dice_value_array(3) = CInt(dice4)
dice_value_array(4) = CInt(dice5)
For i as integer = 0 to 4
For j as integer = 0 to 4
if i = j then
'don't compare it's the same dice
else
If dice_value_array(i) = dice_value_array(j) Then
count += 1
End If
end if
next j
next i
If (count >= 3) Then
score += 20
threeof = score
Label9.Text = threeof.ToString
lblThreeOfAKind.Enabled = False
End If
Next
I havn't tested it, but give that a go.

Last edited by Guest0496; 04182010 at 05:39 AM.
Reason: Fixed something i missed
