Jump to content

poker game (The first steps of using arrays)


ioa747
 Share

Recommended Posts

poker game to study, play, or whatever you want !

an old challenge of mine that I have given up  :)

#NoTrayIcon
#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Icon=poker.ico
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <ColorConstants.au3>
#include <Array.au3>

Opt("MustDeclareVars", 1) ;0=no, 1=require pre-declaration
#Region === GUI ===
Local $Form1_1 = GUICreate("Poker", 769, 382, 374, 395)
GUISetBkColor($COLOR_TEAL)
GUISetIcon(@ScriptDir & "\spade.ico")

Local $Pic1 = GUICtrlCreatePic("", 20, 60, 130, 190)
GUICtrlSetState(-1, $GUI_DISABLE)
Local $Pic2 = GUICtrlCreatePic("", 170, 60, 130, 190)
GUICtrlSetState(-1, $GUI_DISABLE)
Local $Pic3 = GUICtrlCreatePic("", 320, 60, 130, 190)
GUICtrlSetState(-1, $GUI_DISABLE)
Local $Pic4 = GUICtrlCreatePic("", 470, 60, 130, 190)
GUICtrlSetState(-1, $GUI_DISABLE)
Local $Pic5 = GUICtrlCreatePic("", 620, 60, 130, 190)
GUICtrlSetState(-1, $GUI_DISABLE)

Local $Hold1 = GUICtrlCreateLabel("", 20, 250, 130, 33, $SS_CENTER)
GUICtrlSetFont(-1, 17, 800, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0xFFFF00) ;Yellow
Local $Hold2 = GUICtrlCreateLabel("", 170, 250, 130, 33, $SS_CENTER)
GUICtrlSetFont(-1, 17, 800, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0xFFFF00) ;Yellow
Local $Hold3 = GUICtrlCreateLabel("", 320, 250, 130, 33, $SS_CENTER)
GUICtrlSetFont(-1, 17, 800, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0xFFFF00) ;Yellow
Local $Hold4 = GUICtrlCreateLabel("", 470, 250, 130, 33, $SS_CENTER)
GUICtrlSetFont(-1, 17, 800, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0xFFFF00) ;Yellow
Local $Hold5 = GUICtrlCreateLabel("", 620, 250, 130, 33, $SS_CENTER)
GUICtrlSetFont(-1, 17, 800, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0xFFFF00) ;Yellow

Local $Label1 = GUICtrlCreateLabel("", 20, 10, 587, 41, $SS_CENTER)
GUICtrlSetFont(-1, 24, 800, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0xFFFFFF) ;White

Local $Label2 = GUICtrlCreateLabel("", 620, 10, 130, 33, $SS_CENTER)
GUICtrlSetFont(-1, 17, 800, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0xFFFF00) ;Yellow

Local $Button1 = GUICtrlCreateButton("START", 20, 320, 735, 35)
GUICtrlSetFont(-1, 14, 400, 0, "MS Sans Serif")
;GUICtrlSetColor(-1, 0x000000)

Local $Button2 = GUICtrlCreateButton("RED", 290, 280, 100, 35)
GUICtrlSetState(-1, $GUI_HIDE)
Local $Button3 = GUICtrlCreateButton("BLACK", 400, 280, 100, 35)
GUICtrlSetState(-1, $GUI_HIDE)

GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
#Region === make the card ===
;clubs diamonds hearts spades
Local $aColor = ["clubs", "heart", "diamond", "spade"]
Local $shColor = ["C", "H", "D", "S"]
Local $k, $nMsg, $Str
Local $at = ["2", "3", "4", "5", "6", "7", "8", "9", "10", "jack", "queen", "king", "ace"]
Local $Oat = ["102", "103", "104", "105", "106", "107", "108", "109", "110", "111", "112", "113", "114"]
Local $aCard[53][4]
$aCard[0][0] = 52

$k = 1
For $C = 0 To UBound($aColor) - 1
    For $j = 0 To UBound($at) - 1
        $aCard[$k][0] = $aColor[$C] & "_" & $at[$j] ; card full name
        $aCard[$k][1] = $shColor[$C]                ; suit
        $aCard[$k][2] = $at[$j]                     ; card
        $aCard[$k][3] = $Oat[$j]                    ; order
        $k += 1
    Next
Next

ReplaceInArray($aCard, "jack", "J", 2)
ReplaceInArray($aCard, "queen", "Q", 2)
ReplaceInArray($aCard, "king", "K", 2)
ReplaceInArray($aCard, "ace", "A", 2)

$aColor = 0
$shColor = 0
$at = 0
$Oat = 0
;_ArrayDisplay($aCard)
_ArrayShuffle($aCard, 1)
#EndRegion === make the card ===
Local $Rnt = 1, $Cnt = 1, $Score = 100, $GameMode = "Play", $WinAmount
Local $HandCard[6][4]
$HandCard[0][0] = 5
;*******************************************************************************
While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Pic1
            If GUICtrlRead($Hold1) = "" Then
                GUICtrlSetData($Hold1, "Hold")
            Else
                GUICtrlSetData($Hold1, "")
            EndIf
        Case $Pic2
            If GUICtrlRead($Hold2) = "" Then
                GUICtrlSetData($Hold2, "Hold")
            Else
                GUICtrlSetData($Hold2, "")
            EndIf
        Case $Pic3
            If GUICtrlRead($Hold3) = "" Then
                GUICtrlSetData($Hold3, "Hold")
            Else
                GUICtrlSetData($Hold3, "")
            EndIf
        Case $Pic4
            If GUICtrlRead($Hold4) = "" Then
                GUICtrlSetData($Hold4, "Hold")
            Else
                GUICtrlSetData($Hold4, "")
            EndIf
        Case $Pic5
            If GUICtrlRead($Hold5) = "" Then
                GUICtrlSetData($Hold5, "Hold")
            Else
                GUICtrlSetData($Hold5, "")
            EndIf
            ;-------------------
        Case $Hold1

        Case $Button1  ;deal
            Button1()

        Case $Button2  ;red
            Button2()

        Case $Button3  ;black
            Button3()

    EndSwitch
WEnd
;********************************************************************************

;-------------------------------------------------------------------------------
Func Button1() ; deal , take
    Select
        Case $GameMode = "Play" ; then deal
            Deal()
        Case $GameMode = "Black-Red" ; then take
            $Score = $Score + $WinAmount
            GUICtrlSetState($Button2, $GUI_HIDE)
            GUICtrlSetState($Button3, $GUI_HIDE)
            GUICtrlSetFont($Label1, 24, 800, 0, "MS Sans Serif")
            GUICtrlSetData($Label1, "")
            GUICtrlSetData($Label2, $Score)
            GUICtrlSetFont($Label2, 24, 800, 0, "MS Sans Serif")
            Sleep(500)
            GUICtrlSetFont($Label2, 17, 800, 0, "MS Sans Serif")
            ;GUICtrlSetFont($Label2, 17, 800, 0, "MS Sans Serif")
            ;GUICtrlSetColor($Label2, 0xFFFF00) ;Yellow

            $GameMode = "Play"
            GUICtrlSetData($Button1, "DEAL")
            GUISetBkColor($COLOR_TEAL)

    EndSelect

EndFunc   ;==>Button1
;-------------------------------------------------------------------------------
Func Button2() ;red
    CardColor("Red")
EndFunc   ;==>Button2
;-------------------------------------------------------------------------------
Func Button3() ;black
    CardColor("Black")
EndFunc   ;==>Button3
;-------------------------------------------------------------------------------
Func ReplaceInArray(ByRef $Array, $oStr, $nStr, $Col)
    For $i = 0 To UBound($Array) - 1
        If $Array[$i][$Col] = $oStr Then
            $Array[$i][$Col] = $nStr
            ;ConsoleWrite ($oStr & " in " & $i & " to " & $nStr & @CRLF)
        EndIf
    Next
    ;ToConsole($Array, $Col)
EndFunc   ;==>ReplaceInArray
;-------------------------------------------------------------------------------
Func ToConsole($Array, $Col) ;write array to console
    For $i = 0 To UBound($Array) - 1
        ConsoleWrite($Array[$i][$Col] & "  ")
    Next
    ConsoleWrite(@CRLF)

EndFunc   ;==>ToConsole
;-------------------------------------------------------------------------------
Func TurnCards() ;TurnCards
    GUICtrlSetImage($Pic1, @ScriptDir & "\card\back04.jpg")
    GUICtrlSetImage($Pic2, @ScriptDir & "\card\back04.jpg")
    GUICtrlSetImage($Pic3, @ScriptDir & "\card\back04.jpg")
    GUICtrlSetImage($Pic4, @ScriptDir & "\card\back04.jpg")
    GUICtrlSetImage($Pic5, @ScriptDir & "\card\back04.jpg")
