Sign in to follow this  
Followers 0
Ivanw

Read Poker Cards

9 posts in this topic

Hi, Could somebody give me advice how to read the poker card in online game?

I am new in programmer, and my english is not very good. Sorry.

BTW this is my case.

I have already a script from my friend, it use pixelcheksum. but it seems that not every same type card has the same pixelcheksum. here is the code :

;=================================================================
    ; Read the Cards
    ;=================================================================
    #include-once
    #Include "vendor/ScreenCapture/ScreenCaptureFixed.au3"
    #Include "Table.au3"

    Global $logScreenCard = Int(IniRead(@ScriptDir & "\settings.ini","Log","log_screen_card", 0))
    Global $oCardDictionary = ObjCreate("Scripting.Dictionary")
    Global $oSuitDictionary = ObjCreate("Scripting.Dictionary")
    Global $sDataPath = '..\data'
    Global $sLogPath = '..\log'
    Global $aTop[2]


    Func _Cards($iSeat)
       Local $aCards[7], $aSuits[7]

       If $aTop[0] == False Then
          Return False
       EndIf
       If $iSeat < 1 Then
          Return False
       EndIf

       ; table card locations
       Local $aTableCard1_XY[2]
       Local $aTableCard2_XY[2]
       Local $aTableCard3_XY[2]
       Local $aTableCard4_XY[2]
       Local $aTableCard5_XY[2]

       ; seat card locations
       Local $aSeatCard1_XY[9][2]
       Local $aSeatCard2_XY[9][2]

       ; seat 1
       $aSeatCard1_XY[0][0] = 527
       $aSeatCard1_XY[0][1] = 33
       $aSeatCard2_XY[0][0] = 552
       $aSeatCard2_XY[0][1] = 33

       ; seat 2
       $aSeatCard1_XY[1][0] = 637
       $aSeatCard1_XY[1][1] = 83
       $aSeatCard2_XY[1][0] = 662
       $aSeatCard2_XY[1][1] = 83

       ; seat 3
       $aSeatCard1_XY[2][0] = 647
       $aSeatCard1_XY[2][1] = 205
       $aSeatCard2_XY[2][0] = 672
       $aSeatCard2_XY[2][1] = 205

       ; seat 4
       $aSeatCard1_XY[3][0] = 527
       $aSeatCard1_XY[3][1] = 278
       $aSeatCard2_XY[3][0] = 552
       $aSeatCard2_XY[3][1] = 278

       ; seat 5
       $aSeatCard1_XY[4][0] = 402
       $aSeatCard1_XY[4][1] = 283
       $aSeatCard2_XY[4][0] = 427
       $aSeatCard2_XY[4][1] = 283

       ; seat 6
       $aSeatCard1_XY[5][0] = 182
       $aSeatCard1_XY[5][1] = 277
       $aSeatCard2_XY[5][0] = 207
       $aSeatCard2_XY[5][1] = 277

       ; seat 7
       $aSeatCard1_XY[6][0] = 62
       $aSeatCard1_XY[6][1] = 205
       $aSeatCard2_XY[6][0] = 87
       $aSeatCard2_XY[6][1] = 205

       ; seat 8
       $aSeatCard1_XY[7][0] = 61
       $aSeatCard1_XY[7][1] = 82
       $aSeatCard2_XY[7][0] = 86
       $aSeatCard2_XY[7][1] = 82

       ; seat 9
       $aSeatCard1_XY[8][0] = 182
       $aSeatCard1_XY[8][1] = 33
       $aSeatCard2_XY[8][0] = 207
       $aSeatCard2_XY[8][1] = 33

       ; table card 1
       $aTableCard1_XY[0] = 287
       $aTableCard1_XY[1] = 134

       ; table card 2
       $aTableCard2_XY[0] = 327
       $aTableCard2_XY[1] = 134

       ; table card 3
       $aTableCard3_XY[0] = 367
       $aTableCard3_XY[1] = 134

       ; table card 4
       $aTableCard4_XY[0] = 407
       $aTableCard4_XY[1] = 134

       ; table card 5
       $aTableCard5_XY[0] = 447
       $aTableCard5_XY[1] = 134

       ; get the numbers
       $aCards[0] = _CardNumber($aTop[0]+$aSeatCard1_XY[$iSeat-1][0],$aTop[1]+$aSeatCard1_XY[$iSeat-1][1])
       $aCards[1] = _CardNumber($aTop[0]+$aSeatCard2_XY[$iSeat-1][0],$aTop[1]+$aSeatCard2_XY[$iSeat-1][1])
       $aCards[2] = _CardNumber($aTop[0]+$aTableCard1_XY[0],$aTop[1]+$aTableCard1_XY[1])
       $aCards[3] = _CardNumber($aTop[0]+$aTableCard2_XY[0],$aTop[1]+$aTableCard2_XY[1])
       $aCards[4] = _CardNumber($aTop[0]+$aTableCard3_XY[0],$aTop[1]+$aTableCard3_XY[1])
       $aCards[5] = _CardNumber($aTop[0]+$aTableCard4_XY[0],$aTop[1]+$aTableCard4_XY[1])
       $aCards[6] = _CardNumber($aTop[0]+$aTableCard5_XY[0],$aTop[1]+$aTableCard5_XY[1])


       ; get the suits
       $aSuits[0] = _CardSuit($aTop[0]+$aSeatCard1_XY[$iSeat-1][0],$aTop[1]+$aSeatCard1_XY[$iSeat-1][1])
       $aSuits[1] = _CardSuit($aTop[0]+$aSeatCard2_XY[$iSeat-1][0],$aTop[1]+$aSeatCard2_XY[$iSeat-1][1])
       $aSuits[2] = _CardSuit($aTop[0]+$aTableCard1_XY[0],$aTop[1]+$aTableCard1_XY[1])
       $aSuits[3] = _CardSuit($aTop[0]+$aTableCard2_XY[0],$aTop[1]+$aTableCard2_XY[1])
       $aSuits[4] = _CardSuit($aTop[0]+$aTableCard3_XY[0],$aTop[1]+$aTableCard3_XY[1])
       $aSuits[5] = _CardSuit($aTop[0]+$aTableCard4_XY[0],$aTop[1]+$aTableCard4_XY[1])
       $aSuits[6] = _CardSuit($aTop[0]+$aTableCard5_XY[0],$aTop[1]+$aTableCard5_XY[1])
       
       ;$aCards = _CardStringCheck(_CardCount())
       

       ; convert to card string
       $sCards = _CardString($aCards,$aSuits)
       ;_ToolTip($sCards)
       Return $sCards
    EndFunc


    Func _CardChecksum($x,$y)
       Local $iChecksum
       ;$aCard = _CardsPosition($iCard)
       $iChecksum = PixelChecksum($x,$y,$x+6,$y+6)
       Return $iChecksum
    EndFunc

    Func _CardSuitChecksum($x,$y)
       Local $iChecksum
       ;$aCard = _CardsPosition($iCard)
       $iChecksum = PixelChecksum($x,$y+20,$x+6,$y+20+6)
       Return $iChecksum
    EndFunc


    Func _CardChecksumSave($x,$y)
       Local $iChecksum, $sFilename
       $iChecksum = _CardChecksum($x,$y)
       $sFilename = $sDataPath&'\card\'&$iChecksum
       If FileExists($sFilename&'.txt') Then
          Return
       EndIf
       Filewrite($sFilename&'.txt',$iChecksum)
    EndFunc

    Func _CardSuitChecksumSave($x,$y)
       Local $iChecksum, $sFilename
       $iChecksum = _CardSuitChecksum($x,$y)
       $sFilename = $sDataPath&'\suit\'&$iChecksum
       If FileExists($sFilename&'.txt') Then
          Return
       EndIf
       Filewrite($sFilename&'.txt',$iChecksum)
    EndFunc

    Func _CardNumber($x,$y)
       Local $iChecksum, $sFilename
       $iChecksum = _CardChecksum($x,$y)
       
       ;Load from dictionary
       If IsObj($oCardDictionary) And $oCardDictionary.Exists($iChecksum) Then
          Return $oCardDictionary.Item($iChecksum)
       EndIf
       
       ;Load from TXT
       If FileExists($sDataPath&'\card\empty\'&$iChecksum&'.txt') Then
          If IsObj($oCardDictionary) Then
             $oCardDictionary.Add($iChecksum,False)
          EndIf
          Return False
       EndIf
       
    Local $aFolders[13] = ["2",   "3", "4", "5", "6", "7", "8", "9", "T", "J", "Q", "K", "A"]
       For $i = 0 to 12
          If FileExists($sDataPath&'\card\'&$aFolders[$i]&'\'&$iChecksum&'.txt') Then
          $iCards = $aFolders[$i]
          If IsObj($oCardDictionary) Then
                $oCardDictionary($iChecksum,$iCards)
             EndIf
             Return $iCards
          EndIf
       Next   
       
       ;Load from TIF
       If FileExists($sDataPath&'\card\empty\'&$iChecksum&'.tif') Then
          FileWrite($sDataPath&'\card\empty\'&$iChecksum&'.txt','empty') ;Save to txt
             If IsObj($oCardDictionary) Then
                $oCardDictionary.Add($iChecksum,False)
             EndIf
             Return False   
       Endif
       
    Local $aFolders[13] = ["2",   "3", "4", "5", "6", "7", "8", "9", "T", "J", "Q", "K", "A"]
       For $i = 0 to 12
          If FileExists($sDataPath&'\card\'&$aFolders[$i]&'\'&$iChecksum&'.tif') Then
          $iCards = $aFolders[$i]
          FileWrite($sDataPath&'\card\'&$aFolders[$i]&'\'&$iChecksum&'.txt',$iCards)
          If IsObj($oCardDictionary) Then
                $oCardDictionary($iChecksum,$iCards)
             EndIf
             Return $iCards
          EndIf
       Next   
       
       ;not found
       ;$aCard = _CardsPosition($iCard)
       If $logScreenCard <> 0 Then
          _ScreenCapture_Capture($sDataPath&'\card\'&$iChecksum&'.tif',$x-2,$y-2,$x+10,$y+14,False)
       EndIf
       
    Return False

    EndFunc



    ; get a suit based on a x/y location
    Func _CardSuit($x,$y)
       Local $iChecksum, $sFilename
       $iChecksum = _CardSuitChecksum($x,$y)
       
       ;Load from dictionary
       If IsObj($oSuitDictionary) And $oSuitDictionary.Exists($iChecksum) Then
          Return $oSuitDictionary.Item($iChecksum)
       EndIf
       
       ;Load from TXT

       If FileExists($sDataPath&'\suit\empty\'&$iChecksum&'.txt') Then
          If IsObj($oSuitDictionary) Then
             $oSuitDictionary.Add($iChecksum,False)
          EndIf
          Return False
       EndIf

    Local $aFolders[4] = ["c","d","h","s"]
       For $i = 0 to 3
       If FileExists($sDataPath&'\suit\'&$aFolders[$i]&'\'&$iChecksum&'.txt') Then
          $sSuit = $aFolders[$i]
          If IsObj($oSuitDictionary) Then
                $oSuitDictionary($iChecksum,$sSuit)
             EndIf
             Return $sSuit
          EndIf
       Next   
       
       ;Load from TIF
       If FileExists($sDataPath&'\suit\empty\'&$iChecksum&'.tif') Then
          FileWrite($sDataPath&'\suit\empty\'&$iChecksum&'.txt','empty') ;Save to txt
             If IsObj($oSuitDictionary) Then
                $oSuitDictionary.Add($iChecksum,False)
             EndIf
             Return False   
       Endif
       
    Local $aFolders[4] = ["c","d","h","s"]
       For $i = 0 to 3
          If FileExists($sDataPath&'\suit\'&$aFolders[$i]&'\'&$iChecksum&'.tif') Then
          $sSuit = $aFolders[$i]
          FileWrite($sDataPath&'\suit\'&$aFolders[$i]&'\'&$iChecksum&'.txt',$sSuit)
          If IsObj($oSuitDictionary) Then
                $oSuitDictionary($iChecksum,$sSuit)
             EndIf
             Return $sSuit
          EndIf
       Next   
       
       ;not found
       ;$aCard = _CardsPosition($iCard)
       If $logScreenCard <> 0 Then
          _ScreenCapture_Capture($sDataPath&'\suit\'&$iChecksum&'.tif',$x-10,$y+20-10,$x+6+10,$y+20+6+10,False)
       EndIf
       
    Return False
       ;Local $iChecksum = PixelChecksum($x,$y+20,$x+6,$y+20+6)
       
       ;If IsObj($oSuitDictionary) And $oSuitDictionary.Exists($iChecksum) Then
       ;   Return $oSuitDictionary.Item($iChecksum)
       ;EndIf
       
       ;Local $sSuit = IniRead($sDataPath & "\suit.ini","SuitChecksum",$iChecksum,'-')
       ;If $sSuit <> '-' Then
       ;   If IsObj($oSuitDictionary) Then
       ;      $oSuitDictionary.Add($iChecksum,$sSuit)
       ;   EndIf
       ;   Return $sSuit
       ;EndIf
       
       ; unknown suit
       ;If $logScreenCard <> 0 Then
       ;   $sImageFilename = $sLogPath&'\suit\'&$iChecksum
       ;   _ScreenCapture_Capture($sImageFilename&'.tif',$x-10,$y+20-10,$x+6+10,$y+20+6+10,False)
       ;EndIf

       ;If IsObj($oSuitDictionary) Then
       ;   $oSuitDictionary.Add($iChecksum,False)
       ;EndIf
       ;Return False
    EndFunc

    Func _CardString($aCards,$aSuits)
       Local $sCards
       If ($aCards[0]<>False And $aCards[1]<>False) Or ($aCards[2]<>False) Then
          If $aCards[0]<>False And $aCards[1]<>False Then
             $sCards = $aCards[0] & $aSuits[0] & ' ' & $aCards[1] & $aSuits[1]
          Else
             $sCards = '-- --'
          EndIf
          If $aCards[2]<>False And $aCards[3]<>False And $aCards[4]<>False Then
             $sCards = $sCards & ' ' & $aCards[2] & $aSuits[2] & ' ' & $aCards[3] & $aSuits[3] & ' ' & $aCards[4] & $aSuits[4]
             If $aCards[5]<>False Then
                $sCards = $sCards & ' ' & $aCards[5] & $aSuits[5]
                If $aCards[6]<>False Then
                   $sCards = $sCards & ' ' & $aCards[6] & $aSuits[6]
                EndIf
             EndIf
          EndIf
       EndIf
       Return $sCards
    EndFunc

    Func _CardNumbersArray($sCards)
       Local $aCards[7]
       Local $aCardsTmp = StringSplit($sCards,' ',1)
       For $i = 0 To UBound($aCardsTmp)-1
          If $i>0 Then
             $aCards[$i-1] = StringLeft($aCardsTmp[$i],1)
          EndIf
       Next
       Return $aCards
    EndFunc

    Func _CardSuitsArray($sCards)
       Local $aSuits[7]
       Local $aSuitsTmp = StringSplit($sCards,' ',1)
       For $i = 0 To UBound($aSuitsTmp)-1
          If $i>0 Then
             $aSuits[$i-1] = StringRight($aSuitsTmp[$i],1)
          EndIf
       Next
       Return $aSuits
    EndFunc

So the script is make a tiff image everytime it can't read the cards. and we just put that image to the proper folder (2,3,4,5..,K,J,Q,A).

I have already at least 30 image in every folder. But the bot only read about 10% of the cards. While the bot running and can't recognize the cards it make tiff image and at that time I manually directly put that image in the proper folder, then the bot can read the card instanly. And in the next period it can't read the cards again.

Maybe the online poker game give different colour cards even for the same type card (Ex.: As for round one diff. with As for round two). But for the suit is not a problem.

Is the pixelcheksum can't handle in this situation?

Or must use imagesearch?

Thanks for anyone could help.

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

In order to get help you will need to post the site you are accessing.

The more I think about it, the more I think you are trying to cheat on a pay poker site. Why would a poker game go to so much trouble to keep you from reading the cards with a bot? If they are going to the trouble, then it is obvious that you are violating that site's TOS. Take your bot elsewhere. Crap like this gives AutoIt a bad name.

Edited by Volly

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

I successfuly used Prospeed DLL and it's CompareBytes() function where you can use tolerance parameter for comparing two very similar pictures.

base princip:

#include <prospeed30.au3>

LoadFileImage() 
InitFX()
CompareBytes()
Edited by Zedna

Share this post


Link to post
Share on other sites

#include <prospeed30.au3>

LoadFileImage() 
InitFX()
CompareBytes()

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

were do we put these lines

It's concept not final script!

Search forum for Prospeed. Download it and look at examples and helpfile.

EDIT:

CompareBytes() returns number of different bytes for two compared images.

You can use tolerance = 0 for exact diference or tolerance > 0 for similarity

Edited by Zedna

Share this post


Link to post
Share on other sites

Sorry i just came back from out of town , and to long to reply

@ Volly. Sorry if you think so. But I don't think so.

I didn't cheat to steal chip from that site. I just play a bot that will not always win , it can lost too.

@JohnOne. Yes it is a texas holdem poker bot written by cornernote.

@ zedna. Would you give me a simple example script for prospeed.

I already serach in the example script for prospeed, but i didn't found one.

Example: I have a.tiff picture to compare with the picture in area (x1,y1) to (x2,y2)

Could you give a a simple script for that situation?

Thanks in advance.

Share this post


Link to post
Share on other sites

Here is my own example. I made it for testing when I started learning/using Prospeed

#include <ScreenCapture.au3>
#include <prospeed30.au3>

; images can be also other types than BMP, for example PNG,GIF,JPG
$file1 = @ScriptDir & "\pic1.bmp"
$file2 = @ScriptDir & "\pic2.bmp"

; prepare some sample images for comparing
_ScreenCapture_Capture($file1, 0, 0, 100, 100, False)
_ScreenCapture_Capture($file2, 10, 10, 110, 110, False)
;~ _ScreenCapture_Capture($file2, 0, 0, 100, 100, False) ; the same as first (no difference)
        
$start = TimerInit()
$result = CompareImages($file1, $file2, 0) ; tolerance 0%
ConsoleWrite('load/compare/free time: ' & TimerDiff($start) & ' ms' & @CRLF)
ConsoleWrite('number of different bytes: ' & $result & @CRLF)
    
Func CompareImages($file1, $file2, $tolerance)
    $pic1 = LoadFileImage($file1) 
    $array1 = InitFX($pic1) ; Create Array data from loaded Image
    $arrayInfos1  = DllStructCreate("long;long;long;dword;dword;long;long;long;long;long;long;long", $array1)
    $Pointer1     = DllStructGetData($arrayInfos1, 11) ; Get pointer for array1 @ long 11

    $pic2 = LoadFileImage($file2) 
    $array2 = InitFX($pic2) ; Create Array data from loaded Image
    $arrayInfos2  = DllStructCreate("long;long;long;dword;dword;long;long;long;long;long;long;long", $array2)
    $Pointer2     = DllStructGetData($arrayInfos2, 11) ; Get pointer for array1 @ long 11

    $size = GetWidthImage($pic1) * GetHeightImage($pic1) * 3 ; size from first image
    $Compare = CompareBytes($Pointer1, $Pointer2, $size, $tolerance) ; tolerance %

    ; free array and bitmap data from memory
    FreeFX($array1) 
    FreeImage($pic1)

    FreeFX($array2)
    FreeImage($pic2)
    
    Return $Compare
EndFunc

Share this post


Link to post
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
Sign in to follow this  
Followers 0