Jump to content

pokerlogic.au3 Make Your Own Poker Game


Recommended Posts

Hello all.  I recently saw a post where someone was asking to get an old poker logic script working and it inspired me to dust mine off and get it operational.  I am happy to report I was able to do so (though please tell me if you spot any bugs).  I am sure others could code this more efficiently - some of you regex monsters could probably do it with 1 line :sweating:.  That said, the attached pokerlogic.au3 script will evaluate any five or seven card hand and populate a text variable explaining what you have (i.e. "full house", "pair", etc).  It will also create the points and kicker scores.  With the results you can score hands and create a full game. 

If anyone is curious about how it works it mainly relies on two initial tests - one will count how many numeric value cards there are in a given hand (i.e. without regard to suits).  There can only be 13 possibilities (2 - Ace).  It parses the strings representing the cards i.e. "AH" would be ace of hearts and it knows that should be in the last position of a zero-based array (which would be 12 because there are 13 cards in a suit).  That array can evaluate everything except flushes so there is another function that creates a count of the suits in a given hand.  Five of any one suit is obviously a flush.  If that is true then there are additional tests for a royal or straight flush.

Points: The points for each level are hard coded so that a stronger hand wins.  The numeric values are a bit random.  For example, I have a royal flush 1,000,000 points while a straight flush gets 250,000.  The kickers all work pretty consistently.  There can be between 0-4 kickers in a hand.  They should all be the value of the card in card count array multiplied by a decimal place of .01.  Therefore, a 12 becomes a .12.  The .01 is *= against itself so the values of additional kickers are all next to each other after the decimal place.  For example, A and K kickers would be .1211 because the ace is 12 and the king is 11.  On that note, kickers starting at 10 are the value of their card (i.e. 10) less 2 so 10 would be .08.  Why?  Because Ace=12, King=11, Queen=10, and Jack=9.  Therefore, by the time you get to a card with an actual numeric value it is always that value less 2.  What about 2 you say?  2 is equal to 0.  You will always lose if that is your only kicker against any other hand unless you tie (because they also have a 2).

I have also included pokerlogictester.au3.   That file has a full battery of tests with arrays containing pre-made hands of every type.  It can also generate and test any number of random hands.  The results of the tests will show up in the console and be written to a local text file with section headers so you can QA the output.  The first two tests examine one of each type of hand with five and seven cards respectively are not commented out - they will run if you run the script.  Just un-comment the others to run them as well.  

simple_poker_example.au3 shows how to manually test a single hand with just one line "_evaluatehand($hand)"

Please let me know your thoughts and enjoy.

JFish

pokerlogic.au3

pokerlogictester.au3

simple_poker_example.au3

Edited by Jfish
changed title of post

Build your own poker game with AutoIt: pokerlogic.au3 | Learn To Program Using FREE Tools with AutoIt

Link to post
Share on other sites

Oh, I for one, cannot wait to try this out...towards the end of my shift and I find this - can I work overtime?

Have you done any testing on how fast it will give results?

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 post
Share on other sites

@nitekram - thanks for your interest.  I have not clocked the speed but would be interested if someone wants to do that and post the results

EDIT: I created a test script (not sure if it is the best way to measure it - feel free to offer suggestions):

#include<pokerlogic.au3>
global $hand = ["5C","KC","QC","JC","10C"]; this is a test array for this function
for $a=0 to 9
Local $hTimer = TimerInit() ;
_evaluatehand($hand)
Local $fDiff = TimerDiff($hTimer) ; Find the difference in time from the previous call of TimerInit. The variable we stored the TimerInit handlem is passed as the "handle" to TimerDiff.
ConsoleWrite(@crlf&"Time Difference: "& $fDiff&@crlf)
next

It resulted in the following times:

Time Difference: 0.652425870779196

Time Difference: 0.508520631963045

Time Difference: 0.618043886938728

Time Difference: 0.93801815590566

Time Difference: 0.503529698824913

Time Difference: 0.500756958192617

Time Difference: 0.492993284422189

Time Difference: 0.493547832548648

Time Difference: 0.679321454912465

Time Difference: 0.495211476928025

 

Edited by Jfish
Created test and posted results

Build your own poker game with AutoIt: pokerlogic.au3 | Learn To Program Using FREE Tools with AutoIt

Link to post
Share on other sites
  • 1 year later...
