0

Okay so I've been trying to debug this for hours and today and last night. I need to create a simple array(3,12) and use it to evaluate a 5 card poker hand. The problem is that it never returns a "TRUE" Boolean for anything above a 4 of a kind, And CheckStraight() and CheckFlush() are the two functions I call before 4 of a kind so I think the problem lies there, however its possible its in my array, however I've spent hours on the array checking every angle and I think at this point I've ruled it out as a problem. I think the problem lies in my CheckStraight() function. I see no logical reason for it to not work. Oddly when I run it (I created a text-box to output the sum of the calculation in the function) it always comes out at 1, when it should be 5. Here's my CheckStraight() Function:

Private Function CheckStraight(ByVal varHand) As Boolean
    Dim varValue As Boolean = False
    Dim varAces As Integer
    Dim varKings As Integer
    Dim varQueens As Integer
    Dim varJacks As Integer
    Dim varTens As Integer

    varAces = varHand(0, 0) + varHand(1, 0) + varHand(2, 0) + varHand(3, 0)
    If varAces > 1 Then
        varAces = 1
    End If

    varKings = varHand(0, 12) + varHand(1, 12) + varHand(2, 12) + varHand(3, 12)
    If varKings > 1 Then
        varKings = 1
    End If

    varQueens = varHand(0, 11) + varHand(1, 11) + varHand(2, 11) + varHand(3, 11)
    If varQueens > 1 Then
        varQueens = 1
    End If

    varJacks = varHand(0, 10) + varHand(1, 10) + varHand(2, 10) + varHand(3, 10)
    If varJacks > 1 Then
        varJacks = 1
    End If

    varTens = varHand(0, 9) + varHand(1, 9) + varHand(2, 9) + varHand(3, 9)
    If varTens > 1 Then
        varTens = 1
    End If

    '***txtDebug.Text = varAces + varKings + varQueens + varJacks + varTens***
    If varAces + varKings + varQueens + varJacks + varTens = 5 Then
        varValue = True
        Return varValue
    Else

        Dim varCount As Integer = 0
        Dim varTotal As Integer = 0
        Dim varX As Integer = 0
        Dim varY As Integer = 0
        Do While varY < 13
            varTotal = 0
            varX = 0
            Do While varX < 4
                varTotal = varTotal + varHand(varX, varY)
                varX += 1
            Loop
            If varTotal > 1 Then
                Exit Do
            ElseIf varTotal = 1 Then
                varCount += 1
                If varCount = 5 Then
                    varValue = True
                    Exit Do
                End If
            ElseIf varTotal = 0 Then
                varCount = 0
            End If
            varY += 1
        Loop
        If varCount = 5 Then
            Return varValue
        Else
        End If
    End If
End Function

The debug line should be bolded and italic. I'd really appreciate any input and if you need more code just ask.

Ňɏssa Pøngjǣrdenlarp
  • 38,411
  • 12
  • 59
  • 178
XERO40
  • 11
  • 2
  • Its generally easy to detect a straight - you arent using Option Strict so it is hard to tell what some of those things are. Put the cards in order, then compare to a series starting with the lowest card: `testSeq = Enumerable.Range(sortedValue(0), 5)` that creates a straight sequence, so `IsStraight = (testSeq.Except(sortedValue).Any() = False)`. You generally have to do it twice to allow for an Ace low straight (Wheel). you also need to do it in a loop for games with more than 5 card hands – Ňɏssa Pøngjǣrdenlarp Apr 30 '17 at 18:30
  • thanks for the tip ill try to figure out how to use that – XERO40 Apr 30 '17 at 19:45
  • What value(s) are stored in the array to represent when a card is present? – Chalky May 02 '17 at 12:11

0 Answers0