Jump to content

My poker calculator


 Share

Recommended Posts

I'm very new to this script, but I'm picking it up fast... I'm trying to make a odds calculator for the chance of winning with pocket cards in holdem. So far I can deal out a random pocket...and then deal out the board cards 10,000 times. The values of the cards are set at Aces being 1 and Kings being 13. The suits are set at H for (hearts), S(spades), D(diamonds), C(clubs). I want to know how I can take the seven cards in the game and make the best hand with 5 of them. And then rank the hand.

Thanks in advance,

NeWb

Edited by supernewb
Link to comment
Share on other sites

I'm very new to this script, but I'm picking it up fast... I'm trying to make a odds calculator for the chance of winning with pocket cards in holdem. So far I can deal out a random pocket...and then deal out the board cards 10,000 times. The values of the cards are set at Aces being 1 and Kings being 13. The suits are set at H for (hearts), S(spades), D(diamonds), C(clubs). I want to know how I can take the seven cards in the game and make the best hand with 5 of them. And then rank the hand.

Thanks in advance,

NeWb

Ignore jaenster.

I'm assuming that you know yourself which hands are best in hold'em (royal flush, straight flush, 4 of a kind, etc). Also, Aces can be 1 or 14... they are used as highs or lows. Sounds like what you need to do is just do tests on the cards. Like, when the hand is dealt, start at the top (royal flush) and see if any 5 of the cards match the requirements, and then just move down the line. When one matches, stop searching. That's the hand you have. Then, rank it (however you feel).

Link to comment
Share on other sites

I think I'd do it like this:

Put all 7 cards into an array.

Start with royal flush. First, you have to check if there's an ace in the array. If not, you can skip it already. Proceed until you have an ace, king, queen, jack, 10. Then, on those cards only, check if they are all the same suit. If not, you don't have a royal flush.

Next is straight flush. This is similar to royal... but I think this time I'd start with the flush part. See if there are 5 cards of the same suit. Then, within those cards of the same suit, see if there are 5 in a row.

Next is 4-of-a-kind. This is a simple one: just check if there are 4 of the same card (4 kings, or 4 jacks, etc).

Keep going down the line.

Link to comment
Share on other sites

Ok, one last question! Below is the script I use to find the suit: Notice how it uses the same commands over and over. Is there a way to condense this?

Func Cardsuit(ByRef $P1s, ByRef $P2s, ByRef $As, ByRef $Bs, ByRef $Cs, ByRef $Ds, ByRef $Es)

If $P1<=52 and $P1>39 Then

$P1s="S"

ElseIf $P1<=39 and $P1>26 Then

$P1s="H"

ElseIf $P1<=26 and $P1>13 Then

$P1s="C"

Else

$P1s="D"

EndIf

If $P2<=52 and $P2>39 Then

$P2s="S"

ElseIf $P2<=39 and $P2>26 Then

$P2s="H"

ElseIf $P2<=26 and $P2>13 Then

$P2s="C"

Else

$P2s="D"

EndIf

If $As<=52 and $As>39 Then

$As="S"

ElseIf $As<=39 and $As>26 Then

$As="H"

ElseIf $As<=26 and $As>13 Then

$As="C"

Else

$As="D"

EndIf

If $B<=52 and $B>39 Then

$Bs="S"

ElseIf $B<=39 and $B>26 Then

$Bs="H"

ElseIf $B<=26 and $B>13 Then

$Bs="C"

Else

$Bs="D"

EndIf

If $C<=52 and $C>39 Then

$Cs="S"

ElseIf $C<=39 and $C>26 Then

$Cs="H"

ElseIf $C<=26 and $C>13 Then

$Cs="C"

Else

$Cs="D"

EndIf

If $D<=52 and $D>39 Then

$Ds="S"

ElseIf $D<=39 and $D>26 Then

$Ds="H"

ElseIf $D<=26 and $D>13 Then

$Ds="C"

Else

$Ds="D"

EndIf

If $E<=52 and $E>39 Then

$Es="S"

ElseIf $E<=39 and $E>26 Then

$Es="H"

ElseIf $E<=26 and $E>13 Then

$Es="C"

Else

$Es="D"

EndIf

Link to comment
Share on other sites

I changed it around a bit so it would work out better (for me at least).