On Wednesday, June 29, 2016 at 7:58 AM, ALB said:

HI all , im a little confused ... is there a gui that works with this pokerlogic?

Regards ALB

There is a Dice and Card Games Assistant however.  Maybe some enterprising young scripter could make them work together?

Edited by jaberwacky
Link to post
Share on other sites
  • 3 years later...

Hi !

First of all, thank you Jfish for these lines :)

I'm new to this software and I don't understand why filling the array with parameters isn't working. Am I doing anything wrong here ?

#include<pokerlogic2.au3>
#include<Array.au3>

GLOBAL $hand

Global $CARD1 = "QC"
Global $CARD2 = "AD"
Global $FLOP1 = "QD"
Global $FLOP2 = "QS"
Global $FLOP3 = "AH"
Global $TURN = "QH"
Global $RIVER = ""

global $hand = [$CARD1, $CARD2, $FLOP1, $FLOP2, $FLOP3, $TURN, $RIVER];
;~ global $hand = ["QC","AD","QD","AH","QH", ""]; this is a test array for this function

;~ _ArrayDisplay($hand)

_evaluatehand($hand)
MsgBox("","","This is the test hand: " & $hand[0]&" "&$hand[1]&" "&$hand[2]&" "&$hand[3]&" "&$hand[4] &@crlf & _
$text &@crlf & _
"points: "&$points&@crlf)

I am getting the following error message :

