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.





Edited by Jfish
changed title of post

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

Share this post

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



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




GDI 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

Share this post

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):

global $hand = ["5C","KC","QC","JC","10C"]; this is a test array for this function
for $a=0 to 9
Local $hTimer = TimerInit() ;
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)

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

Share this post

Link to post
Share on other sites

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

Regards ALB

Share this post

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

Share this post

Link to post
Share on other sites
Posted (edited)

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 ?


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)

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.




Edited by Xxobster

Share this post

Link to post
Share on other sites
Posted (edited)

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

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

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • 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.
    • By n0ktar
      is it possible to make a wall chams in rainbow six siege using autoit scripts? tell me please and how . 
    • By spikespaz
      The rule against game automation is misguided and unhelpful for the following reasons.
      I am a developer, using AutoIt to automate testing for a game that I am developing. Singleplayer games can be mundane and sometimes cheating can be overlooked. Multiplayer games usually have anticheat against repetitive robotic actions anyways. People want to override the control schemes of games with bad customization. Eg. Axiom Verge, Fortnite (Crouching). Game automation is not always bad. If the user feels the need to automate a singleplayer game for boring or mundane tasks, that is their choice. Similarly, if I wish to use scripts to automate testing, that is my choice.
      Game automation can be a problem for online multiplayer games, giving players a competitive advantage. This could be countered by common sense; ask OP what game they are automating, and is it an online game? What is this script for, and what does it seem to do?

      Please revise the rule as it seems very unnecessary and harmful to people seeking help with innocent attempts at game automation.
    • 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 Mannyfresh31
      This is a game that I'm developing for Slot machines I just finished translating it to English my original version is in Spanish so if I miss spelled or translated something wrongly please accept my apologies I just releasing the Compile version this time just the .exe file Because I'm saving the code for myself since the software was originally written for my business or if someone wants it they have to pay but not you you getting it for free here at Autoit .
      once you run the software for first time is going to ask you for a license and it wont work without it you can get an Access code (license) by request just PM me and provide the code that the software will give when you press the cancel button three times.
      anyways once you're in the game the following hotkeys are set for interacting with it
      "q" for slot one or one credit
      "d" for slot two or five credits
      "1" or "2" or "3" or "4" or "5" to play simple, double, threeple, etc.  once you have credits of course
      "p" to stop the numbers once you're playing
      "c" for configurations or settings
      "i" for printing the receipt
      "s" for exit
      "t" for trading points for credits
      Link to download the game https://drive.google.com/open?id=1x22AM80fjrDjTwwAp_TqbdWyTabawoQX
      and here are some videos so you can see what the game is about
  • Create New...