Jump to content

If u are pro, come help me!


Recommended Posts

How to calculate best hand in texas holdem. I got numbers, how i convert these to best possible 5 card hand ?

mine .au3 file save cards infos in .ini like:

ace : 14 Red cards are H or D like : 14H > Ace heart

king : 13 Blacks are s or t Like : 14s > ace spade

queen : 12

jack : 11

ten : 10

9 : 9

8: 8

7: 7

6: 6

5:5

4:4

3:3

2:2

I have tried many ways...

Like this what(dont work, dont know why) i got in search:

#include <Array.au3>

Sleep(2000)

Global $pf_card[3]

Global $pf_gen[3]

Global $f_card[4]

Global $c[6][2]

Global $d[6][2]

Global $n

Global $p

Global $handrecords[11][2]

Global $r = 0

_getpreflop()

_getflop()

_combinecards()

_convertcards()

;_ArrayDisplay($c, "")

;_findyourhand()

;_ArrayDisplay($c, "")

_findbesthand()

Func _getpreflop()

$pf_card[1] = "9h"

$pf_card[2] = "5h"

EndFunc

Func _getflop()

$f_card[1] = "Th"

$f_card[2] = "Jh"

$f_card[3] = "Ah"

EndFunc

Func _combinecards()

$c[1][0] = StringLeft($pf_card[1], 1)

$c[2][0] = StringLeft($pf_card[2], 1)

$c[3][0] = StringLeft($f_card[1], 1)

$c[4][0] = StringLeft($f_card[2], 1)

$c[5][0] = StringLeft($f_card[3], 1)

$c[1][1] = StringRight($pf_card[1], 1)

$c[2][1] = StringRight($pf_card[2], 1)

$c[3][1] = StringRight($f_card[1], 1)

$c[4][1] = StringRight($f_card[2], 1)

$c[5][1] = StringRight($f_card[3], 1)

EndFunc

Func _convertcards()

Dim $i

For $i = 1 to 5

If $c[$i][0] = "T" Then

$c[$i][0] = Number("10")

ElseIf $c[$i][0] = "J" Then

$c[$i][0] = Number("11")

ElseIf $c[$i][0] = "Q" Then

$c[$i][0] = Number("12")

ElseIf $c[$i][0] = "K" Then

$c[$i][0] = Number("13")

ElseIf $c[$i][0] = "A" Then

$c[$i][0] = Number("14")

ElseIf $c[$i][0] <= "9" Then

$c[$i][0] = Number($c[$i][0])

EndIf

Next

EndFunc

Func _convertgen()

$pf_card[1] = $p

$pf_card[2] = $n

$c[1][0] = StringLeft($pf_card[1], 1)

$c[2][0] = StringLeft($pf_card[2], 1)

$c[3][0] = StringLeft($f_card[1], 1)

$c[4][0] = StringLeft($f_card[2], 1)

$c[5][0] = StringLeft($f_card[3], 1)

$c[1][1] = StringRight($pf_card[1], 1)

$c[2][1] = StringRight($pf_card[2], 1)

$c[3][1] = StringRight($f_card[1], 1)

$c[4][1] = StringRight($f_card[2], 1)

$c[5][1] = StringRight($f_card[3], 1)

Dim $i

For $i = 1 to 5

If $c[$i][0] = "T" Then

$c[$i][0] = Number("10")

ElseIf $c[$i][0] = "J" Then

$c[$i][0] = Number("11")

ElseIf $c[$i][0] = "Q" Then

$c[$i][0] = Number("12")

ElseIf $c[$i][0] = "K" Then

$c[$i][0] = Number("13")

ElseIf $c[$i][0] = "A" Then

$c[$i][0] = Number("14")

ElseIf $c[$i][0] <= "9" Then

$c[$i][0] = Number($c[$i][0])

EndIf

Next

EndFunc

Func _findbesthand()

_cardgen()

_recordsetup()

Dim $i

For $i = 1 to 3

_ArrayDelete($cgen, _ArraySearch($cgen, $f_card[$i], 1, 0, 0))

Next

;$d = $c

$k = 1

For $k = 1 to 49 ; -3 flop cards

;_ArrayDisplay($cgen, "1")

$o = _ArraySearch($cgen, $cgen[$k], 1, 0, 0)

$p = $cgen[$o]

$cgen[$o] = ""

For $l = 1 to 49 ; -1 card $i

$m = _ArraySearch($cgen, $cgen[$l], 1, 0, 0)

$n = $cgen[$m]