\pokerlogic2.au3" (187) : ==> Variable subscript badly formatted.:
if ($newhand[$startPos4] == 1) then
if ($newhand[^ ERROR

 

It is interesting to notice that we get a result with 

Global $CARD1 = "6C"
Global $CARD2 = "AD"
Global $FLOP1 = "QD"
Global $FLOP2 = "QS"
Global $FLOP3 = "AH"
Global $TURN = "QH"
Global $RIVER = ""

 

Also, these combination don't work for me :

global $hand = ["2H","3H","4H","KH","5H","10D","10S"]

Thanks for your time.

Xxob

 

pokerlogic.au3

Edited by Xxobster
Link to post
Share on other sites

"Hands must be 5 or 7 cards", you are passing an array of 7 elements but one is empty (try to fill also the seventh element with an allowed card and it will work)

sorry, I have not read correctly that you want to know why passing those other 6 elements + one empty element it works instead....

Edited by Chimp

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

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
  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By Chimp
      After watching this movie (https://www.youtube.com/watch?v=cPiDHXtM0VA) I wanted to try the test to see how much i could compete with that chimpanzee so i created this script.
      well, actually passing that test is a lot harder than it sounds. With the difficulty set to seven numbers and a display time of one second, I can only remember 2 or 3 numbers ... (what a disappointment)
      I can only do better if I reduce the slider to 5 numbers and increase the storage time to 2 seconds (the easyest level), a very poor performance. That chimpanzee is great.
      The script offers you a sequence of 10 random quizzes. At the end it gives you the percentage of your "level". The chimpanzee resolves on average 8 out of 10 (80%), so you can compare your performance to that of the chimpanzee.
      How to play:
      Run the script. At the beginning there are 2 sliders at the bottom of the screen where you can set the difficulty level by varying the memorization time and the amount of numbers to memorize as you like. After setting the difficulty, click the circle on the bottom left to get started. after the first move the sliders are no longer displayed until the next game, (the game lasts 10 attempts, there is a progress bar at the bottom of the screen to see where you are) between one test and the other of the ten, click on the circle to move on to the next test have fun.
      (here a related interesting video: https://www.youtube.com/watch?v=ktkjUjcZid0 )
      #include <GUIConstants.au3> #include <MsgBoxConstants.au3> #include <Array.au3> #include <WinAPIMisc.au3> ; HotKeySet("{ESC}", "_EndOfGame") Global $iNumbersToGuess = 7, $iExpositionTime = 1000, $iMatches = 10, $iMatchesWon Global $aNumbers[10] = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] Global $aButtons[10], $aControls[5] Global $iWinWidth = @DesktopWidth / 2, $iWinHeight = @DesktopHeight / 2, $iButtonXSide = Int($iWinWidth / UBound($aNumbers)), $iButtonYSide = Int($iWinHeight / UBound($aNumbers)), $sWinTitle = "Beat the Chimp" Global $aX[Int($iWinWidth / $iButtonXSide)], $aY[Int($iWinHeight / $iButtonYSide)], $iNdx = 0, $aPoints[3], $score, $GUIGetMsg, $iDockHeight = 50, $iProgrssHeight = 5 For $i = 0 To (Int($iWinWidth / $iButtonXSide) - 1) * $iButtonXSide Step $iButtonXSide $aX[$iNdx] = $i $iNdx += 1 Next $iNdx = 0 For $i = 0 To (Int($iWinHeight / $iButtonYSide) - 1) * $iButtonYSide Step $iButtonYSide $aY[$iNdx] = $i $iNdx += 1 Next Global Const $iDockLeftBorder = 200, $iForeColor = 0xFFFFFF, $iBackColor = 0x000000 Global $hGUI = GUICreate($sWinTitle, $iWinWidth, $iWinHeight + $iDockHeight + $iProgrssHeight, @DesktopWidth / 4, @DesktopHeight / 5) GUISetBkColor($iBackColor, $hGUI) ; the circle to continue playing $aControls[0] = GUICtrlCreateLabel(ChrW(0x25EF), 0, $iWinHeight + 1, 100, $iDockHeight, 0x01) ; GUICtrlSetTip(-1, "Click the circle," & @CRLF & "then click the squares" & @CRLF & "in numeric order.") GUICtrlSetFont(-1, 24, 900) GUICtrlSetColor(-1, $iForeColor) GUICtrlSetBkColor(-1, $iBackColor) ; slider for the amount of numbers to guess $aControls[2] = GUICtrlCreateSlider($iDockLeftBorder, $iWinHeight, $iWinWidth - $iDockLeftBorder, Int($iDockHeight / 2)) GUICtrlSetLimit(-1, 10, 5) ; 5 steps 5 (easy) to 10 (hard) GUICtrlSetData(-1, $iNumbersToGuess) ; label for the amount of quizzes $aControls[1] = GUICtrlCreateLabel("Numbers : " & GUICtrlRead($aControls[2]), 100, $iWinHeight + 1, 100) GUICtrlSetColor(-1, $iForeColor) ; slider for the exposition time $aControls[4] = GUICtrlCreateSlider($iDockLeftBorder, $iWinHeight + (Int($iDockHeight / 2)), $iWinWidth - $iDockLeftBorder, $iDockHeight / 2) GUICtrlSetLimit(-1, 8, 1) ; 8 steps (0f 250ms each) GUICtrlSetData(-1, $iExpositionTime / 250) ; label for the exposition time $aControls[3] = GUICtrlCreateLabel("ms to show : " & GUICtrlRead($aControls[4]) * 250, 100, $iWinHeight + 1 + (Int($iDockHeight / 2)), 100) GUICtrlSetColor(-1, $iForeColor) ; progress bar of the match Global $idProgressbar = GUICtrlCreateProgress(0, $iWinHeight + $iDockHeight, $iWinWidth, $iProgrssHeight) ; Create buttons For $i = 0 To 9 $aButtons[$i] = GUICtrlCreateLabel($i + 1, $iWinWidth + 5, $iWinHeight + $iDockHeight + $iProgrssHeight + 5, $iButtonXSide, $iButtonYSide, 0x01) GUICtrlSetFont($aButtons[$i], 24) GUICtrlSetColor($aButtons[$i], $iForeColor) GUICtrlSetBkColor($aButtons[$i], $iBackColor) Next GUISetState(@SW_SHOW) ; --- Main loop --- Do ; New game $iMatchesWon = 0 GUICtrlSetData($idProgressbar, 0) For $iRound = 1 To $iMatches ; the game lasts $iMatches rounds $iNdx = 0 ; reset pointer (index to the next correct answer) _HideControls(__get_IDs_by_indexes($aButtons, $aNumbers)) ; remove the numbers from the screen ; show the dock and wait (only in the first round are also shown the sliders) _ShowControls($iRound = 1 ? $aControls : $aControls[0]) ; display the dock's control(s) While 1 Switch GUIGetMsg() Case $aControls[0] ; The circle (play a new quiz) ExitLoop Case $aControls[2] ; slider to choose how many numbers to guess $iNumbersToGuess = GUICtrlRead($aControls[2]) GUICtrlSetData($aControls[1], "Numbers : " & $iNumbersToGuess) Case $aControls[4] ; slider to choose how long (milliseconds) to show the numbers $iExpositionTime = GUICtrlRead($aControls[4]) * 250 ; 8 steps of 250 milliseconds each GUICtrlSetData($aControls[3], "ms to show : " & $iExpositionTime) Case $GUI_EVENT_CLOSE _EndOfGame() EndSwitch WEnd _HideControls($aControls) ; hide the dock Sleep(750) ; wait a bit $aQuiz = _GenerateQuiz($iNumbersToGuess) ; generate random elements to guess _SpreadControls(__get_IDs_by_indexes($aButtons, $aQuiz)) ; scatter the numbers on the GUI _ShowControls(__get_IDs_by_indexes($aButtons, $aQuiz)) ; display the numbers Sleep($iExpositionTime) ; leave numbers visible for a short time _MaskControls(__get_IDs_by_indexes($aButtons, $aQuiz)) ; mask the numbers GUICtrlSetData($idProgressbar, Round($iRound / $iMatches * 100)) ; _ShowControls(__get_IDs_by_indexes($aButtons, $aQuiz)) ; <------------- keep numbers visible FOR DEBUG PURPOSE ONLY! While 1 ; wait for a move $GUIGetMsg = GUIGetMsg() If $GUIGetMsg = $GUI_EVENT_CLOSE Then _EndOfGame() ; scan all quiz buttons to check if one was pressed For $i = 0 To UBound($aQuiz) - 1 ; $aButtons) - 1 If $GUIGetMsg = $aButtons[$aQuiz[$i] - 1] Then If $i = $iNdx Then ; -------------------------- ; actions for a right move ; -------------------------- ; hide the guessed number _HideControls($aButtons[$aQuiz[$i] - 1]) ; --------------------------------- ; check if this round is complete ; --------------------------------- If $iNdx = (UBound($aQuiz) - 1) Then _WinAPI_PlaySound("SystemExclamation", Null, BitOR($SND_ALIAS, $SND_ASYNC)) $iMatchesWon += 1 ExitLoop 2 EndIf ; play a short ok sound ; _WinAPI_PlaySound("FaxBeep", Null, BitOR($SND_ALIAS, $SND_ASYNC)) ; "SystemAsterisk" $iNdx += 1 ; set index to next correct answer Else ; -------------------------- ; actions for a wrong move ; -------------------------- ; show all the right sequence _ShowControls(__get_IDs_by_indexes($aButtons, $aQuiz)) _WinAPI_PlaySound("DeviceFail", Null, BitOR($SND_ALIAS, $SND_ASYNC)) ; give a little time to the user to control it Sleep(1500) ; go to next step ExitLoop 2 EndIf EndIf Next WEnd ; loop till end of match $score = Round($iMatchesWon / $iMatches * 100, 2) ; percentage Select Case $score < 80 $sResult = "The chimp beat you!" Case $score > 80 $sResult = "You beat the chimp!" Case $score = 80 $sResult = "You tied the chimp." EndSelect Next ; next round ; game over? Until MsgBox($MB_YESNO + $MB_ICONINFORMATION + $MB_TASKMODAL + $MB_SETFOREGROUND, _ "Game over", _ "You got " & $score & "% correct." & @CRLF & _ "Ayumu averages 80% correct." & @CRLF & $sResult & @CRLF & @CRLF & _ "do you want to try again?") <> 6 Func _SpreadControls($aTemp) ; place the required numbers scattered on the GUI SRandom(@YEAR + @MON + @MDAY + @HOUR + @MIN + @SEC) _ArrayShuffle($aX) _ArrayShuffle($aY) ; first, place all buttons out of GUI For $i = 0 To UBound($aButtons) - 1 GUICtrlSetPos($aButtons[$i], $iWinWidth + 5, $iWinHeight + $iDockHeight + $iProgrssHeight + 5) GUICtrlSetState($aButtons[$i], $GUI_DISABLE) Next ; Then place only the numbers of this quiz in visible area For $i = 0 To UBound($aTemp) - 1 GUICtrlSetPos($aTemp[$i], $aX[$i], $aY[$i]) GUICtrlSetState($aTemp[$i], $GUI_ENABLE) Next EndFunc ;==>_SpreadControls Func _GenerateQuiz($iNumElements) ; generate an array of required random numbers SRandom(@YEAR + @MON + @MDAY + @HOUR + @MIN + @SEC) Local $aTemp[$iNumElements] _ArrayShuffle($aNumbers) For $i = 0 To $iNumElements - 1 $aTemp[$i] = $aNumbers[$i] Next _ArraySort($aTemp) Return $aTemp EndFunc ;==>_GenerateQuiz Func _ShowControls($aTemp) ; render controls visible (and enabled) $aTemp = _EnforceArray($aTemp) For $i = 0 To UBound($aTemp) - 1 GUICtrlSetState($aTemp[$i], $GUI_SHOW) GUICtrlSetColor($aTemp[$i], $iForeColor) GUICtrlSetBkColor($aTemp[$i], $iBackColor) Next EndFunc ;==>_ShowControls Func _MaskControls($aTemp) ; mask the controls $aTemp = _EnforceArray($aTemp) For $i = 0 To UBound($aTemp) - 1 GUICtrlSetColor($aTemp[$i], $iForeColor) GUICtrlSetBkColor($aTemp[$i], $iForeColor) Next EndFunc ;==>_MaskControls Func _HideControls($aTemp) ; hide the controls (implies disable) $aTemp = _EnforceArray($aTemp) For $i = 0 To UBound($aTemp) - 1 GUICtrlSetState($aTemp[$i], $GUI_HIDE) ; $GUI_DISABLE) ; GUICtrlSetColor($aButtons[$aTemp[$i] - 1], $iBackColor) ; GUICtrlSetBkColor($aButtons[$aTemp[$i] - 1], $iBackColor) Next EndFunc ;==>_HideControls Func _EnforceArray($vParam) ; if only one value is passed, turn it into an array of only 1 element If Not IsArray($vParam) Then Local $aTemp[1] = [$vParam] Return $aTemp EndIf Return $vParam EndFunc ;==>_EnforceArray Func __get_IDs_by_indexes(ByRef $aCtrls, ByRef $aNdxs) ; returns the handles of the controls pointed to by the indexes Local $aTemp[UBound($aNdxs)] For $i = 0 To UBound($aNdxs) - 1 $aTemp[$i] = $aCtrls[$aNdxs[$i] - 1] Next Return $aTemp EndFunc ;==>__get_IDs_by_indexes Func _EndOfGame() ; _WinAPI_PlaySound ("SystemExit" , Null, $SND_ALIAS) GUIDelete() Exit EndFunc ;==>_EndOfGame P.S. At this link (https://web.archive.org/web/20131006161544/http://games.lumosity.com/chimp.html) there is a Flash version of this game.
    • By Barney
      From MiniMax to Machine Learning ... Tic Tac Toe is a good game for studying AI algorithm because it's simple!
      I use Tabular Q Learning to implement this game, Every time a game finished, it will use the Q function to update
      the score of each steps it played.
      Q(S,A) = Q(S,A) + α ∗ (γ ∗ maxaQ(S′,a) − Q(S,A))
      S being the current state, A the current action, S′ the state after doing A, α being the learning rate, γ being the
      discount factor,  and maxaQ(S′,a) the highest Q value of any move in the next state S′, i.e. the Q value of the best
      move in the following state.
      It's funny to see that it plays better and better. That's why people were charmed by Machine Learning!
      Thank you!
      Download: tic_tac_toe.zip

    • By Dan_555
      Hi, this is a Nonogram Game.
      It is compiled for windows in 32bit (64bit does not work as intended!), sourcecode in v3.3.14.5, icon and the required ini file with more than 100 puzzles.
      The Game has an built-in Editor, and can generate random playfields. 
    • By Barney
      Hi guys, I just finished a Connect 4 game by using MiniMax with Alpha Beta Pruning. I haven't written a program for a long time, but writing an
      AI program is always funny! I have to learn how the algorithm works and try to optimize the code to run faster. Let's play and have fun!
       

       

      Oops, I lost the game ...
      Thanks guys!
      Download: Connect 4.zip
    • By gwinter
      Just something I made to auto-collect Gil from FFCC and to test out a new templating system for AutoIt. The templating system is a work in progress, but it is meant to be a companion to AutoIT, which automates creation of GUI, buttons, scripts, templates, etc. It also has built-in chat and group-collaboration, an asset management system and online library for resources.
      -snip-
×
×
  • Create New...