Jump to content

Array - finding consecutive numbers - POKER HANDS


Recommended Posts

OK - I have been working ( a long time ) on trying to figure out how to find the difference between straights and straight flushes and having a tough time at it. I need help before I rip whats left of my hair out.

3 digits numbers, the first number represents the suit ( 1=spades, 2=hearts, 3=diamonds, 4=clubs ) the second number is the card number 12 = 2, 13 = 3 ... 19 = 9, 20 = 10 ... 23 = king, 24 = Ace

I have come close a few times but once I figure out one the other parts break. Below is my code that I have so far. Whats happening is, that if the straight is there and there is a 5 cards of the same suit not in the straight it will come out as a straight flush.

If you need more info - please let me know, but I am lost. I have recieved some great help from @martin and got further, but feel I might have bitten off more than I can chew. I left my test code in place so that you can see that I have tried, and tried I have.

#include<Array.au3>


Global $Straight = 4, $StraightFlush = 8


Dim $aArray[7] = [216, 217, 218, 212, 213, 214, 215]
If _FindStraight2($aArray) = $StraightFlush Then
    ConsoleWrite("!>STRAIGHTFLUSH" & @CRLF)
Else
    ConsoleWrite("!>STRAIGHT" & @CRLF)
EndIf


Dim $aArray[7] = [116, 217, 218, 212, 213, 214, 215]
If _FindStraight2($aArray) = $StraightFlush Then
    ConsoleWrite("!>STRAIGHTFLUSH" & @CRLF)
Else
    ConsoleWrite("!>STRAIGHT" & @CRLF)
EndIf



