bcil
bcil

Reputation: 3

Choosing the biggest pair in a yatzee game

Hello just as the title says i got some problems with getting the biggest pair in a yatzee game. So far I've got this code:

Public Function parVerdier(ByVal regel As Integer, tall As Object)
Dim sum As Integer = 0
For i As Integer = 0 To 4
    For j As Integer = (i + 1) To 4
        If tall(i) = tall(j) Then
            sum = tall(i) + tall(j)
        End If
    Next
Next
Return sum
End Function

Any idea what i should edit to make me able to pick the biggest pair and not ust some random pair? Example. I got the dices 4 4 3 3 5 and I want 4 4 which gives 8 points, but instead i get 6 points (3+3) Help pls and ty :)

Upvotes: 0

Views: 52

Answers (1)

user3534643
user3534643

Reputation:

Your loops look at every possible combination of two dice. With your example 44335 it calculates 4+4=8 first, after that overrides sum=3+3=6. If you just want the biggest pair you need another if-condition. Check if the sum of the pair is bigger than the pair of the loops before.

 Public Function parVerdier(ByVal regel As Integer, tall As Object)
        Dim sum As Integer = 0
        For i As Integer = 0 To 4
            For j As Integer = (i + 1) To 4
                If tall(i) = tall(j) Then
                    If tall(i) + tall(j) > sum Then
                        sum = tall(i) + tall(j)
                    End If
                End If
            Next
        Next
        Return sum
    End Function

Upvotes: 2

Related Questions