EndFunc   ;==>TurnCards
;-------------------------------------------------------------------------------
Func Deal() ;Deal the Cards
    Local $C, $R
    If $Rnt = 1 Then
        TurnCards()
        Sleep(300)
        _ArrayShuffle($aCard, 1)
        ckHolder()

        $Score = $Score - 1
        GUICtrlSetData($Label2, $Score)

        GUICtrlSetImage($Pic1, @ScriptDir & "\card\" & $aCard[1][0] & ".jpg")
        GUICtrlSetImage($Pic2, @ScriptDir & "\card\" & $aCard[2][0] & ".jpg")
        GUICtrlSetImage($Pic3, @ScriptDir & "\card\" & $aCard[3][0] & ".jpg")
        GUICtrlSetImage($Pic4, @ScriptDir & "\card\" & $aCard[4][0] & ".jpg")
        GUICtrlSetImage($Pic5, @ScriptDir & "\card\" & $aCard[5][0] & ".jpg")

        For $C = 0 To 3
            For $R = 1 To 5
                $HandCard[$R][$C] = $aCard[$R][$C]
            Next
        Next
        ;_ArrayDisplay($HandCard, "Deal")
        ToConsole($HandCard, 2)

        $Rnt = 2
        $Cnt = 6
    Else

        If GUICtrlRead($Hold1) = "" Then
            GUICtrlSetImage($Pic1, @ScriptDir & "\card\" & $aCard[$Cnt][0] & ".jpg")
            $HandCard[1][0] = $aCard[$Cnt][0]
            $HandCard[1][1] = $aCard[$Cnt][1]
            $HandCard[1][2] = $aCard[$Cnt][2]
            $HandCard[1][3] = $aCard[$Cnt][3]
            $Cnt += 1
        EndIf
        If GUICtrlRead($Hold2) = "" Then
            GUICtrlSetImage($Pic2, @ScriptDir & "\card\" & $aCard[$Cnt][0] & ".jpg")
            $HandCard[2][0] = $aCard[$Cnt][0]
            $HandCard[2][1] = $aCard[$Cnt][1]
            $HandCard[2][2] = $aCard[$Cnt][2]
            $HandCard[2][3] = $aCard[$Cnt][3]
            $Cnt += 1
        EndIf
        If GUICtrlRead($Hold3) = "" Then
            GUICtrlSetImage($Pic3, @ScriptDir & "\card\" & $aCard[$Cnt][0] & ".jpg")
            $HandCard[3][0] = $aCard[$Cnt][0]
            $HandCard[3][1] = $aCard[$Cnt][1]
            $HandCard[3][2] = $aCard[$Cnt][2]
            $HandCard[3][3] = $aCard[$Cnt][3]
            $Cnt += 1
        EndIf
        If GUICtrlRead($Hold4) = "" Then
            GUICtrlSetImage($Pic4, @ScriptDir & "\card\" & $aCard[$Cnt][0] & ".jpg")
            $HandCard[4][0] = $aCard[$Cnt][0]
            $HandCard[4][1] = $aCard[$Cnt][1]
            $HandCard[4][2] = $aCard[$Cnt][2]
            $HandCard[4][3] = $aCard[$Cnt][3]
            $Cnt += 1
        EndIf
        If GUICtrlRead($Hold5) = "" Then
            GUICtrlSetImage($Pic5, @ScriptDir & "\card\" & $aCard[$Cnt][0] & ".jpg")
            $HandCard[5][0] = $aCard[$Cnt][0]
            $HandCard[5][1] = $aCard[$Cnt][1]
            $HandCard[5][2] = $aCard[$Cnt][2]
            $HandCard[5][3] = $aCard[$Cnt][3]
            $Cnt += 1
        EndIf

        ckHolder()
        ToConsole($HandCard, 2)
        ChekForWin()
        $Rnt = 1
    EndIf

EndFunc   ;==>Deal
;-------------------------------------------------------------------------------
Func ckHolder() ;Check the Holders
    If GUICtrlRead($Label2) = "" Then GUICtrlSetData($Label2, $Score)

    If $Rnt = 1 Then
        ConsoleWrite("********************" & @CRLF)
        ConsoleWrite($Rnt & " Round ------------" & @CRLF)
        GUICtrlSetData($Button1, "OK")
        GUICtrlSetFont($Label1, 18, 800, 0, "MS Sans Serif")
        GUICtrlSetData($Label1, "hold your cards")

        GUICtrlSetState($Pic1, $GUI_ENABLE)
        GUICtrlSetState($Pic2, $GUI_ENABLE)
        GUICtrlSetState($Pic3, $GUI_ENABLE)
        GUICtrlSetState($Pic4, $GUI_ENABLE)
        GUICtrlSetState($Pic5, $GUI_ENABLE)

        GUICtrlSetData($Hold1, "")
        GUICtrlSetData($Hold2, "")
        GUICtrlSetData($Hold3, "")
        GUICtrlSetData($Hold4, "")
        GUICtrlSetData($Hold5, "")
    ElseIf $Rnt = 2 Then
        ConsoleWrite($Rnt & " Round ------------" & @CRLF)
        GUICtrlSetData($Button1, "DEAL")
        ;GUICtrlSetFont($Label1, 12, 800, 0, "MS Sans Serif")
        GUICtrlSetData($Label1, "")

        GUICtrlSetState($Pic1, $GUI_DISABLE)
        GUICtrlSetState($Pic2, $GUI_DISABLE)
        GUICtrlSetState($Pic3, $GUI_DISABLE)
        GUICtrlSetState($Pic4, $GUI_DISABLE)
        GUICtrlSetState($Pic5, $GUI_DISABLE)

        GUICtrlSetData($Hold1, "")
        GUICtrlSetData($Hold2, "")
        GUICtrlSetData($Hold3, "")
        GUICtrlSetData($Hold4, "")
        GUICtrlSetData($Hold5, "")

    ElseIf $Rnt = 3 Then

    EndIf

EndFunc   ;==>ckHolder
;-------------------------------------------------------------------------------
Func ChekForWin() ;Check for Win
    Local $tmpHand, $CardStr = ""

    _ArraySort($HandCard, 0, 1, 0, 3) ; array sort by card order
    ;_ArrayDisplay($HandCard, "ChekForWin")

    ;------------------------------------------------------------------------------------
    ; Flush

    For $i = 1 To $HandCard[0][0]
        $CardStr = $CardStr & $HandCard[$i][1]
    Next

    Select
        Case $CardStr = "CCCCC"
            $tmpHand = "Flush"
        Case $CardStr = "DDDDD"
            $tmpHand = "Flush"
        Case $CardStr = "HHHHH"
            $tmpHand = "Flush"
        Case $CardStr = "SSSSS"
            $tmpHand = "Flush"
    EndSelect

    ;------------------------------------------------------------------------------------
    $CardStr = ""
    For $i = 1 To $HandCard[0][0]
        $CardStr = $CardStr & $HandCard[$i][2]
    Next

    ConsoleWrite("ChekForWin ---------" & @CRLF)
    ConsoleWrite("$CardStr = " & $CardStr & @CRLF)
    ConsoleWrite("$tmpHand1 = " & $tmpHand & @CRLF)

    ;------------------------------------------------------------------------------------

    If $tmpHand = "Flush" Then
        Select
            Case StringInStr($CardStr, "10JQKA") > 0 And $tmpHand = "Flush"
                $tmpHand = "Royal Flush"
            Case StringInStr($CardStr, "910JQK") > 0 And $tmpHand = "Flush"
                $tmpHand = "Straight Flush"
            Case StringInStr($CardStr, "8910JQ") > 0 And $tmpHand = "Flush"
                $tmpHand = "Straight Flush"
            Case StringInStr($CardStr, "78910J") > 0 And $tmpHand = "Flush"
                $tmpHand = "Straight Flush"
            Case StringInStr($CardStr, "678910") > 0 And $tmpHand = "Flush"
                $tmpHand = "Straight Flush"
            Case StringInStr($CardStr, "56789") > 0 And $tmpHand = "Flush"
                $tmpHand = "Straight Flush"
            Case StringInStr($CardStr, "45678") > 0 And $tmpHand = "Flush"
                $tmpHand = "Straight Flush"
            Case StringInStr($CardStr, "34567") > 0 And $tmpHand = "Flush"
                $tmpHand = "Straight Flush"
            Case StringInStr($CardStr, "23456") > 0 And $tmpHand = "Flush"
                $tmpHand = "Straight Flush"
            Case Else
                $tmpHand = "Flush"
        EndSelect
    Else
        Select
            Case StringInStr($CardStr, "2222") > 0
                $tmpHand = "Four of kind"
            Case StringInStr($CardStr, "3333") > 0
                $tmpHand = "Four of kind"
            Case StringInStr($CardStr, "4444") > 0
                $tmpHand = "Four of kind"
            Case StringInStr($CardStr, "5555") > 0
                $tmpHand = "Four of kind"
            Case StringInStr($CardStr, "6666") > 0
                $tmpHand = "Four of kind"
            Case StringInStr($CardStr, "7777") > 0
                $tmpHand = "Four of kind"
            Case StringInStr($CardStr, "8888") > 0
                $tmpHand = "Four of kind"
            Case StringInStr($CardStr, "9999") > 0
                $tmpHand = "Four of kind"
            Case StringInStr($CardStr, "10101010") > 0
                $tmpHand = "Four of kind"
            Case StringInStr($CardStr, "JJJJ") > 0
                $tmpHand = "Four of kind"
            Case StringInStr($CardStr, "QQQQ") > 0
                $tmpHand = "Four of kind"
            Case StringInStr($CardStr, "KKKK") > 0
                $tmpHand = "Four of kind"
            Case StringInStr($CardStr, "AAAA") > 0
                $tmpHand = "Four of kind"
                ;------------------------------------------------------------------------------------
            Case StringInStr($CardStr, "22333") > 0
                $tmpHand = "Full house"
            Case StringInStr($CardStr, "22444") > 0
                $tmpHand = "Full house"
            Case StringInStr($CardStr, "22555") > 0
                $tmpHand = "Full house"
            Case StringInStr($CardStr, "22666") > 0
                $tmpHand = "Full house"
            Case StringInStr($CardStr, "22777") > 0
                $tmpHand = "Full house"
            Case StringInStr($CardStr, "22888") > 0
                $tmpHand = "Full house"
            Case StringInStr($CardStr, "22999") > 0
                $tmpHand = "Full house"
            Case StringInStr($CardStr, "22101010") > 0
                $tmpHand = "Full house"
            Case StringInStr($CardStr, "22JJJ") > 0
                $tmpHand = "Full house"
            Case StringInStr($CardStr, "22QQQ") > 0
                $tmpHand = "Full house"
            Case StringInStr($CardStr, "22KKK") > 0
                $tmpHand = "Full house"
            Case StringInStr($CardStr, "22AAA") > 0
                $tmpHand = "Full house"

            Case StringInStr($CardStr, "22233") > 0
                $tmpHand = "Full house"
            Case StringInStr($CardStr, "22244") > 0
                $tmpHand = "Full house"
            Case StringInStr($CardStr, "22255") > 0
                $tmpHand = "Full house"
            Case StringInStr($CardStr, "22266") > 0
                $tmpHand = "Full house"
            Case StringInStr($CardStr, "22277") > 0
                $tmpHand = "Full house"
            Case StringInStr($CardStr, "22288") > 0
                $tmpHand = "Full house"
            Case StringInStr($CardStr, "22299") > 0
                $tmpHand = "Full house"
            Case StringInStr($CardStr, "2221010") > 0
                $tmpHand = "Full house"
            Case StringInStr($CardStr, "222JJ") > 0
                $tmpHand = "Full house"
            Case StringInStr($CardStr, "222QQ") > 0
                $tmpHand = "Full house"
            Case StringInStr($CardStr, "222KK") > 0
                $tmpHand = "Full house"
            Case StringInStr($CardStr, "222AA") > 0
                $tmpHand = "Full house"
                ;------------------------------------------------------------------------------------
            Case StringInStr($CardStr, "33444") > 0
                $tmpHand = "Full house"
            Case StringInStr($CardStr, "33555") > 0
                $tmpHand = "Full house"
            Case StringInStr($CardStr, "33666") > 0
                $tmpHand = "Full house"
            Case StringInStr($CardStr, "33777") > 0
                $tmpHand = "Full house"
            Case StringInStr($CardStr, "33888") > 0
                $tmpHand = "Full house"
            Case StringInStr($CardStr, "33999") > 0
                $tmpHand = "Full house"
            Case StringInStr($CardStr, "33101010") > 0
                $tmpHand = "Full house"
            Case StringInStr($CardStr, "33JJJ") > 0
                $tmpHand = "Full house"
            Case StringInStr($CardStr, "33QQQ") > 0
                $tmpHand = "Full house"
            Case StringInStr($CardStr, "33KKK") > 0
                $tmpHand = "Full house"
            Case StringInStr($CardStr, "33AAA") > 0
                $tmpHand = "Full house"

            Case StringInStr($CardStr, "33344") > 0
                $tmpHand = "Full house"
            Case StringInStr($CardStr, "33355") > 0
                $tmpHand = "Full house"
            Case StringInStr($CardStr, "33366") > 0
                $tmpHand = "Full house"
            Case StringInStr($CardStr, "33377") > 0
                $tmpHand = "Full house"
            Case StringInStr($CardStr, "33388") > 0
                $tmpHand = "Full house"
            Case StringInStr($CardStr, "33399") > 0
                $tmpHand = "Full house"
            Case StringInStr($CardStr, "3331010") > 0
                $tmpHand = "Full house"
            Case StringInStr($CardStr, "333JJ") > 0
                $tmpHand = "Full house"
            Case StringInStr($CardStr, "333QQ") > 0
                $tmpHand = "Full house"
            Case StringInStr($CardStr, "333KK") > 0
                $tmpHand = "Full house"
            Case StringInStr($CardStr, "333AA") > 0
                $tmpHand = "Full house"
                ;------------------------------------------------------------------------------------"
            Case StringInStr($CardStr, "44555") > 0
                $tmpHand = "Full house"
            Case StringInStr($CardStr, "44666") > 0
                $tmpHand = "Full house"
            Case StringInStr($CardStr, "44777") > 0
                $tmpHand = "Full house"
            Case StringInStr($CardStr, "44888") > 0
                $tmpHand = "Full house"
            Case StringInStr($CardStr, "44999") > 0
                $tmpHand = "Full house"
            Case StringInStr($CardStr, "44101010") > 0
                $tmpHand = "Full house"
            Case StringInStr($CardStr, "44JJJ") > 0
                $tmpHand = "Full house"
            Case StringInStr($CardStr, "44QQQ") > 0
                $tmpHand = "Full house"
            Case StringInStr($CardStr, "44KKK") > 0
                $tmpHand = "Full house"
            Case StringInStr($CardStr, "44AAA") > 0
                $tmpHand = "Full house"

            Case StringInStr($CardStr, "44455") > 0
                $tmpHand = "Full house"
            Case StringInStr($CardStr, "44466") > 0
                $tmpHand = "Full house"
            Case StringInStr($CardStr, "44477") > 0
                $tmpHand = "Full house"
            Case StringInStr($CardStr, "44488") > 0
                $tmpHand = "Full house"
            Case StringInStr($CardStr, "44499") > 0
                $tmpHand = "Full house"
            Case StringInStr($CardStr, "4441010") > 0
                $tmpHand = "Full house"
            Case StringInStr($CardStr, "444JJ") > 0
                $tmpHand = "Full house"
            Case StringInStr($CardStr, "444QQ") > 0
                $tmpHand = "Full house"
            Case StringInStr($CardStr, "444KK") > 0
                $tmpHand = "Full house"
            Case StringInStr($CardStr, "444AA") > 0
                $tmpHand = "Full house"
                ;------------------------------------------------------------------------------------
            Case StringInStr($CardStr, "55666") > 0
                $tmpHand = "Full house"
            Case StringInStr($CardStr, "55777") > 0
                $tmpHand = "Full house"
            Case StringInStr($CardStr, "55888") > 0
                $tmpHand = "Full house"
            Case StringInStr($CardStr, "55999") > 0
                $tmpHand = "Full house"
            Case StringInStr($CardStr, "55101010") > 0
                $tmpHand = "Full house"
            Case StringInStr($CardStr, "55JJJ") > 0
                $tmpHand = "Full house"
            Case StringInStr($CardStr, "55QQQ") > 0
                $tmpHand = "Full house"
            Case StringInStr($CardStr, "55KKK") > 0
                $tmpHand = "Full house"
            Case StringInStr($CardStr, "55AAA") > 0
                $tmpHand = "Full house"

            Case StringInStr($CardStr, "55566") > 0
                $tmpHand = "Full house"
            Case StringInStr($CardStr, "55577") > 0
                $tmpHand = "Full house"
            Case StringInStr($CardStr, "55588") > 0
                $tmpHand = "Full house"
            Case StringInStr($CardStr, "55599") > 0
                $tmpHand = "Full house"
            Case StringInStr($CardStr, "5551010") > 0
                $tmpHand = "Full house"
            Case StringInStr($CardStr, "555JJ") > 0
                $tmpHand = "Full house"
            Case StringInStr($CardStr, "555QQ") > 0
                $tmpHand = "Full house"
            Case StringInStr($CardStr, "555KK") > 0
                $tmpHand = "Full house"
            Case StringInStr($CardStr, "555AA") > 0
                $tmpHand = "Full house"
                ;------------------------------------------------------------------------------------
            Case StringInStr($CardStr, "66777") > 0
                $tmpHand = "Full house"
            Case StringInStr($CardStr, "66888") > 0
                $tmpHand = "Full house"
            Case StringInStr($CardStr, "66999") > 0
                $tmpHand = "Full house"
            Case StringInStr($CardStr, "66101010") > 0
                $tmpHand = "Full house"
            Case StringInStr($CardStr, "66JJJ") > 0
                $tmpHand = "Full house"
            Case StringInStr($CardStr, "66QQQ") > 0
                $tmpHand = "Full house"
            Case StringInStr($CardStr, "66KKK") > 0
                $tmpHand = "Full house"
            Case StringInStr($CardStr, "66AAA") > 0
                $tmpHand = "Full house"

            Case StringInStr($CardStr, "66677") > 0
                $tmpHand = "Full house"
            Case StringInStr($CardStr, "66688") > 0
                $tmpHand = "Full house"
            Case StringInStr($CardStr, "66699") > 0
                $tmpHand = "Full house"
            Case StringInStr($CardStr, "6661010") > 0
                $tmpHand = "Full house"
            Case StringInStr($CardStr, "666JJ") > 0
                $tmpHand = "Full house"
            Case StringInStr($CardStr, "666QQ") > 0
                $tmpHand = "Full house"
            Case StringInStr($CardStr, "666KK") > 0
                $tmpHand = "Full house"
            Case StringInStr($CardStr, "666AA") > 0
                $tmpHand = "Full house"
                ;------------------------------------------------------------------------------------
            Case StringInStr($CardStr, "77888") > 0
                $tmpHand = "Full house"
            Case StringInStr($CardStr, "77999") > 0
                $tmpHand = "Full house"
            Case StringInStr($CardStr, "77101010") > 0
                $tmpHand = "Full house"
            Case StringInStr($CardStr, "77JJJ") > 0
                $tmpHand = "Full house"
            Case StringInStr($CardStr, "77QQQ") > 0
                $tmpHand = "Full house"
            Case StringInStr($CardStr, "77KKK") > 0
                $tmpHand = "Full house"
            Case StringInStr($CardStr, "77AAA") > 0
                $tmpHand = "Full house"

            Case StringInStr($CardStr, "77788") > 0
                $tmpHand = "Full house"
            Case StringInStr($CardStr, "77799") > 0
                $tmpHand = "Full house"
            Case StringInStr($CardStr, "7771010") > 0
                $tmpHand = "Full house"
            Case StringInStr($CardStr, "777JJ") > 0
                $tmpHand = "Full house"
            Case StringInStr($CardStr, "777QQ") > 0
                $tmpHand = "Full house"
            Case StringInStr($CardStr, "777KK") > 0
                $tmpHand = "Full house"
            Case StringInStr($CardStr, "777AA") > 0
                $tmpHand = "Full house"
                ;------------------------------------------------------------------------------------
            Case StringInStr($CardStr, "88999") > 0
                $tmpHand = "Full house"
            Case StringInStr($CardStr, "88101010") > 0
                $tmpHand = "Full house"
            Case StringInStr($CardStr, "88JJJ") > 0
                $tmpHand = "Full house"
            Case StringInStr($CardStr, "88QQQ") > 0
                $tmpHand = "Full house"
            Case StringInStr($CardStr, "88KKK") > 0
                $tmpHand = "Full house"
            Case StringInStr($CardStr, "88AAA") > 0
                $tmpHand = "Full house"

            Case StringInStr($CardStr, "88899") > 0
                $tmpHand = "Full house"
            Case StringInStr($CardStr, "8881010") > 0
                $tmpHand = "Full house"
            Case StringInStr($CardStr, "888JJ") > 0
                $tmpHand = "Full house"
            Case StringInStr($CardStr, "888QQ") > 0
                $tmpHand = "Full house"
            Case StringInStr($CardStr, "888KK") > 0
                $tmpHand = "Full house"
            Case StringInStr($CardStr, "888AA") > 0
                $tmpHand = "Full house"
                ;------------------------------------------------------------------------------------
            Case StringInStr($CardStr, "99101010") > 0
                $tmpHand = "Full house"
            Case StringInStr($CardStr, "99JJJ") > 0
                $tmpHand = "Full house"
            Case StringInStr($CardStr, "99QQQ") > 0
                $tmpHand = "Full house"
            Case StringInStr($CardStr, "99KKK") > 0
                $tmpHand = "Full house"
            Case StringInStr($CardStr, "99AAA") > 0
                $tmpHand = "Full house"

            Case StringInStr($CardStr, "9991010") > 0
                $tmpHand = "Full house"
            Case StringInStr($CardStr, "999JJ") > 0
                $tmpHand = "Full house"
            Case StringInStr($CardStr, "999QQ") > 0
                $tmpHand = "Full house"
            Case StringInStr($CardStr, "999KK") > 0
                $tmpHand = "Full house"
            Case StringInStr($CardStr, "999AA") > 0
                $tmpHand = "Full house"
                ;------------------------------------------------------------------------------------
            Case StringInStr($CardStr, "1010JJJ") > 0
                $tmpHand = "Full house"
            Case StringInStr($CardStr, "1010QQQ") > 0
                $tmpHand = "Full house"
            Case StringInStr($CardStr, "1010KKK") > 0
                $tmpHand = "Full house"
            Case StringInStr($CardStr, "1010AAA") > 0
                $tmpHand = "Full house"

            Case StringInStr($CardStr, "101010JJ") > 0
                $tmpHand = "Full house"
            Case StringInStr($CardStr, "101010QQ") > 0
                $tmpHand = "Full house"
            Case StringInStr($CardStr, "101010KK") > 0
                $tmpHand = "Full house"
            Case StringInStr($CardStr, "101010AA") > 0
                $tmpHand = "Full house"
                ;------------------------------------------------------------------------------------
            Case StringInStr($CardStr, "JJQQQ") > 0
                $tmpHand = "Full house"
            Case StringInStr($CardStr, "JJKKK") > 0
                $tmpHand = "Full house"
            Case StringInStr($CardStr, "JJAAA") > 0
                $tmpHand = "Full house"

            Case StringInStr($CardStr, "JJJQQ") > 0
                $tmpHand = "Full house"
            Case StringInStr($CardStr, "JJJKK") > 0
                $tmpHand = "Full house"
            Case StringInStr($CardStr, "JJJAA") > 0
                $tmpHand = "Full house"
                ;------------------------------------------------------------------------------------
            Case StringInStr($CardStr, "QQKKK") > 0
                $tmpHand = "Full house"
            Case StringInStr($CardStr, "QQAAA") > 0
                $tmpHand = "Full house"

            Case StringInStr($CardStr, "QQQKK") > 0
                $tmpHand = "Full house"
            Case StringInStr($CardStr, "QQQAA") > 0
                $tmpHand = "Full house"
                ;------------------------------------------------------------------------------------
            Case StringInStr($CardStr, "KKAAA") > 0
                $tmpHand = "Full house"

            Case StringInStr($CardStr, "KKKAA") > 0
                $tmpHand = "Full house"
                ;------------------------------------------------------------------------------------
            Case StringInStr($CardStr, "10JQKA") > 0
                $tmpHand = "Straight"
            Case StringInStr($CardStr, "910JQK") > 0
                $tmpHand = "Straight"
            Case StringInStr($CardStr, "8910JQ") > 0
                $tmpHand = "Straight"
            Case StringInStr($CardStr, "78910J") > 0
                $tmpHand = "Straight"
            Case StringInStr($CardStr, "678910") > 0
                $tmpHand = "Straight"
            Case StringInStr($CardStr, "56789") > 0
                $tmpHand = "Straight"
            Case StringInStr($CardStr, "45678") > 0
                $tmpHand = "Straight"
            Case StringInStr($CardStr, "34567") > 0
                $tmpHand = "Straight"
            Case StringInStr($CardStr, "23456") > 0
                $tmpHand = "Straight"
            Case StringInStr($CardStr, "A2345") > 0
                $tmpHand = "Straight"
                ;------------------------------------------------------------------------------------
            Case StringInStr($CardStr, "222") > 0
                $tmpHand = "Three of kind"
            Case StringInStr($CardStr, "333") > 0
                $tmpHand = "Three of kind"
            Case StringInStr($CardStr, "444") > 0
                $tmpHand = "Three of kind"
            Case StringInStr($CardStr, "555") > 0
                $tmpHand = "Three of kind"
            Case StringInStr($CardStr, "666") > 0
                $tmpHand = "Three of kind"
            Case StringInStr($CardStr, "777") > 0
                $tmpHand = "Three of kind"
            Case StringInStr($CardStr, "888") > 0
                $tmpHand = "Three of kind"
            Case StringInStr($CardStr, "999") > 0
                $tmpHand = "Three of kind"
            Case StringInStr($CardStr, "101010") > 0
                $tmpHand = "Three of kind"
            Case StringInStr($CardStr, "JJJ") > 0
                $tmpHand = "Three of kind"
            Case StringInStr($CardStr, "QQQ") > 0
                $tmpHand = "Three of kind"
            Case StringInStr($CardStr, "KKK") > 0
                $tmpHand = "Three of kind"
            Case StringInStr($CardStr, "AAA") > 0
                $tmpHand = "Three of kind"
                ;------------------------------------------------------------------------------------
            Case StringInStr($CardStr, "22") > 0 And StringInStr($CardStr, "33") > 0
                $tmpHand = "Two pair"
            Case StringInStr($CardStr, "22") > 0 And StringInStr($CardStr, "44") > 0
                $tmpHand = "Two pair"
            Case StringInStr($CardStr, "22") > 0 And StringInStr($CardStr, "55") > 0
                $tmpHand = "Two pair"
            Case StringInStr($CardStr, "22") > 0 And StringInStr($CardStr, "66") > 0
                $tmpHand = "Two pair"
            Case StringInStr($CardStr, "22") > 0 And StringInStr($CardStr, "77") > 0
                $tmpHand = "Two pair"
            Case StringInStr($CardStr, "22") > 0 And StringInStr($CardStr, "88") > 0
                $tmpHand = "Two pair"
            Case StringInStr($CardStr, "22") > 0 And StringInStr($CardStr, "99") > 0
                $tmpHand = "Two pair"
            Case StringInStr($CardStr, "22") > 0 And StringInStr($CardStr, "1010") > 0
                $tmpHand = "Two pair"
            Case StringInStr($CardStr, "22") > 0 And StringInStr($CardStr, "JJ") > 0
                $tmpHand = "Two pair"
            Case StringInStr($CardStr, "22") > 0 And StringInStr($CardStr, "QQ") > 0
                $tmpHand = "Two pair"
            Case StringInStr($CardStr, "22") > 0 And StringInStr($CardStr, "KK") > 0
                $tmpHand = "Two pair"
            Case StringInStr($CardStr, "22") > 0 And StringInStr($CardStr, "AA") > 0
                $tmpHand = "Two pair"
                ;------------------------------------------------------------------------------------
            Case StringInStr($CardStr, "33") > 0 And StringInStr($CardStr, "44") > 0
                $tmpHand = "Two pair"
            Case StringInStr($CardStr, "33") > 0 And StringInStr($CardStr, "55") > 0
                $tmpHand = "Two pair"
            Case StringInStr($CardStr, "33") > 0 And StringInStr($CardStr, "66") > 0
                $tmpHand = "Two pair"
            Case StringInStr($CardStr, "33") > 0 And StringInStr($CardStr, "77") > 0
                $tmpHand = "Two pair"
            Case StringInStr($CardStr, "33") > 0 And StringInStr($CardStr, "88") > 0
                $tmpHand = "Two pair"
            Case StringInStr($CardStr, "33") > 0 And StringInStr($CardStr, "99") > 0
                $tmpHand = "Two pair"
            Case StringInStr($CardStr, "33") > 0 And StringInStr($CardStr, "1010") > 0
                $tmpHand = "Two pair"
            Case StringInStr($CardStr, "33") > 0 And StringInStr($CardStr, "JJ") > 0
                $tmpHand = "Two pair"
            Case StringInStr($CardStr, "33") > 0 And StringInStr($CardStr, "QQ") > 0
                $tmpHand = "Two pair"
            Case StringInStr($CardStr, "33") > 0 And StringInStr($CardStr, "KK") > 0
                $tmpHand = "Two pair"
            Case StringInStr($CardStr, "33") > 0 And StringInStr($CardStr, "AA") > 0
                $tmpHand = "Two pair"
                ;------------------------------------------------------------------------------------
            Case StringInStr($CardStr, "44") > 0 And StringInStr($CardStr, "55") > 0
                $tmpHand = "Two pair"
            Case StringInStr($CardStr, "44") > 0 And StringInStr($CardStr, "66") > 0
                $tmpHand = "Two pair"
            Case StringInStr($CardStr, "44") > 0 And StringInStr($CardStr, "77") > 0
                $tmpHand = "Two pair"
            Case StringInStr($CardStr, "44") > 0 And StringInStr($CardStr, "88") > 0
                $tmpHand = "Two pair"
            Case StringInStr($CardStr, "44") > 0 And StringInStr($CardStr, "99") > 0
                $tmpHand = "Two pair"
            Case StringInStr($CardStr, "44") > 0 And StringInStr($CardStr, "1010") > 0
                $tmpHand = "Two pair"
            Case StringInStr($CardStr, "44") > 0 And StringInStr($CardStr, "JJ") > 0
                $tmpHand = "Two pair"
            Case StringInStr($CardStr, "44") > 0 And StringInStr($CardStr, "QQ") > 0
                $tmpHand = "Two pair"
            Case StringInStr($CardStr, "44") > 0 And StringInStr($CardStr, "KK") > 0
                $tmpHand = "Two pair"
            Case StringInStr($CardStr, "44") > 0 And StringInStr($CardStr, "AA") > 0
                $tmpHand = "Two pair"
                ;------------------------------------------------------------------------------------
            Case StringInStr($CardStr, "55") > 0 And StringInStr($CardStr, "66") > 0
                $tmpHand = "Two pair"
            Case StringInStr($CardStr, "55") > 0 And StringInStr($CardStr, "77") > 0
                $tmpHand = "Two pair"
            Case StringInStr($CardStr, "55") > 0 And StringInStr($CardStr, "88") > 0
                $tmpHand = "Two pair"
            Case StringInStr($CardStr, "55") > 0 And StringInStr($CardStr, "99") > 0
                $tmpHand = "Two pair"
            Case StringInStr($CardStr, "55") > 0 And StringInStr($CardStr, "1010") > 0
                $tmpHand = "Two pair"
            Case StringInStr($CardStr, "55") > 0 And StringInStr($CardStr, "JJ") > 0
                $tmpHand = "Two pair"
            Case StringInStr($CardStr, "55") > 0 And StringInStr($CardStr, "QQ") > 0
                $tmpHand = "Two pair"
            Case StringInStr($CardStr, "55") > 0 And StringInStr($CardStr, "KK") > 0
                $tmpHand = "Two pair"
            Case StringInStr($CardStr, "55") > 0 And StringInStr($CardStr, "AA") > 0
                $tmpHand = "Two pair"
                ;------------------------------------------------------------------------------------
            Case StringInStr($CardStr, "66") > 0 And StringInStr($CardStr, "77") > 0
                $tmpHand = "Two pair"
            Case StringInStr($CardStr, "66") > 0 And StringInStr($CardStr, "88") > 0
                $tmpHand = "Two pair"
            Case StringInStr($CardStr, "66") > 0 And StringInStr($CardStr, "99") > 0
                $tmpHand = "Two pair"
            Case StringInStr($CardStr, "66") > 0 And StringInStr($CardStr, "1010") > 0
                $tmpHand = "Two pair"
            Case StringInStr($CardStr, "66") > 0 And StringInStr($CardStr, "JJ") > 0
                $tmpHand = "Two pair"
            Case StringInStr($CardStr, "66") > 0 And StringInStr($CardStr, "QQ") > 0
                $tmpHand = "Two pair"
            Case StringInStr($CardStr, "66") > 0 And StringInStr($CardStr, "KK") > 0
                $tmpHand = "Two pair"
            Case StringInStr($CardStr, "66") > 0 And StringInStr($CardStr, "AA") > 0
                $tmpHand = "Two pair"
                ;------------------------------------------------------------------------------------
            Case StringInStr($CardStr, "77") > 0 And StringInStr($CardStr, "88") > 0
                $tmpHand = "Two pair"
            Case StringInStr($CardStr, "77") > 0 And StringInStr($CardStr, "99") > 0
                $tmpHand = "Two pair"
            Case StringInStr($CardStr, "77") > 0 And StringInStr($CardStr, "1010") > 0
                $tmpHand = "Two pair"
            Case StringInStr($CardStr, "77") > 0 And StringInStr($CardStr, "JJ") > 0
                $tmpHand = "Two pair"
            Case StringInStr($CardStr, "77") > 0 And StringInStr($CardStr, "QQ") > 0
                $tmpHand = "Two pair"
            Case StringInStr($CardStr, "77") > 0 And StringInStr($CardStr, "KK") > 0
                $tmpHand = "Two pair"
            Case StringInStr($CardStr, "77") > 0 And StringInStr($CardStr, "AA") > 0
                $tmpHand = "Two pair"
                ;------------------------------------------------------------------------------------
            Case StringInStr($CardStr, "88") > 0 And StringInStr($CardStr, "99") > 0
                $tmpHand = "Two pair"
            Case StringInStr($CardStr, "88") > 0 And StringInStr($CardStr, "1010") > 0
                $tmpHand = "Two pair"
            Case StringInStr($CardStr, "88") > 0 And StringInStr($CardStr, "JJ") > 0
                $tmpHand = "Two pair"
            Case StringInStr($CardStr, "88") > 0 And StringInStr($CardStr, "QQ") > 0
                $tmpHand = "Two pair"
            Case StringInStr($CardStr, "88") > 0 And StringInStr($CardStr, "KK") > 0
                $tmpHand = "Two pair"
            Case StringInStr($CardStr, "88") > 0 And StringInStr($CardStr, "AA") > 0
                $tmpHand = "Two pair"
                ;------------------------------------------------------------------------------------
            Case StringInStr($CardStr, "99") > 0 And StringInStr($CardStr, "1010") > 0
                $tmpHand = "Two pair"
            Case StringInStr($CardStr, "99") > 0 And StringInStr($CardStr, "JJ") > 0
                $tmpHand = "Two pair"
            Case StringInStr($CardStr, "99") > 0 And StringInStr($CardStr, "QQ") > 0
                $tmpHand = "Two pair"
            Case StringInStr($CardStr, "99") > 0 And StringInStr($CardStr, "KK") > 0
                $tmpHand = "Two pair"
            Case StringInStr($CardStr, "99") > 0 And StringInStr($CardStr, "AA") > 0
                $tmpHand = "Two pair"
                ;------------------------------------------------------------------------------------
            Case StringInStr($CardStr, "1010") > 0 And StringInStr($CardStr, "JJ") > 0
                $tmpHand = "Two pair"
            Case StringInStr($CardStr, "1010") > 0 And StringInStr($CardStr, "QQ") > 0
                $tmpHand = "Two pair"
            Case StringInStr($CardStr, "1010") > 0 And StringInStr($CardStr, "KK") > 0
                $tmpHand = "Two pair"
            Case StringInStr($CardStr, "1010") > 0 And StringInStr($CardStr, "AA") > 0
                $tmpHand = "Two pair"
                ;------------------------------------------------------------------------------------
            Case StringInStr($CardStr, "JJ") > 0 And StringInStr($CardStr, "QQ") > 0
                $tmpHand = "Two pair"
            Case StringInStr($CardStr, "JJ") > 0 And StringInStr($CardStr, "KK") > 0
                $tmpHand = "Two pair"
            Case StringInStr($CardStr, "JJ") > 0 And StringInStr($CardStr, "AA") > 0
                $tmpHand = "Two pair"
                ;------------------------------------------------------------------------------------
            Case StringInStr($CardStr, "QQ") > 0 And StringInStr($CardStr, "KK") > 0
                $tmpHand = "Two pair"
            Case StringInStr($CardStr, "QQ") > 0 And StringInStr($CardStr, "AA") > 0
                $tmpHand = "Two pair"
                ;------------------------------------------------------------------------------------
            Case StringInStr($CardStr, "KK") > 0 And StringInStr($CardStr, "AA") > 0
                $tmpHand = "Two pair"
                ;------------------------------------------------------------------------------------
            Case StringInStr($CardStr, "22") > 0
                $tmpHand = "Pair"
            Case StringInStr($CardStr, "33") > 0
                $tmpHand = "Pair"
            Case StringInStr($CardStr, "44") > 0
                $tmpHand = "Pair"
            Case StringInStr($CardStr, "55") > 0
                $tmpHand = "Pair"
            Case StringInStr($CardStr, "66") > 0
                $tmpHand = "Pair"
            Case StringInStr($CardStr, "77") > 0
                $tmpHand = "Pair"
            Case StringInStr($CardStr, "88") > 0
                $tmpHand = "Pair"
            Case StringInStr($CardStr, "99") > 0
                $tmpHand = "Pair"
            Case StringInStr($CardStr, "1010") > 0
                $tmpHand = "Pair"
            Case StringInStr($CardStr, "JJ") > 0
                $tmpHand = "Pair"
            Case StringInStr($CardStr, "QQ") > 0
                $tmpHand = "Pair"
            Case StringInStr($CardStr, "KK") > 0
                $tmpHand = "Pair"
            Case StringInStr($CardStr, "AA") > 0
                $tmpHand = "Pair"
                ;------------------------------------------------------------------------------------
        EndSelect
    EndIf

    ConsoleWrite("$tmpHand2 = " & $tmpHand & @CRLF)

    If $tmpHand = "" Then
        ;nothing to win
    Else
        TakeWin($tmpHand)
    EndIf

EndFunc   ;==>ChekForWin
;-------------------------------------------------------------------------------
Func TakeWin($Hand) ;amount to take
    Local $Msg
    Select    ;win $Hand
        Case $Hand = "Royal Flush"
            $WinAmount = 89
        Case $Hand = "Straight Flush"
            $WinAmount = 55
        Case $Hand = "Flush"
            $WinAmount = 34
        Case $Hand = "Four of kind"
            $WinAmount = 21
        Case $Hand = "Full house"
            $WinAmount = 13
        Case $Hand = "Straight"
            $WinAmount = 8
        Case $Hand = "Three of kind"
            $WinAmount = 5
        Case $Hand = "Two pair"
            $WinAmount = 3
        Case $Hand = "Pair"
            $WinAmount = 2
    EndSelect

    GUICtrlSetState($Button1, $GUI_DISABLE)

    GUICtrlSetFont($Label1, 24, 800, 0, "MS Sans Serif")
    GUICtrlSetData($Label1, $Hand)

    ; blink
    GUICtrlSetColor($Label1, 0xFF0000) ;red
    Sleep(300)
    GUICtrlSetColor($Label1, 0xFFFFFF) ;White
    Sleep(300)
    GUICtrlSetColor($Label1, 0xFF0000) ;red
    Sleep(300)
    GUICtrlSetColor($Label1, 0xFFFFFF) ;White
    Sleep(300)
    GUICtrlSetColor($Label1, 0xFF0000) ;red
    Sleep(300)
    GUICtrlSetColor($Label1, 0xFFFFFF) ;White

    ConsoleWrite("TakeWin ------------" & @CRLF)
    BlackRed()


EndFunc   ;==>TakeWin
;-------------------------------------------------------------------------------
Func BlackRed() ;Black Red bet

    Local $Msg
    TurnCards()

    $Msg = "Win amount " & $WinAmount & ",  choose black - red to double it  or press take to take it"
    ;GUICtrlSetFont($Label1, 24, 800, 0, "MS Sans Serif")
    GUICtrlSetFont($Label1, 12, 800, 0, "MS Sans Serif")
    GUICtrlSetData($Label1, $Msg)

    $GameMode = "Black-Red"
    GUICtrlSetData($Button1, "TAKE")
    GUISetBkColor($COLOR_PURPLE) ; will change background color

    GUICtrlSetState($Button1, $GUI_ENABLE)
    GUICtrlSetState($Button2, $GUI_SHOW)
    GUICtrlSetState($Button3, $GUI_SHOW)

    ;GUICtrlSetState($Button1, $GUI_ENABLE)

    ConsoleWrite("Win amount = " & $WinAmount & @CRLF)

EndFunc   ;==>BlackRed
;-------------------------------------------------------------------------------
Func CardColor($crdColor) ; check Black Red bet
    Local $Par1, $Par2
    If $crdColor = "Red" Then
        $Par1 = "D"
        $Par2 = "H"
    Else
        $Par1 = "C"
        $Par2 = "S"
    EndIf

    Local $X = $Cnt, $CardColor
    $Cnt += 1
    GUICtrlSetImage($Pic3, @ScriptDir & "\card\" & $aCard[$X][0] & ".jpg")

    Sleep(1000)

    $CardColor = $aCard[$X][1]

    If $CardColor = $Par1 Or $CardColor = $Par2 Then ;win
        $WinAmount = $WinAmount + $WinAmount
        BlackRed()
    Else
        $WinAmount = 0
        ConsoleWrite("Win amount = " & 0 & @CRLF)
        TurnCards()
        GUICtrlSetState($Button2, $GUI_HIDE)
        GUICtrlSetState($Button3, $GUI_HIDE)
        GUICtrlSetFont($Label1, 24, 800, 0, "MS Sans Serif")
        GUICtrlSetData($Label1, "")
        GUICtrlSetData($Label2, $Score)
        $GameMode = "Play"
        GUICtrlSetData($Button1, "DEAL")
        GUISetBkColor($COLOR_TEAL)

    EndIf
EndFunc   ;==>CardColor
;-------------------------------------------------------------------------------

Please, leave your comments and experiences here

Thank you !

card_deck.zip

Edited by ioa747
Link to comment
Share on other sites

Thanks for sharing this. Nice work, only Problem: 1 played ~ 5 hours and after ending i didn't get my won money 4578$ - the 100 credit.

 

I used your card-deck for a little script. The player must remember a card, and after each run tell in which column the remebered card is now.

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Icon=..\..\..\..\IconViewer\Icons\pifmgr_23.ico
#AutoIt3Wrapper_Outfile_x64=..\..\Desktop\MagicCards.Exe
#AutoIt3Wrapper_Res_Fileversion=1.0.3.1
#AutoIt3Wrapper_Res_ProductVersion=1.03
#AutoIt3Wrapper_Res_LegalCopyright=autoBert
#AutoIt3Wrapper_Res_Language=1031
#AutoIt3Wrapper_AU3Check_Parameters=-q -d -w 1 -w 2 -w 3 -w- 4 -w 5 -w 6
#AutoIt3Wrapper_Run_Tidy=y
#Tidy_Parameters=/gd
#AutoIt3Wrapper_Run_Au3Stripper=y
#Au3Stripper_Parameters=/mo /rsln
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
;compstui.dll
;noch auf Updaten der Labels umstellen

#include <ComboConstants.au3>
#include <StaticConstants.au3>
#include <ColorConstants.au3>
#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>
#include <Array.au3>
#include <ScreenCapture.au3>

Global $iDelay = 150, $iRound = 0, $sCards, $iCard, $sInCol, $iMsg
Global $sCardsFP = @ScriptDir & '\Card\'
;Kartensatz generieren
Global $aCards[32][5], $aCardsSave[32][5], $iCards = 0
Global $aColors = ['Diamond', 'Heart', 'spade', 'Clubs']
Global $aWerte = ['7', '8', '9', '10', 'Jack', 'Queen', 'King', 'Ace']

Global $sTitel = 'Magic Cards', $iWidth = 415, $iHeight = @DesktopHeight - 60
Global $sJpgPath = @AppDataDir & '\' & $sTitel
If Not FileExists($sJpgPath) Then DirCreate($sJpgPath)
;ShellExecute($sJpgPath)
Global $hTable = GUICreate($sTitel, $iWidth, $iHeight)  ; , BitOR($WS_MINIMIZEBOX, $WS_MAXIMIZEBOX, $WS_SIZEBOX))
Global $idCboInCol = GUICtrlCreateCombo('Linke', 0, 2, 140, $CBS_SIMPLE)
Global $idBtnRound = GUICtrlCreateButton(' &Start', 145, 2, 60, 26)
;GUICtrlSetBkColor(-1, $COLOR_LIGHTGRAY)
GUICtrlSetColor(-1, $COLOR_RED)
GUICtrlSetData($idCboInCol, 'Mittlere|Rechte', 'Linke')
GUISetState()
;#cs
_CardsShuffle()
$iRound = -1
For $jRows = 0 To 6
    For $iCols = 0 To 2
        _ShowCard($iCard, $iCols * 135 + 5, $jRows * 95 + 30, $iCols)
        $aCards[$iCard][2] = $jRows
        GUICtrlSetState(-1, 160)         ;(hiden & disabled)
        $iCard = $iCard + 1
    Next
Next
;_ArrayDisplay($aCards)
;#ce

;erzeugt eine GUI
GUISetBkColor($COLOR_GRAY)
;GUISetIcon("C:\Users\(len)Bert\Pictures\Icons\pifmgr_23.ico", $hTable)
GUISetIcon(@SystemDir & '\pifmgr.dll', -24)
GUICtrlSetState($idBtnRound, BitOR($GUI_ENABLE, $gui_show))
GUISetState()

Global $msg
While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $idBtnRound
            ConsoleWrite(@ScriptLineNumber & @TAB & 'Runde: ' & $iRound & @CRLF)
            If $iRound = -1 Then
                $iRound = $iRound + 1
                _PlaceCarts()
            Else
                $sInCol = GUICtrlRead($idCboInCol)
                If $iRound > 0 Then _SortForCols($sInCol)
            EndIf
            ;_ArrayDisplay($aCards, $iRound)
            GUICtrlSetColor($idBtnRound, $COLOR_Black)
            $iRound = $iRound + 1
            _PlaceCarts()
            ;ConsoleWrite($sJpgPath & '\mm' & $iRound & '.jpg' & @CRLF)
            GUICtrlSetData($idBtnRound, 'Runde ' & $iRound)
            ;ConsoleWrite($iRound & 'Gegeben' & @CRLF)
            WinSetTitle($hTable, '', $sTitel & ' ' & $hTable & ' ' & @HOUR & ':' & @MIN & ':' & @SEC & ':' & @MSEC) 
            Sleep(500)
            _ScreenCapture_CaptureWnd($sJpgPath & '\mm' & $iRound & '.jpg', $hTable)
            WinSetTitle($hTable, '', $sTitel)
            ControlFocus($hTable, '', $idCboInCol)
            ;#cs
            If $iRound = 4 Then
                GUICtrlSetState($idCboInCol, $GUI_DISABLE)
                GUICtrlSetData($idCboInCol, 'Mittlere')
                _SortForCols('Mittlere')
                _ShowCard(10, 140, 315, 1)
                GUICtrlSetData($idBtnRound, 'Lösung ')
                GUICtrlSetBkColor($aCards[10][0], $COLOR_FIREBRICK)
                ;           ;_ArrayDisplay($aCards)
                Sleep(5000)
                ;GUISetState(@SW_SHOWNORMAL , $hTable)
                ConsoleWrite(@ScriptLineNumber & @TAB & 'nochmal? ' & $iRound & @CRLF)

                $iMsg = $IDretry
                If MsgBox($MB_YESNO + $MB_ICONQUESTION, 'Lösungskarte war: ' & $aCards[10][4], 'Noch einmal?', 15, $hTable) = $idyes Then Exit ShellExecute(@DesktopDir & '\MagicCards.Exe')
                Exit

            EndIf

        Case $idCboInCol
            ;GUICtrlSetState($idCboInCol, $GUI_DISABLE)
            GUICtrlSetState($idBtnRound, $GUI_ENABLE)
    EndSwitch
WEnd

Func _SortForCols($sCol)
    ;ConsoleWrite('===========================' & $sCol & '===========================' & @CRLF)
    ;_ArrayDisplay($aCards)
    Local $aFound, $iCard = $aCards[0][0], $acardsNew[32][5]
    Local $sCols ;$iCols,
    Switch $sCol
        Case 'Linke'
            $sCols = 'Mittlere|Linke|Rechte'
        Case 'Rechte'
            $sCols = 'Linke|Rechte|Mittlere'
        Case 'Mittlere'
            $sCols = 'Linke|Mittlere|Rechte'
    EndSwitch
    Local $aCardsCols = StringSplit($sCols, '|', 3)
    ;ConsoleWrite($sCols & @CRLF)
    $aFound = _ArrayFindAll($aCards, $aCardsCols[0], 0, 0, 0, 0, 3)
    ;_ArrayDisplay($aFound)
    For $i = 0 To UBound($aFound) - 1
        ;For $iCols = 1 To 4
        $acardsNew[$i][1] = $aCards[$aFound[$i]][1]
        ;Next
        $acardsNew[$i][0] = $iCard
        ;GUICtrlSetState($iCard, 160)     ;(hidden & disabled)
    Next
    $aFound = _ArrayFindAll($aCards, $aCardsCols[1], 0, 0, 0, 0, 3)
    ;   ;_ArrayDisplay($aFound)
    For $i = 0 To UBound($aFound) - 1
        ;For $iCols = 1 To 4
        $acardsNew[$i + 7][1] = $aCards[$aFound[$i]][1]
        ;Next
        $acardsNew[$i][0] = $iCard
        ;GUICtrlSetState($iCard, 160)     ;(hidden & disabled)
    Next
    $aFound = _ArrayFindAll($aCards, $aCardsCols[2], 0, 0, 0, 0, 3)
    ;   ;_ArrayDisplay($aFound)
    For $i = 0 To UBound($aFound) - 1
        ;For $iCols = 1 To 4
        $acardsNew[$i + 14][1] = $aCards[$aFound[$i]][1]
        ;Next
        $acardsNew[$i][0] = $iCard
        ;GUICtrlSetState($iCard, 160)     ;(hidden & disabled)
    Next
    For $i = 0 To 20
        $acardsNew[$i][0] = 0
        $acardsNew[$i][2] = $aCards[$i][2]
        $acardsNew[$i][3] = $aCards[$i][3]
        $acardsNew[$i][4] = StringReplace($aCards[$i][1], '_', ' ')
    Next
    $aCards = $acardsNew
    ;_ArrayDisplay($acards, 'Picked Up' & $iRound)
EndFunc   ;==>_SortForCols

Func _PlaceCarts()
    ConsoleWrite($iRound & @CRLF)
    Local $jRows, $iCols, $iCard
    If $iRound > 0 Then
        For $i = 0 To 20
            GUICtrlDelete($aCards[$i][0])
        Next
    EndIf
    For $jRows = 0 To 6
        For $iCols = 0 To 2
            _ShowCard($iCard, $iCols * 135 + 5, $jRows * 95 + 30, $iCols)
            If $iRound > 0 Then Sleep($iDelay)
            $iCard = $iCard + 1
        Next
    Next
EndFunc   ;==>_PlaceCarts

Func _ShowCard($iNr, $x, $y, $iCol)
    ;   Local $aColors = [$COLOR_DARKORANGE, $COLOR_RED, $COLOR_Green, $COLOR_Black]
    Local $aCols = ['Linke', 'Mittlere', 'Rechte'], $iErr
    Switch $iRound
        Case -1, 1, 2, 3, 4
            $aCards[$iNr][0] = GUICtrlCreatePic($sCardsFP & $aCards[$iNr][1], $x, $y, 131, 190)
            GUICtrlSetState($aCards[$iNr][0], 80)     ;(show & enabled)
        Case 0
            $aCards[$iNr][0] = GUICtrlCreatePic($sCardsFP & $aCards[$iNr][1], $x, $y, 131, 190)
            GUICtrlSetState($aCards[$iNr][0], 80)     ;(show & enabled)
        Case Else
    EndSwitch
    ;$sCardsFP & $aCardsSave[$iNr][1] & '|' &
    If $iErr Then ConsoleWrite($sCardsFP & $aCards[$iNr][1] & '|' & $aCards[$iNr][0] & @TAB & ' Pos: ' & $x & '|' & $y & @TAB & 'Error: ' & $iErr & @CRLF)
    $aCards[$iNr][3] = $aCols[$iCol]
EndFunc   ;==>_ShowCard

Func _CardsShuffle()
    ;_ArrayDisplay($aColors)
    For $iColors = 0 To 3
        For $jWerte = 0 To 7
            $iCards = $iColors * 8 + $jWerte
            ;$aCards[$iCards][0] = $iCards
            $aCards[$iCards][1] = $aColors[$iColors] & '_' & $aWerte[$jWerte] & '.jpg'
            $aCards[$iCards][2] = $iColors
            $aCards[$iCards][4] = $aColors[$iColors] & ' ' & $aWerte[$jWerte]
            ;MsgBox(64,'',$iCards & ': ' & $aCards[$iCards][1]); & @CRLF)
            ;ConsoleWrite($iCards & ': ' & $aCards[$iCards][1] & @CRLF)
        Next
    Next
    _ArrayShuffle($aCards, 0, 0)
    ConsoleWrite(@ScriptLineNumber & 'Gemischt' & @CRLF)
EndFunc   ;==>_CardsShuffle

My uncle played it with me over 60 years ago.

The script runs, but i must polish the code.

Edited by AutoBert
added code for documentation (.JPG)
Link to comment
Share on other sites

  • ioa747 changed the title to poker game (The first steps of using arrays)
2 hours ago, AutoBert said:

after ending i didn't get my won money 4578$ - the 100 credit

when you get it, don't forget me, I want a cut too!  :)

 I'm glad you like it and have fun with this.

for me it was a challenge, how to  catch all the winning hands combination

 

Τhank you for responding !

P.S.  in your game I didn't understand how to choose which card you will remember

Link to comment
Share on other sites

8 hours ago, ioa747 said:

in your game I didn't understand how to choose which card you will remember

Oh, i see i must integrate advisories for the user.

Spoiler

It isn't a real game it's a "magic" card trick. 3 rounds with correct user input the rememberd card is always on place 11, in the mid of row from the middle column.   

 

Link to comment
Share on other sites

Never played poker so don't know the rules of this game 
just for fun try to trim ChekForWin() code
@ioa747 as it your code you can tell if my modified code work or not.

Func ChekForWin() ;Check for Win
    Local $tmpHand = "", $CardStr = ""

    _ArraySort($HandCard, 0, 1, 0, 3) ; array sort by card order
    ;_ArrayDisplay($HandCard, "ChekForWin")

    ;------------------------------------------------------------------------------------
    ; Flush
    For $i = 1 To $HandCard[0][0]
        $CardStr = $CardStr & $HandCard[$i][1]
    Next

    If StringRegExp($CardStr, 'CCCCC|DDDDD|HHHHH|SSSSS', 0) Then $tmpHand = "Flush"
    ;------------------------------------------------------------------------------------
    $CardStr = ""
    For $i = 1 To $HandCard[0][0]
        $CardStr = $CardStr & $HandCard[$i][2]
    Next

    ConsoleWrite("ChekForWin ---------" & @CRLF)
    ConsoleWrite("$CardStr = " & $CardStr & @CRLF)
    ConsoleWrite("$tmpHand1 = " & $tmpHand & @CRLF)
    ;------------------------------------------------------------------------------------
    ; '910JQK' (Straight Flush)| '10JQKA' (Royal Flush)
    ; 'A2345' (Straight)| '24556' (pair)| '25556' (Three of kind)| '25555' (Four of kind)| '556QQ' (Two pair)| '66777' (Full house)
    Local $o_Card = '2345678910JQKA'
    Local $o_Pattern = StringRegExp($CardStr, "([2-9AJQK]|10)\1+", 3)

    Local $CountPoint = 0
    If $tmpHand = "Flush" Then
        $CountPoint = StringInStr($o_Card, $CardStr)
        If $CountPoint <> 0  Then $tmpHand = (($CountPoint = 9) ? 'Royal Flush' : 'Straight Flush')
    Else
        If UBound($o_Pattern) = 0 Then
            $o_Card = 'A' & $o_Card
            If StringInStr($o_Card, $CardStr) Then $tmpHand = 'Straight'
        Else
            For $i = 0 To UBound($o_Pattern) - 1
                StringReplace($CardStr, $o_Pattern[$i], '')
                $CountPoint += @Extended
            Next
            If $CountPoint = 2  Then $tmpHand = 'pair'
            If $CountPoint = 3  Then $tmpHand = 'Three of kind'
            If ($CountPoint = 4) Then $tmpHand = ((UBound($o_Pattern) = 1) ? 'Four of kind' : 'Two pair')
            If $CountPoint = 5  Then $tmpHand = 'Full house'
        Endif
    EndIf
    ConsoleWrite("$tmpHand2 = " & $tmpHand & @CRLF)
    ;------------------------------------------------------------------------------------

    If $tmpHand = "" Then
        ;nothing to win
    Else
        TakeWin($tmpHand)
    EndIf
EndFunc   ;==>ChekForWin

 

Link to comment
Share on other sites

@ioa747 Converting your 680 line ChekForWin() code to 56 line code was fun.

I asked to check my modified code working or not.

10 hours ago, jugador said:

@ioa747 as it your code you can tell if my modified code work or not.

but (look like) you instantly replied something I didn't understand.  :bye:

Link to comment
Share on other sites

 

I tried the script you posted and it didn't work. I had to look it up in something I did 10 years ago (in the 1200 lines).

that's why I told you it's difficult

I am glad you made it in the end.
why didn't you post your script too?

(from me you've got the right) :)

Edited by ioa747
Link to comment
Share on other sites

ok I download your code and try with my ChekForWin() code.
look to me it's working.

 

2 hours ago, ioa747 said:

I tried the script you posted and it didn't work.

@ioa747 would you mind telling why it's not working

which pattern it failed to recognize....
(Straight Flush)|(Royal Flush)| (Straight)|(pair)|(Three of kind)|(Four of kind)|(Two pair)|(Full house)

Link to comment
Share on other sites

2 hours ago, jugador said:

@ioa747 would you mind telling why it's not working

:oops: I owe you an apology
I didn't understand what exactly you did, I downloaded it, I ran it and as it was natural, it gave me an error because it couldn't find the variables.
Now that I saw it better I understood that I had to put it in the program, and replace the function,

and yes it works !!

(I didn't check if it catches all the cases)
amazing job well done and sorry again

Link to comment
Share on other sites

shorter version thanks to @jugador

; https://www.autoitscript.com/forum/topic/209569-poker-game-the-first-steps-of-using-arrays/?do=findComment&comment=1512307

#NoTrayIcon
#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Icon=poker.ico
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <ColorConstants.au3>
#include <Array.au3>

Opt("MustDeclareVars", 1) ;0=no, 1=require pre-declaration
#Region === GUI ===
Local $Form1_1 = GUICreate("Poker", 769, 382, 374, 395)
GUISetBkColor($COLOR_TEAL)
GUISetIcon(@ScriptDir & "\spade.ico")

Local $Pic1 = GUICtrlCreatePic("", 20, 60, 130, 190)
GUICtrlSetState(-1, $GUI_DISABLE)
Local $Pic2 = GUICtrlCreatePic("", 170, 60, 130, 190)
GUICtrlSetState(-1, $GUI_DISABLE)
Local $Pic3 = GUICtrlCreatePic("", 320, 60, 130, 190)
GUICtrlSetState(-1, $GUI_DISABLE)
Local $Pic4 = GUICtrlCreatePic("", 470, 60, 130, 190)
GUICtrlSetState(-1, $GUI_DISABLE)
Local $Pic5 = GUICtrlCreatePic("", 620, 60, 130, 190)
GUICtrlSetState(-1, $GUI_DISABLE)

Local $Hold1 = GUICtrlCreateLabel("", 20, 250, 130, 33, $SS_CENTER)
GUICtrlSetFont(-1, 17, 800, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0xFFFF00) ;Yellow
Local $Hold2 = GUICtrlCreateLabel("", 170, 250, 130, 33, $SS_CENTER)
GUICtrlSetFont(-1, 17, 800, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0xFFFF00) ;Yellow
Local $Hold3 = GUICtrlCreateLabel("", 320, 250, 130, 33, $SS_CENTER)
GUICtrlSetFont(-1, 17, 800, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0xFFFF00) ;Yellow
Local $Hold4 = GUICtrlCreateLabel("", 470, 250, 130, 33, $SS_CENTER)
GUICtrlSetFont(-1, 17, 800, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0xFFFF00) ;Yellow
Local $Hold5 = GUICtrlCreateLabel("", 620, 250, 130, 33, $SS_CENTER)
GUICtrlSetFont(-1, 17, 800, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0xFFFF00) ;Yellow

Local $Label1 = GUICtrlCreateLabel("", 20, 10, 587, 41, $SS_CENTER)
GUICtrlSetFont(-1, 24, 800, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0xFFFFFF) ;White

Local $Label2 = GUICtrlCreateLabel("", 620, 10, 130, 33, $SS_CENTER)
GUICtrlSetFont(-1, 17, 800, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0xFFFF00) ;Yellow

Local $Button1 = GUICtrlCreateButton("START", 20, 320, 735, 35)
GUICtrlSetFont(-1, 14, 400, 0, "MS Sans Serif")
;GUICtrlSetColor(-1, 0x000000)

Local $Button2 = GUICtrlCreateButton("RED", 290, 280, 100, 35)
GUICtrlSetState(-1, $GUI_HIDE)
Local $Button3 = GUICtrlCreateButton("BLACK", 400, 280, 100, 35)
GUICtrlSetState(-1, $GUI_HIDE)

GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
#Region === make the card ===
;clubs diamonds hearts spades
Local $aColor = ["clubs", "heart", "diamond", "spade"]
Local $shColor = ["C", "H", "D", "S"]
Local $k, $nMsg, $Str
Local $at = ["2", "3", "4", "5", "6", "7", "8", "9", "10", "jack", "queen", "king", "ace"]
Local $Oat = ["102", "103", "104", "105", "106", "107", "108", "109", "110", "111", "112", "113", "114"]
Local $aCard[53][4]
$aCard[0][0] = 52

$k = 1
For $C = 0 To UBound($aColor) - 1
    For $j = 0 To UBound($at) - 1
        $aCard[$k][0] = $aColor[$C] & "_" & $at[$j] ; card full name
        $aCard[$k][1] = $shColor[$C]                ; suit
        $aCard[$k][2] = $at[$j]                     ; card
        $aCard[$k][3] = $Oat[$j]                    ; order
        $k += 1
    Next
Next

ReplaceInArray($aCard, "jack", "J", 2)
ReplaceInArray($aCard, "queen", "Q", 2)
ReplaceInArray($aCard, "king", "K", 2)
ReplaceInArray($aCard, "ace", "A", 2)

$aColor = 0
$shColor = 0
$at = 0
$Oat = 0
;_ArrayDisplay($aCard)
_ArrayShuffle($aCard, 1)
#EndRegion === make the card ===
Local $Rnt = 1, $Cnt = 1, $Score = 100, $GameMode = "Play", $WinAmount
Local $HandCard[6][4]
$HandCard[0][0] = 5
;*******************************************************************************
While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Pic1
            If GUICtrlRead($Hold1) = "" Then
                GUICtrlSetData($Hold1, "Hold")
            Else
                GUICtrlSetData($Hold1, "")
            EndIf
        Case $Pic2
            If GUICtrlRead($Hold2) = "" Then
                GUICtrlSetData($Hold2, "Hold")
            Else
                GUICtrlSetData($Hold2, "")
            EndIf
        Case $Pic3
            If GUICtrlRead($Hold3) = "" Then
                GUICtrlSetData($Hold3, "Hold")
            Else
                GUICtrlSetData($Hold3, "")
            EndIf
        Case $Pic4
            If GUICtrlRead($Hold4) = "" Then
                GUICtrlSetData($Hold4, "Hold")
            Else
                GUICtrlSetData($Hold4, "")
            EndIf
        Case $Pic5
            If GUICtrlRead($Hold5) = "" Then
                GUICtrlSetData($Hold5, "Hold")
            Else
                GUICtrlSetData($Hold5, "")
            EndIf
            ;-------------------
        Case $Hold1

        Case $Button1  ;deal
            Button1()

        Case $Button2  ;red
            Button2()

        Case $Button3  ;black
            Button3()

    EndSwitch
WEnd
;********************************************************************************

;-------------------------------------------------------------------------------
Func Button1() ; deal , take
    Select
        Case $GameMode = "Play" ; then deal
            Deal()
        Case $GameMode = "Black-Red" ; then take
            $Score = $Score + $WinAmount
            GUICtrlSetState($Button2, $GUI_HIDE)
            GUICtrlSetState($Button3, $GUI_HIDE)
            GUICtrlSetFont($Label1, 24, 800, 0, "MS Sans Serif")
            GUICtrlSetData($Label1, "")
            GUICtrlSetData($Label2, $Score)
            GUICtrlSetFont($Label2, 24, 800, 0, "MS Sans Serif")
            Sleep(500)
            GUICtrlSetFont($Label2, 17, 800, 0, "MS Sans Serif")
            ;GUICtrlSetFont($Label2, 17, 800, 0, "MS Sans Serif")
            ;GUICtrlSetColor($Label2, 0xFFFF00) ;Yellow

            $GameMode = "Play"
            GUICtrlSetData($Button1, "DEAL")
            GUISetBkColor($COLOR_TEAL)

    EndSelect

EndFunc   ;==>Button1
;-------------------------------------------------------------------------------
Func Button2() ;red
    CardColor("Red")
EndFunc   ;==>Button2
;-------------------------------------------------------------------------------
Func Button3() ;black
    CardColor("Black")
EndFunc   ;==>Button3
;-------------------------------------------------------------------------------
Func ReplaceInArray(ByRef $Array, $oStr, $nStr, $Col)
    For $i = 0 To UBound($Array) - 1
        If $Array[$i][$Col] = $oStr Then
            $Array[$i][$Col] = $nStr
            ;ConsoleWrite ($oStr & " in " & $i & " to " & $nStr & @CRLF)
        EndIf
    Next
    ;ToConsole($Array, $Col)
EndFunc   ;==>ReplaceInArray
;-------------------------------------------------------------------------------
Func ToConsole($Array, $Col) ;write array to console
    For $i = 0 To UBound($Array) - 1
        ConsoleWrite($Array[$i][$Col] & "  ")
    Next
    ConsoleWrite(@CRLF)

EndFunc   ;==>ToConsole
;-------------------------------------------------------------------------------
Func TurnCards() ;TurnCards
    GUICtrlSetImage($Pic1, @ScriptDir & "\card\back04.jpg")
    GUICtrlSetImage($Pic2, @ScriptDir & "\card\back04.jpg")
    GUICtrlSetImage($Pic3, @ScriptDir & "\card\back04.jpg")
    GUICtrlSetImage($Pic4, @ScriptDir & "\card\back04.jpg")
    GUICtrlSetImage($Pic5, @ScriptDir & "\card\back04.jpg")
EndFunc   ;==>TurnCards
;-------------------------------------------------------------------------------
Func Deal() ;Deal the Cards
    Local $C, $R
    If $Rnt = 1 Then
        TurnCards()
        Sleep(300)
        _ArrayShuffle($aCard, 1)
        ckHolder()

        $Score = $Score - 1
        GUICtrlSetData($Label2, $Score)

        GUICtrlSetImage($Pic1, @ScriptDir & "\card\" & $aCard[1][0] & ".jpg")
        GUICtrlSetImage($Pic2, @ScriptDir & "\card\" & $aCard[2][0] & ".jpg")
        GUICtrlSetImage($Pic3, @ScriptDir & "\card\" & $aCard[3][0] & ".jpg")
        GUICtrlSetImage($Pic4, @ScriptDir & "\card\" & $aCard[4][0] & ".jpg")
        GUICtrlSetImage($Pic5, @ScriptDir & "\card\" & $aCard[5][0] & ".jpg")

        For $C = 0 To 3
            For $R = 1 To 5
                $HandCard[$R][$C] = $aCard[$R][$C]
            Next
        Next
        ;_ArrayDisplay($HandCard, "Deal")
        ToConsole($HandCard, 2)

        $Rnt = 2
        $Cnt = 6
    Else

        If GUICtrlRead($Hold1) = "" Then
            GUICtrlSetImage($Pic1, @ScriptDir & "\card\" & $aCard[$Cnt][0] & ".jpg")
            $HandCard[1][0] = $aCard[$Cnt][0]
            $HandCard[1][1] = $aCard[$Cnt][1]
            $HandCard[1][2] = $aCard[$Cnt][2]
            $HandCard[1][3] = $aCard[$Cnt][3]
            $Cnt += 1
        EndIf
        If GUICtrlRead($Hold2) = "" Then
            GUICtrlSetImage($Pic2, @ScriptDir & "\card\" & $aCard[$Cnt][0] & ".jpg")
            $HandCard[2][0] = $aCard[$Cnt][0]
            $HandCard[2][1] = $aCard[$Cnt][1]
            $HandCard[2][2] = $aCard[$Cnt][2]
            $HandCard[2][3] = $aCard[$Cnt][3]
            $Cnt += 1
        EndIf
        If GUICtrlRead($Hold3) = "" Then
            GUICtrlSetImage($Pic3, @ScriptDir & "\card\" & $aCard[$Cnt][0] & ".jpg")
            $HandCard[3][0] = $aCard[$Cnt][0]
            $HandCard[3][1] = $aCard[$Cnt][1]
            $HandCard[3][2] = $aCard[$Cnt][2]
            $HandCard[3][3] = $aCard[$Cnt][3]
            $Cnt += 1
        EndIf
        If GUICtrlRead($Hold4) = "" Then
            GUICtrlSetImage($Pic4, @ScriptDir & "\card\" & $aCard[$Cnt][0] & ".jpg")
            $HandCard[4][0] = $aCard[$Cnt][0]
            $HandCard[4][1] = $aCard[$Cnt][1]
            $HandCard[4][2] = $aCard[$Cnt][2]
            $HandCard[4][3] = $aCard[$Cnt][3]
            $Cnt += 1
        EndIf
        If GUICtrlRead($Hold5) = "" Then
            GUICtrlSetImage($Pic5, @ScriptDir & "\card\" & $aCard[$Cnt][0] & ".jpg")
            $HandCard[5][0] = $aCard[$Cnt][0]
            $HandCard[5][1] = $aCard[$Cnt][1]
            $HandCard[5][2] = $aCard[$Cnt][2]
            $HandCard[5][3] = $aCard[$Cnt][3]
            $Cnt += 1
        EndIf

        ckHolder()
        ToConsole($HandCard, 2)
        ChekForWin()
        $Rnt = 1
    EndIf

EndFunc   ;==>Deal
;-------------------------------------------------------------------------------
Func ckHolder() ;Check the Holders
    If GUICtrlRead($Label2) = "" Then GUICtrlSetData($Label2, $Score)

    If $Rnt = 1 Then
        ConsoleWrite("********************" & @CRLF)
        ConsoleWrite($Rnt & " Round ------------" & @CRLF)
        GUICtrlSetData($Button1, "OK")
        GUICtrlSetFont($Label1, 18, 800, 0, "MS Sans Serif")
        GUICtrlSetData($Label1, "hold your cards")

        GUICtrlSetState($Pic1, $GUI_ENABLE)
        GUICtrlSetState($Pic2, $GUI_ENABLE)
        GUICtrlSetState($Pic3, $GUI_ENABLE)
        GUICtrlSetState($Pic4, $GUI_ENABLE)
        GUICtrlSetState($Pic5, $GUI_ENABLE)

        GUICtrlSetData($Hold1, "")
        GUICtrlSetData($Hold2, "")
        GUICtrlSetData($Hold3, "")
        GUICtrlSetData($Hold4, "")
        GUICtrlSetData($Hold5, "")
    ElseIf $Rnt = 2 Then
        ConsoleWrite($Rnt & " Round ------------" & @CRLF)
        GUICtrlSetData($Button1, "DEAL")
        ;GUICtrlSetFont($Label1, 12, 800, 0, "MS Sans Serif")
        GUICtrlSetData($Label1, "")

        GUICtrlSetState($Pic1, $GUI_DISABLE)
        GUICtrlSetState($Pic2, $GUI_DISABLE)
        GUICtrlSetState($Pic3, $GUI_DISABLE)
        GUICtrlSetState($Pic4, $GUI_DISABLE)
        GUICtrlSetState($Pic5, $GUI_DISABLE)

        GUICtrlSetData($Hold1, "")
        GUICtrlSetData($Hold2, "")
        GUICtrlSetData($Hold3, "")
        GUICtrlSetData($Hold4, "")
        GUICtrlSetData($Hold5, "")

    ElseIf $Rnt = 3 Then

    EndIf

EndFunc   ;==>ckHolder
;-------------------------------------------------------------------------------
Func TakeWin($Hand) ;amount to take
    Local $Msg
    Select    ;win $Hand
        Case $Hand = "Royal Flush"
            $WinAmount = 89
        Case $Hand = "Straight Flush"
            $WinAmount = 55
        Case $Hand = "Flush"
            $WinAmount = 34
        Case $Hand = "Four of kind"
            $WinAmount = 21
        Case $Hand = "Full house"
            $WinAmount = 13
        Case $Hand = "Straight"
            $WinAmount = 8
        Case $Hand = "Three of kind"
            $WinAmount = 5
        Case $Hand = "Two pair"
            $WinAmount = 3
        Case $Hand = "Pair"
            $WinAmount = 2
    EndSelect

    GUICtrlSetState($Button1, $GUI_DISABLE)

    GUICtrlSetFont($Label1, 24, 800, 0, "MS Sans Serif")
    GUICtrlSetData($Label1, $Hand)

    ; blink
    GUICtrlSetColor($Label1, 0xFF0000) ;red
    Sleep(300)
    GUICtrlSetColor($Label1, 0xFFFFFF) ;White
    Sleep(300)
    GUICtrlSetColor($Label1, 0xFF0000) ;red
    Sleep(300)
    GUICtrlSetColor($Label1, 0xFFFFFF) ;White
    Sleep(300)
    GUICtrlSetColor($Label1, 0xFF0000) ;red
    Sleep(300)
    GUICtrlSetColor($Label1, 0xFFFFFF) ;White

    ConsoleWrite("TakeWin ------------" & @CRLF)
    BlackRed()


EndFunc   ;==>TakeWin
;-------------------------------------------------------------------------------
Func BlackRed() ;Black Red bet

    Local $Msg
    TurnCards()

    $Msg = "Win amount " & $WinAmount & ",  choose black - red to double it  or press take to take it"
    ;GUICtrlSetFont($Label1, 24, 800, 0, "MS Sans Serif")
    GUICtrlSetFont($Label1, 12, 800, 0, "MS Sans Serif")
    GUICtrlSetData($Label1, $Msg)

    $GameMode = "Black-Red"
    GUICtrlSetData($Button1, "TAKE")
    GUISetBkColor($COLOR_PURPLE) ; will change background color

    GUICtrlSetState($Button1, $GUI_ENABLE)
    GUICtrlSetState($Button2, $GUI_SHOW)
    GUICtrlSetState($Button3, $GUI_SHOW)

    ;GUICtrlSetState($Button1, $GUI_ENABLE)

    ConsoleWrite("Win amount = " & $WinAmount & @CRLF)

EndFunc   ;==>BlackRed
;-------------------------------------------------------------------------------
Func CardColor($crdColor) ; check Black Red bet
    Local $Par1, $Par2
    If $crdColor = "Red" Then
        $Par1 = "D"
        $Par2 = "H"
    Else
        $Par1 = "C"
        $Par2 = "S"
    EndIf

    Local $X = $Cnt, $CardColor
    $Cnt += 1
    GUICtrlSetImage($Pic3, @ScriptDir & "\card\" & $aCard[$X][0] & ".jpg")

    Sleep(1000)

    $CardColor = $aCard[$X][1]

    If $CardColor = $Par1 Or $CardColor = $Par2 Then ;win
        $WinAmount = $WinAmount + $WinAmount
        BlackRed()
    Else
        $WinAmount = 0
        ConsoleWrite("Win amount = " & 0 & @CRLF)
        TurnCards()
        GUICtrlSetState($Button2, $GUI_HIDE)
        GUICtrlSetState($Button3, $GUI_HIDE)
        GUICtrlSetFont($Label1, 24, 800, 0, "MS Sans Serif")
        GUICtrlSetData($Label1, "")
        GUICtrlSetData($Label2, $Score)
        $GameMode = "Play"
        GUICtrlSetData($Button1, "DEAL")
        GUISetBkColor($COLOR_TEAL)

    EndIf
EndFunc   ;==>CardColor
;-------------------------------------------------------------------------------
Func ChekForWin() ;Check for Win
    Local $tmpHand = "", $CardStr = ""

    _ArraySort($HandCard, 0, 1, 0, 3) ; array sort by card order
    ;_ArrayDisplay($HandCard, "ChekForWin")

    ;------------------------------------------------------------------------------------
    ; Flush
    For $i = 1 To $HandCard[0][0]
        $CardStr = $CardStr & $HandCard[$i][1]
    Next

    If StringRegExp($CardStr, 'CCCCC|DDDDD|HHHHH|SSSSS', 0) Then $tmpHand = "Flush"
    ;------------------------------------------------------------------------------------
    $CardStr = ""
    For $i = 1 To $HandCard[0][0]
        $CardStr = $CardStr & $HandCard[$i][2]
    Next

    ConsoleWrite("ChekForWin ---------" & @CRLF)
    ConsoleWrite("$CardStr = " & $CardStr & @CRLF)
    ConsoleWrite("$tmpHand1 = " & $tmpHand & @CRLF)
    ;------------------------------------------------------------------------------------
    ; '910JQK' (Straight Flush)| '10JQKA' (Royal Flush)
    ; 'A2345' (Straight)| '24556' (pair)| '25556' (Three of kind)| '25555' (Four of kind)| '556QQ' (Two pair)| '66777' (Full house)
    Local $o_Card = '2345678910JQKA'
    Local $o_Pattern = StringRegExp($CardStr, "([2-9AJQK]|10)\1+", 3)

    Local $CountPoint = 0
    If $tmpHand = "Flush" Then
        $CountPoint = StringInStr($o_Card, $CardStr)
        If $CountPoint <> 0 Then $tmpHand = (($CountPoint = 9) ? 'Royal Flush' : 'Straight Flush')
    Else
        If UBound($o_Pattern) = 0 Then
            $o_Card = 'A' & $o_Card
            If StringInStr($o_Card, $CardStr) Then $tmpHand = 'Straight'
        Else
            For $i = 0 To UBound($o_Pattern) - 1
                StringReplace($CardStr, $o_Pattern[$i], '')
                $CountPoint += @extended
            Next
            If $CountPoint = 2 Then $tmpHand = 'pair'
            If $CountPoint = 3 Then $tmpHand = 'Three of kind'
            If ($CountPoint = 4) Then $tmpHand = ((UBound($o_Pattern) = 1) ? 'Four of kind' : 'Two pair')
            If $CountPoint = 5 Then $tmpHand = 'Full house'
        EndIf
    EndIf
    ConsoleWrite("$tmpHand2 = " & $tmpHand & @CRLF)
    ;------------------------------------------------------------------------------------

    If $tmpHand = "" Then
        ;nothing to win
    Else
        TakeWin($tmpHand)
    EndIf
EndFunc   ;==>ChekForWin

 

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

×
×
  • Create New...