Func _FindStraight2($aArray)
    ; thanks @martin for the following code
    Local $arr2[UBound($aArray)], $str
    Local $SpadeCount, $HeartsCount, $DiamondsCount, $ClubsCount
    For $n = 0 To UBound($aArray) - 1
        $str = String($aArray[$n])
        $arr2[$n] = StringRight($str, StringLen($str) - 1) & StringLeft($str, 1)
    Next
    _ArraySort($arr2)
    ;;_ArrayDisplay($arr2)
    For $n = 0 To UBound($aArray) - 1
        $aArray[$n] = Number(StringRight($arr2[$n], 1) & StringLeft($arr2[$n], StringLen($arr2[$n]) - 1))
    Next

    ;_ArrayDisplay($aArray)
    ; end @martin's code
    
    ;MsgBox('', '', UBound($aArray))
    For $i = 0 To UBound($aArray) - 1
        
        If $aArray[$i] > 100 Then ;Or $i <> UBound($aArray) -1 Then
        
        ;MsgBox('', $aArray[$i], UBound($aArray))
        
        ;If StringRight($aArray[$i], 2) - StringRight($aArray[$i + 1], 2) <> 0 Then MsgBox('', '', 'same,1')
        If StringRight($aArray[$i], 2) - StringRight($aArray[$i + 1], 2) = -1 Or _
                StringRight($aArray[$i], 2) - StringRight($aArray[$i + 1], 2) <> 0 Then
                If @error Then ContinueLoop
            Select
                Case StringLeft($aArray[$i + 0], 1) = 1
                    $SpadeCount += 1
                Case StringLeft($aArray[$i + 0], 1) = 2
                    $HeartsCount += 1
                Case StringLeft($aArray[$i + 0], 1) = 3
                    $DiamondsCount += 1
                Case StringLeft($aArray[$i + 0], 1) = 4
                    $ClubsCount += 1
            EndSelect
            ;MsgBox('','count',$SpadeCount & 's ' & $HeartsCount & ' h' & $DiamondsCount & 'd ' & $ClubsCount & 'c')
            ;MsgBox('', '1', $aArray[$i])
            ;MsgBox('', '1', StringLeft($aArray[$i + 0],1))
            If StringRight($aArray[$i + 1], 2) - StringRight($aArray[$i + 2], 2) = -1 Or _
                    StringRight($aArray[$i + 1], 2) - StringRight($aArray[$i + 2], 2) <> 0 Then
                    If @error Then ContinueLoop
                Select
                    Case StringLeft($aArray[$i + 1], 1) = 1
                        $SpadeCount += 1
                    Case StringLeft($aArray[$i + 1], 1) = 2
                        $HeartsCount += 1
                    Case StringLeft($aArray[$i + 1], 1) = 3
                        $DiamondsCount += 1
                    Case StringLeft($aArray[$i + 1], 1) = 4
                        $ClubsCount += 1
                EndSelect
                ;MsgBox('', 'count1', $SpadeCount & 's ' & $HeartsCount & ' h' & $DiamondsCount & 'd ' & $ClubsCount & 'c')
                ;MsgBox('', '2', $aArray[$i + 1])
                If StringRight($aArray[$i + 2], 2) - StringRight($aArray[$i + 3], 2) = -1 Or _
                        StringRight($aArray[$i + 2], 2) - StringRight($aArray[$i + 3], 2) <> 0 Then
                        If @error Then ContinueLoop
                    Select
                        Case StringLeft($aArray[$i + 2], 1) = 1
                            $SpadeCount += 1
                        Case StringLeft($aArray[$i + 2], 1) = 2
                            $HeartsCount += 1
                        Case StringLeft($aArray[$i + 2], 1) = 3
                            $DiamondsCount += 1
                        Case StringLeft($aArray[$i + 2], 1) = 4
                            $ClubsCount += 1
                    EndSelect
                    ;MsgBox('', 'count2', $SpadeCount & 's ' & $HeartsCount & ' h' & $DiamondsCount & 'd ' & $ClubsCount & 'c')
                    ;MsgBox('', '3', $aArray[$i + 2])
                    If StringRight($aArray[$i + 3], 2) - StringRight($aArray[$i + 4], 2) = -1 Or _
                            StringRight($aArray[$i + 3], 2) - StringRight($aArray[$i + 4], 2) <> 0 Then
                            If @error Then ContinueLoop
                        Select
                            Case StringLeft($aArray[$i + 3], 1) = 1
                                $SpadeCount += 1
                            Case StringLeft($aArray[$i + 3], 1) = 2
                                $HeartsCount += 1
                            Case StringLeft($aArray[$i + 3], 1) = 3
                                $DiamondsCount += 1
                            Case StringLeft($aArray[$i + 3], 1) = 4
                                $ClubsCount += 1
                        EndSelect
                        ;MsgBox('', 'count3', $SpadeCount & 's ' & $HeartsCount & ' h' & $DiamondsCount & 'd ' & $ClubsCount & 'c')
                        ;MsgBox('', '4', $aArray[$i + 3])
                        
                        ;If StringRight($aArray[$i + 4], 2) - StringRight($aArray[$i + 5], 2) = -1 Or _
                        ;       StringRight($aArray[$i + 4], 2) - StringRight($aArray[$i + 5], 2) <> 0 Then
                        ;   Select
                        ;       Case StringLeft($aArray[$i + 4], 1) = 1
                        ;           $SpadeCount += 1
                        ;       Case StringLeft($aArray[$i + 4], 1) = 2
                        ;           $HeartsCount += 1
                        ;       Case StringLeft($aArray[$i + 4], 1) = 3
                        ;           $DiamondsCount += 1
                        ;       Case StringLeft($aArray[$i + 4], 1) = 4
                        ;           $ClubsCount += 1
                        ;   EndSelect
                            ;MsgBox('', '5', $aArray[$i + 4])
                            If $SpadeCount >= 3 Or $HeartsCount >= 3 Or $DiamondsCount >= 3 Or $ClubsCount >= 3 Then
                                Return $StraightFlush
                            Else
                                Return $Straight
                            EndIf
                        ;EndIf
                    EndIf
                    
                EndIf
                
            EndIf
            
        EndIf
        ;EndIf
        EndIf
    Next
    
    
    
EndFunc   ;==>_FindStraight2

All by me:

"Sometimes you have to go back to where you started, to get to where you want to go." 

"Everybody catches up with everyone, eventually" 

"As you teach others, you are really teaching yourself."

From my dad

"Do not worry about yesterday, as the only thing that you can control is tomorrow."

 

WindowsError.gif

WIKI | Tabs; | Arrays; | Strings | Wiki Arrays | How to ask a Question | Forum Search | FAQ | Tutorials | Original FAQ | ONLINE HELP | UDF's Wiki | AutoIt PDF

AutoIt Snippets | Multple Guis | Interrupting a running function | Another Send

StringRegExp | StringRegExp Help | RegEXTester | REG TUTOR | Reg TUTOT 2

AutoItSetOption | Macros | AutoIt Snippets | Wrapper | Autoit  Docs

SCITE | SciteJump | BB | MyTopics | Programming | UDFs | AutoIt 123 | UDFs Form | UDF

Learning to script | Tutorials | Documentation | IE.AU3 | Games? | FreeSoftware | Path_Online | Core Language

Programming Tips

Excel Changes

ControlHover.UDF

GDI_Plus

Draw_On_Screen

GDI Basics

GDI_More_Basics

GDI Rotate

GDI Graph

GDI  CheckExistingItems

GDI Trajectory

Replace $ghGDIPDll with $__g_hGDIPDll

DLL 101?

Array via Object

GDI Swimlane

GDI Plus French 101 Site

GDI Examples UEZ

GDI Basic Clock

GDI Detection

Ternary operator

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...