Jump to content

[HELP] Straight in texas holdem


Recommended Posts

So the goal is to (in the end) have the program be able to recognize if a straight is possible after the flop in the game Texas Hold'em. So my program kinda works like this:

Get Cards from user input and shove it into and array:

Global $CardNumbers[13] = [2, 3, 4, 5, 6, 7, 8, 9, 10, "J", "Q", "K", "A"]
Global $CardSuits[4] = ["Hearts", "Diamonds", "Spades", "Clubs"]
Global $myCards[4]

Func _Get_Hand();gets input from GUI
    $myCards[0] = GUICtrlRead($Urcard1)
    $myCards[1] = GUICtrlRead($Ursuit1)
    $myCards[2] = GUICtrlRead($Urcard2)
    $myCards[3] = GUICtrlRead($Ursuit2)

    If $myCards[0] = $CardNumbers[9] Then $myCards[0] = 11
    If $myCards[0] = $CardNumbers[10] Then $myCards[0] = 12
    If $myCards[0] = $CardNumbers[11] Then $myCards[0] = 13
    If $myCards[0] = $CardNumbers[12] Then $myCards[0] = 1

    If $myCards[2] = $CardNumbers[9] Then $myCards[2] = 11
    If $myCards[2] = $CardNumbers[10] Then $myCards[2] = 12
    If $myCards[2] = $CardNumbers[11] Then $myCards[2] = 13
    If $myCards[2] = $CardNumbers[12] Then $myCards[2] = 1

EndFunc   ;==>_Get_Hand

Same idea for the flop.

The program is to calculate pot odds and outs. Im right now working on the outs for a straight which would be :

Example       [HAND]            [FLOP]       [specific outs]  [outs]
Inside Straight [6♣ 7♦]     [5♠ 9♥ A♦]    8♣, 8♦, 8♥, 8♠     4
Open Straight   [9♥ T♣]     [3♣ 8♦ J♥]    Any 7, Any Q       8

Once it knows that a straight is possible then i also need to figure out how many outs is needed (if there are only 3 of the 5 cards i would need 8 outs and if there is only 1 card missing i would need 4) which could be dont with a simple switch statement.

Now because there are so many kinds of possible straights i cant think of an algorithm that would solve it.

Now i figured out how i could tell if i had a chance at a straight without the flop by simply doing

Abs($mycard[0] - $mycard[2])

and if it = within 4 then it would run this code that i am currently stuck on.

Thank you very much in advance. If you need more info just ask and i will respond pretty quickly. :x

(btw my program is a fair size. The above is only a little tiny bit to show what kind of vars im working with)

Edited by gononono64
Link to comment
Share on other sites

Have you read the announcement regarding game Bots and Automation?

http://www.autoitscript.com/forum/forum-2/announcement-12-game-bots-and-automation/

It looks to me like you are building a bot. If that is the case, you should expect no help and the topic may be closed.

SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script

wannabe "Unbeatable" Tic-Tac-Toe

Paper-Scissor-Rock ... try to beat it anyway :)

Link to comment
Share on other sites

My intention was to just point that to you, to avoid any further troubles.

I can understand what are you saying and I wish you good luck with that. For me it looks like the algorythm would be quite a complex one. Unfortunately it is more that I can handle at the moment.

SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script

wannabe "Unbeatable" Tic-Tac-Toe

Paper-Scissor-Rock ... try to beat it anyway :)

Link to comment
Share on other sites

You might want to look into this and change some of the code -

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

This is suppose to help, I hope.

; http://www.autoitscript.com/forum/topic/...s-holdem/page__view__findpost_

Global $aCard[15] = ["", 'A', 2, 3, 4, 5, 6, 7, 8, 9, 10, 'J', 'Q', 'K', 'A']
Local $sHandType, $sOut
Local $aFlop[3] = ["11S", "10H", "9D"]
Local $iTurn = 3 ;"" ;

; ================ Example 1 (Inside straight)==============
Local $aHand[2] = ["1C", "13C"]
Local $a = _CheckStraight($aHand, $aFlop, $iTurn, $sHandType, $sOut)

; ---------- Array Display ---------
Local $sStr = "Index" & @TAB & "Contents" & @CRLF
For $i = 0 To UBound($a) - 1
    $sStr &= $i & @TAB & $aCard[$a[$i]] & @CRLF
Next
MsgBox(0, "Inside straight", $sStr & "HandType = " & $sHandType & ";  Specific Out = " & $sOut)
; -----> End of Array Display -------

; ================ Example 2  (Outside straight)==============
Local $aHand[2] = [5, 8]
Local $a = _CheckStraight($aHand, $aFlop, $iTurn, $sHandType, $sOut)

; ---------- Array Display ---------
Local $sStr = "Index" & @TAB & "Contents" & @CRLF
For $i = 0 To UBound($a) - 1
    $sStr &= $i & @TAB & $aCard[$a[$i]] & @CRLF