Func Cardsuit($P1, $P2, $A, $B, $C, $D, $E)
    Local $CardArray[8] = [7, $P1, $P2, $A, $B, $C, $D, $E]
    Local $CardSuitArray[8]
    For $i = 1 To 7
        If $CardArray[$i] >= 1 And $CardArray[$i] <= 13 Then
            $CardSuitArray[$i] = "D"
        ElseIf $CardArray[$i] >= 14 And $CardArray[$i] <= 26 Then
            $CardSuitArray[$i] = "C"
        ElseIf $CardArray[$i] >= 27 And $CardArray[$i] <= 39 Then
            $CardSuitArray[$i] = "H"
        ElseIf $CardArray[$i] >= 40 And $CardArray[$i] <= 52 Then
            $CardSuitArray[$i] = "S"
        EndIf
    Next
    Return $CardSuitArray
EndFunc

Now you have to input the cards themselves - it takes the inputted card numbers, stores them to an array, calculates the suits for each one, and returns the array of suits relating to each card.

Link to comment
Share on other sites

  • Moderators

This may help in some odd way, I made a Texas Hold'em game bet never completed it, this was some of it

Dim $Cards[53][2]
$Cards[0][0] = 0
For $Suits = 1 To 4
   For $Suits_B = 1 To 13
      $Cards[0][0] = $Cards[0][0] + 1
      If $Suits_B > 9 Then
         If $Suits_B = 10 Then $Cards[$Cards[0][0]][0] = 'T'
         If $Suits_B = 11 Then $Cards[$Cards[0][0]][0] = 'J'
         If $Suits_B = 12 Then $Cards[$Cards[0][0]][0] = 'Q'
         If $Suits_B = 13 Then $Cards[$Cards[0][0]][0] = 'K'
      Else
         If $Suits_B = 1 Then
            $Cards[$Cards[0][0]][0] = 'A'
         Else
            $Cards[$Cards[0][0]][0] = $Suits_B
         EndIf
      EndIf
      If $Suits = 1 Then
         $Cards[$Cards[0][0]][1] = 'S'
      ElseIf $Suits = 2 Then
         $Cards[$Cards[0][0]][1] = 'C'
      ElseIf $Suits = 3 Then
         $Cards[$Cards[0][0]][1] = 'H'
      ElseIf $Suits = 4 Then
         $Cards[$Cards[0][0]][1] = 'D'
      EndIf
   Next
Next

Run("notepad.exe")
Sleep(500)
For $a = 1 To 52
    For $b = 0 To 1
        ControlSend("Untitled - Notepad", "", "Edit1", $Cards[$a][$b])
    Next
    ControlSend("Untitled - Notepad", "", "Edit1", @cr)
Next

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

  • 3 months later...

[almost complete amateur here]

i made an odds calcs in javascript then put into php

on belief it is faster in this format

you are welcome to browse the code for ideas

it is up at www.dougs.cc

however i dont think you can access the code part, so have

taken a copy and put it at

www.dougs.cc/code.txt

as i say, i am happy for people to use the code, however if you use

the majority of it, please donate a link or make mention, ta!

(just something i found humerous, i asked similar of a guy who asked

me to provide the code just to "look over". He said he had no intention to use it, but a day later

this site appeared - notice any similarities??!!!)

anyway, as for the gist - it forms an array of 7 cards, starting with the player's cards and the cards known

and searches for (in roughly this order) royal flush, 4oak, flush, str8, 3of a kind, fh pair, 2pair

the last four might appear wrong order, as most in descending order of strenth, hwover have to look for 3 of a kind before fh,

it assigns a unique number based on hand strength, (for flush this is just one number, for others, it is based on the strength of hand in that category, so for a two pair, the number will uniquely determine the two difrferent pairs held)

when it comes to comparring 7 card arrays, it then can compare the number - and if necessary ask to

see kicker cards, for when the numbers match

my friend mused an alternative method, of finding hand strength by computing all possible 5 card hands from the 7 given cards

dont thnk this has benefits, as 7 choose 2 for each array = 21 possibilities,

his method then created a unique 6 long vector however - hand strenth, top card, second card, third card 4th, 5th

which made it easier comparing hands, as did not have to additionally request kickers

though on other hand, my method might be speedier in only requestion kickers when needed

anyway, will follow this thread with interest, as ever since i saw a 4 line sudoku solver, ive realsed

how much you can improve your code....

regards

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