If $n = "" Then

; nothin

Else

$cgen[$m] = ""

_convertgen()

;_ArrayDisplay($c, "loop")

$d = $c

_ArraySort($c, 1, 1, "", 2)

_findyourhand()

;addhandrecord($handtoadd)

;MsgBox(0, "", $handrec)

$cgen[$m] = $n

EndIf

Next

$cgen[$o] = $p

$cgen[$k] = ""

;Dim $q

;For $q = 1 to 4

; $q += $r

; If $q > 49 Then

; $q = 49

; EndIf

; $cgen[$q] = ""

;Next

;$r += 4

Next

_ArrayDisplay($handrecords, "Possible Hands when Flop = " & $d[3][0] & $d[3][1] & " " & $d[4][0] & $d[4][1] & " " & $d[5][0] & $d[5][1])

EndFunc

Func _recordsetup()

$handrecords[1][0] = "Royal flush"

$handrecords[2][0] = "Straight flush"

$handrecords[3][0] = "Four of a kind"

$handrecords[4][0] = "Full house"

$handrecords[5][0] = "Flush"

$handrecords[6][0] = "Straight"

$handrecords[7][0] = "Three of a kind"

$handrecords[8][0] = "Two pair"

$handrecords[9][0] = "One pair"

$handrecords[10][0] = "High card"

$handrecords[1][1] = Number("0")

$handrecords[2][1] = Number("0")

$handrecords[3][1] = Number("0")

$handrecords[4][1] = Number("0")

$handrecords[5][1] = Number("0")

$handrecords[6][1] = Number("0")

$handrecords[7][1] = Number("0")

$handrecords[8][1] = Number("0")

$handrecords[9][1] = Number("0")

$handrecords[10][1] = Number("0")

;_ArrayDisplay($handrecords, "1")

EndFunc

;$d[1][0] & $d[1][1] & " " & $d[2][0] & $d[2][1] & " " & $d[3][0] & $d[3][1] & " " & $d[4][0] & $d[4][1] & " " & $d[5][0] & $d[5][1]

Func _findyourhand()

If _checkflush() = 1 And _checkstraight() = 1 And $c[5][0] = "10" Then

$handrecords[1][1] += 1

;MsgBox(0, "", $d[1][0] & $d[1][1] & " " & $d[2][0] & $d[2][1] & " " & $d[3][0] & $d[3][1] & " " & $d[4][0] & $d[4][1] & " " & $d[5][0] & $d[5][1])

ElseIf _checkflush() = 1 And _checkstraight() = 1 Then

$handrecords[2][1] += 1

ElseIf _checkfourkind() = 1 Then

$handrecords[3][1] += 1

ElseIf _checkfullhouse() = 1 Then

$handrecords[4][1] += 1

ElseIf _checkflush() = 1 Then

$handrecords[5][1] += 1

ElseIf _checkstraight() = 1 Then

$handrecords[6][1] += 1

ElseIf _checkthreekind() = 1 Then

$handrecords[7][1] += 1

ElseIf _checktwopair() = 1 Then

$handrecords[8][1] += 1

ElseIf _onepair() = 1 Then

$handrecords[9][1] += 1

ElseIf _highcard() = 1 Then

$handrecords[10][1] += 1

EndIf

;_ArrayDisplay($handrecords, "2")

EndFunc

Func _checkflush()

If $c[1][1] = $c[2][1] And $c[2][1] = $c[3][1] And $c[3][1] = $c[4][1] And $c[4][1] = $c[5][1] Then

Return 1

EndIf

EndFunc

Func _checkstraight()

If $c[1][0] - $c[5][0] <= 4 Then

If $c[1][0] > $c[2][0] And $c[2][0] > $c[3][0] And $c[3][0] > $c[4][0] And $c[4][0] > $c[5][0] Then

Return 1

EndIf

EndIf

EndFunc

Func _checkfourkind()

Dim $count

Dim $i

For $i = 1 to 5

$count = 0

If $c[$i][0] = $c[1][0] Then

$count += 1

EndIf

If $c[$i][0] = $c[2][0] Then

$count += 1

EndIf

If $c[$i][0] = $c[3][0] Then

$count += 1

EndIf

If $c[$i][0] = $c[4][0] Then

$count += 1

EndIf

If $c[$i][0] = $c[5][0] Then

$count += 1

EndIf

If $count >= 4 Then

Return 1

EndIf

Next

EndFunc

Func _checkfullhouse()

Dim $threekind = 0

Dim $twopair = 0