Next
MsgBox(0, "Outside straight", $sStr & "HandType = " & $sHandType & ";  Specific Out = " & $sOut)
; -----> End of Array Display -------

; ================ Example 3  (A straight)===================
Local $aHand[2] = [7, 8]
Local $a = _CheckStraight($aHand, $aFlop, $iTurn, $sHandType, $sOut)

; ---------- Array Display ---------
Local $sStr = "Index" & @TAB & "Contents" & @CRLF
For $i = 0 To UBound($a) - 1
    $sStr &= $i & @TAB & $aCard[$a[$i]] & @CRLF
Next
MsgBox(0, "A straight", $sStr & "HandType = " & $sHandType & ";  Specific Out = " & $sOut)
; -----> End of Array Display -------


Func _CheckStraight($aHnd, $aFlop, $iTurn, ByRef $sHandType, ByRef $sOut)
    ; ------ Join Hand and Flop into an array --------
    Local $a[5 + ($iTurn <> "") * 1]
    For $i = 0 To 1
        $a[$i] = StringRegExpReplace($aHnd[$i], "(\d*)", "\1") ; Returns digits only
        If ($a[$i] = 1) Then ; High low Ace
            ReDim $a[UBound($a) + 1]
            $a[UBound($a) - 1] = 14
        EndIf
        If ($a[$i] = 14) Then ; High low Ace
            ReDim $a[UBound($a) + 1]
            $a[UBound($a) - 1] = 1
        EndIf
    Next

    For $i = 2 To 4 ;- ($iTurn <> "") * 1
        ConsoleWrite($i & @CRLF)
        $a[$i] = StringRegExpReplace($aFlop[$i - 2], "(\d*)", "\1") ; Returns digits only
        If ($a[$i] = 1) Then ; High low Ace
            ReDim $a[UBound($a) + 1]
            $a[UBound($a) - 1] = 14
        EndIf
        If ($a[$i] = 14) Then ; High low Ace
            ReDim $a[UBound($a) + 1]
            $a[UBound($a) - 1] = 1
        EndIf
    Next
    If ($iTurn <> "") Then $a[5] = $iTurn

    ; ------- ArrayUnique_SortNumeric -------------------
    Local $Temp, $LoopFlag = 1, $i = 0, $iDuplicNum = 100, $iCount = 0
    While $LoopFlag
        $LoopFlag = 0
        For $i = 1 To UBound($a) - 1
            If Number($a[$i - 1]) = Number($a[$i]) Then ; Record duplicate entries
                $a[$i] = $iDuplicNum
                $iDuplicNum -= 1
                $LoopFlag = 1
                $iCount += 1
            EndIf
            If Number($a[$i - 1]) >= Number($a[$i]) Then ; Sort ascending order
                $Temp = $a[$i - 1]
                $a[$i - 1] = $a[$i]
                $a[$i] = $Temp
                $LoopFlag = 1
            EndIf
        Next
    WEnd
    If $iCount <> 0 Then ReDim $a[UBound($a) - $iCount] ; Delete duplicate entries
    ; -------> End of ArrayUnigueSortNumeric ---------------

    For $i = 3 To UBound($a) - 1

        ; ----- Check Outside straight -----
        If ($a[$i] - ($a[$i - 3])) = 3 Then
            $sHandType = "Outside straight"
            $sOut = __Iif(($a[$i - 3] - 1) > 0, "Any " & $aCard[$a[$i - 3] - 1], "") & __Iif(($a[$i] + 1) < 15, ", " & "Any " & $aCard[$a[$i] + 1], "")
        EndIf

        ; ----- Check Inside straight -----
        If ($a[$i] - ($a[$i - 3])) = 4 Then
            $sHandType = "Inside straight"
            For $j = $i - 2 To UBound($a) - 1
                If $a[$j - 1] + 1 <> $a[$j] Then
                    $sOut = "Any " & $aCard[$a[$j - 1] + 1]
                    ;ExitLoop
                EndIf
            Next
        EndIf
    Next

    ; ----- Check Actual straight -----
    For $i = 4 To UBound($a) - 1
        If ($a[$i] - $a[$i - 4]) = 4 Then
            $sHandType = "Is a straight"
            $sOut = "NA" ; Not Applicable
        EndIf
    Next
    Return $a
EndFunc   ;==>_CheckStraight


;Copy of _Iif from #Include <Misc.au3>
Func __Iif($fTest, $vTrueVal, $vFalseVal)
    If $fTest Then
        Return $vTrueVal
    Else
        Return $vFalseVal
    EndIf
EndFunc   ;==>__Iif

Edit: (Dec 16 2010 10:59 AM) Corrected $aFlop, $aHand, and $a array sizes.

Edit: Added - Allowed for high/low Ace in straight.

Edited by Malkey
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...