Dim $count

Dim $i

For $i = 1 to 5

$count = 0

If $c[$i][0] = $c[1][0] Then

$count += 1

EndIf

If $c[$i][0] = $c[2][0] Then

$count += 1

EndIf

If $c[$i][0] = $c[3][0] Then

$count += 1

EndIf

If $c[$i][0] = $c[4][0] Then

$count += 1

EndIf

If $c[$i][0] = $c[5][0] Then

$count += 1

EndIf

If $count = 3 Then

$threekind = 1

EndIf

If $count = 2 Then

$twopair = 1

EndIf

Next

If $threekind = 1 And $twopair = 1 Then

Return 1

EndIf

EndFunc

Func _checkthreekind()

Dim $count

Dim $i

For $i = 1 to 5

$count = 0

If $c[$i][0] = $c[1][0] Then

$count += 1

EndIf

If $c[$i][0] = $c[2][0] Then

$count += 1

EndIf

If $c[$i][0] = $c[3][0] Then

$count += 1

EndIf

If $c[$i][0] = $c[4][0] Then

$count += 1

EndIf

If $c[$i][0] = $c[5][0] Then

$count += 1

EndIf

If $count >= 3 Then

Return 1

EndIf

Next

EndFunc

Func _checktwopair()

Dim $twopair = 0

Dim $count

Dim $i

For $i = 1 to 5

$count = 0

If $c[$i][0] = $c[1][0] Then

$count += 1

EndIf

If $c[$i][0] = $c[2][0] Then

$count += 1

EndIf

If $c[$i][0] = $c[3][0] Then

$count += 1

EndIf

If $c[$i][0] = $c[4][0] Then

$count += 1

EndIf

If $c[$i][0] = $c[5][0] Then

$count += 1

EndIf

If $count = 2 Then

$twopair += 1

EndIf

Next

If $twopair = 4 Then

Return 1

EndIf

EndFunc

Func _onepair()

Dim $count

Dim $i

For $i = 1 to 5

$count = 0

If $c[$i][0] = $c[1][0] Then

$count += 1

EndIf

If $c[$i][0] = $c[2][0] Then

$count += 1

EndIf

If $c[$i][0] = $c[3][0] Then

$count += 1

EndIf

If $c[$i][0] = $c[4][0] Then

$count += 1

EndIf

If $c[$i][0] = $c[5][0] Then

$count += 1

EndIf

If $count >= 2 Then

Return 1

EndIf

Next

EndFunc

Func _highcard()

;_ArraySort($pf_card, 1, 1)

;MsgBox(0, "", "high card = " & $pf_card[1])

Return 1

EndFunc

;(1,49)

;(2,48) ;(52) store all cards in [1] array

Func _cardgen()

Global $cgen[53]

$cgen[1] = "2s"

$cgen[2] = "2c"

$cgen[3] = "2h"

$cgen[4] = "2d"

$cgen[5] = "3s"

$cgen[6] = "3c"

$cgen[7] = "3h"

$cgen[8] = "3d"

$cgen[9] = "4s"

$cgen[10] = "4c"

$cgen[11] = "4h"

$cgen[12] = "4d"

$cgen[13] = "5s"

$cgen[14] = "5c"

$cgen[15] = "5h"

$cgen[16] = "5d"

$cgen[17] = "6s"

$cgen[18] = "6c"

$cgen[19] = "6h"

$cgen[20] = "6d"

$cgen[21] = "7s"

$cgen[22] = "7c"

$cgen[23] = "7h"

$cgen[24] = "7d"

$cgen[25] = "8s"

$cgen[26] = "8c"

$cgen[27] = "8h"

$cgen[28] = "8d"

$cgen[29] = "9s"

$cgen[30] = "9c"

$cgen[31] = "9h"

$cgen[32] = "9d"

$cgen[33] = "Ts"

$cgen[34] = "Tc"

$cgen[35] = "Th"

$cgen[36] = "Td"

$cgen[37] = "Js"

$cgen[38] = "Jc"

$cgen[39] = "Jh"

$cgen[40] = "Jd"

$cgen[41] = "Qs"

$cgen[42] = "Qc"

$cgen[43] = "Qh"

$cgen[44] = "Qd"

$cgen[45] = "Ks"

$cgen[46] = "Kc"

$cgen[47] = "Kh"

$cgen[48] = "Kd"

$cgen[49] = "As"

$cgen[50] = "Ac"

$cgen[51] = "Ah"

$cgen[52] = "Ad"

EndFunc

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...