Application Center - Maplesoft

App Preview:

Poker Calculator

You can switch back to the summary page by clicking here.

Learn about Maple
Download Application




 

 

Poker Calculator

 

Marcus Davidsson (2013)   davidsson_marcus@hotmail.com 

Inspired by:   http://wizardofodds.com/games/texas-hold-em/old-two-player-version/

 

 

 

 

 

We will in this worksheet calculate the pr-flop probability of wining for player-1 given a random par of cards
for a two person poker game. Any combination of aces are superior if you want to win the game :-)

 

 

 

 

We can start with some basic poker probabilities:

 

 

NULL

#

Poker Hand

Frequency

Probability

1

Royal flush

4

4/binomial(52, 5)
 = 1/649740

2

Straight flush

36

36/binomial(52, 5)
 = 3/216580

3

Four of a kind

624

624/binomial(52, 5)
 = 1/4165``

4

Full house

3 744

3744/binomial(52, 5)
 = 6/4165``

5

Flush

5 108

5108/binomial(52, 5)
 = 1277/649740``

6

Straight

10 200

10200/binomial(52, 5)
 = 5/1274``

7

Three of a kind

54 912

54912/binomial(52, 5)
 = 88/4165``

8

Two pair

123 552

123552/binomial(52, 5)
 = 198/4165``

9

One pair

1 098 240

1098240/binomial(52, 5)
 = 352/833``

10

High card

1 302 540

1302540/binomial(52, 5)
 = 1277/2548``

NA

Total

binomial(52, 5)
 = 2598960 

binomial(52, 5)*(1/binomial(52, 5))
 = 1 

 

 

 


We are going to use the following notation:

 

C=Clubs  D=Diamonds  H=Hearts S=Spades    A=Ace K=King Q=Queen J=
Jack

 

 

 

 

We can simulate the hands of two poker player as follows:

 

 

restart; with(Statistics); randomize(); with(combinat); with(ListTools); Clubs := [CA, CK, CQ, CJ, seq(cat(C, i), i = 2 .. 10)]; Diamonds := [DA, DK, DQ, DJ, seq(cat(D, i), i = 2 .. 10)]; Hearts := [HA, HK, HQ, HJ, seq(cat(H, i), i = 2 .. 10)]; Spades := [SA, SK, SQ, SJ, seq(cat(S, i), i = 2 .. 10)]; Cards := [op(Clubs), op(Diamonds), op(Hearts), op(Spades)]; p1 := [Shuffle(Cards)[1]]; Cards := subs([seq(t = NULL, `in`(t, p1))], Cards); p2 := [Shuffle(Cards)[1]]; Cards := subs([seq(t = NULL, `in`(t, p2))], Cards); p1 := [op(p1), Shuffle(Cards)[1]]; Cards := subs([seq(t = NULL, `in`(t, p1))], Cards); p2 := [op(p2), Shuffle(Cards)[1]]; Cards := subs([seq(t = NULL, `in`(t, p2))], Cards); flop := Shuffle(Cards)[1 .. 3]; Cards := subs([seq(t = NULL, `in`(t, flop))], Cards); turn := Shuffle(Cards)[1]; Cards := subs([seq(t = NULL, `in`(t, turn))], Cards); river := Shuffle(Cards)[1]; Cards := subs([seq(t = NULL, `in`(t, river))], Cards); p1 := [op(p1), op(flop), op(turn), op(river)]; p2 := [op(p2), op(flop), op(turn), op(river)]

[H5, C4, S5, HK, H9, C10, C3]

(1)

 

 

 

 

We can now see who won the game:

 

 

X := proc (w) local p1has, z, p1, p11, p11N, p11NN, p11L, c1, c2, c3; p1 := w; unassign('p1has'); if verify(convert([CA, CK, CQ, CJ], set), convert(p1, set), `subset`) = true or verify(convert([DA, DK, DQ, DJ], set), convert(p1, set), `subset`) = true or verify(convert([HA, HK, HQ, HJ], set), convert(p1, set), `subset`) = true or verify(convert([SA, SK, SQ, SJ], set), convert(p1, set), `subset`) = true then p1has := 10 end if; unassign('c1'); unassign('c2'); unassign('c3'); z := {CA = C14, CJ = C11, CK = C13, CQ = C12, DA = D14, DJ = D11, DK = D13, DQ = D12, HA = H14, HJ = H11, HK = H13, HQ = H12, SA = S14, SJ = S11, SK = K13, SQ = S12}; p11 := subs(z, p1); p11N := [parse(convert(p11[1], string)[2 .. 3]), parse(convert(p11[2], string)[2 .. 3]), parse(convert(p11[3], string)[2 .. 3]), parse(convert(p11[4], string)[2 .. 3]), parse(convert(p11[5], string)[2 .. 3]), parse(convert(p11[6], string)[2 .. 3]), parse(convert(p11[7], string)[2 .. 3])]; p11NN := max(p11N); p11L := [parse(convert(p11[1], string)[1]), parse(convert(p11[3], string)[1]), parse(convert(p11[4], string)[1]), parse(convert(p11[5], string)[1]), parse(convert(p11[6], string)[1]), parse(convert(p11[7], string)[1])]; if 5 <= nops([SearchAll(C, p11L)]) then c1 := [SearchAll(C, p11L)]; c2 := [seq(p11N[c1[i]], i = 1 .. nops(c1))] elif 5 <= nops([SearchAll(D, p11L)]) then c1 := [SearchAll(D, p11L)]; c2 := [seq(p11N[c1[i]], i = 1 .. nops(c1))] elif 5 <= nops([SearchAll(H, p11L)]) then c1 := [SearchAll(H, p11L)]; c2 := [seq(p11N[c1[i]], i = 1 .. nops(c1))] elif 5 <= nops([SearchAll(S, p11L)]) then c1 := [SearchAll(S, p11L)]; c2 := [seq(p11N[c1[i]], i = 1 .. nops(c1))] end if; if assigned(c1) = true then c3 := Occurrences(1, [Occurrences(min(c2)+1, c2), Occurrences(min(c2)+2, c2), Occurrences(min(c2)+3, c2), Occurrences(min(c2)+4, c2)]) end if; if assigned(c1) = true and 4 <= c3 then p1has := 9 end if; if max([seq(Occurrences(op(p11N[x]), p11N), x = 1 .. nops(p11N))]) = 4 then p1has := 8 end if; if max([seq(Occurrences(op(p11N[x]), p11N), x = 1 .. nops(p11N))]) = 3 and Occurrences(2, [seq(Occurrences(op(p11N[x]), p11N), x = 1 .. nops(p11N))]) = 2 then p1has := 7 end if; if 5 <= max([nops([SearchAll(C, p11L)]), nops([SearchAll(D, p11L)]), nops([SearchAll(H, p11L)]), nops([SearchAll(S, p11L)])]) then p1has := 6 end if; c3 := Occurrences(1, [Occurrences(min(p11N)+1, p11N), Occurrences(min(p11N)+2, p11N), Occurrences(min(p11N)+3, p11N), Occurrences(min(p11N)+4, p11N)]); if 4 <= c3 then p1has := 5 end if; if max([seq(Occurrences(op(p11N[x]), p11N), x = 1 .. nops(p11N))]) = 3 then p1has := 4 end if; if Occurrences(2, [seq(Occurrences(op(p11N[x]), p11N), x = 1 .. nops(p11N))]) = 4 then p1has := 3 end if; if Occurrences(2, [seq(Occurrences(op(p11N[x]), p11N), x = 1 .. nops(p11N))]) = 2 then p1has := 2 end if; if assigned(p1has) = false then p1has := evalf((1/10)*max(p11N), 4) end if; return [p1has, p11NN] end proc; XX := proc () local rr; if X(p2)[1] < X(p1)[1] then rr := "Player 1 Win" elif X(p1)[1] < X(p2)[1] then rr := "Player 2 Win" elif X(p1)[1] = X(p2)[1] and X(p2)[2] < X(p1)[2] then rr := "Player 1 Win" elif X(p1)[1] = X(p2)[1] and X(p1)[2] < X(p2)[2] then rr := "Player 2 Win" elif X(p1)[1] = X(p2)[1] and X(p1)[2] = X(p2)[2] then rr := "Draw" end if; return rr end proc; XX()

"Draw"

(2)

 

 

 

``

We can use math containers as follows:

 

 

 

``

        Player 1

   Player 2

                  

        

                      

      

 

Outcome

                                    

      

 

 

``

 

 

A generic version is given by (you can change the text in red for any pair of cards):

 

restart:

.77200

(3)

 

 

 

 

 

Finally we can calculate the pre-flop probability of winning given a two card holding for player one
as follows:

NULL

``

``

NULL

restart; with(Statistics); randomize(); with(combinat); with(ListTools); with(LinearAlgebra); X := proc (w) local p1has, z, p1, p11, p11N, p11NN, p11L, c1, c2, c3; p1 := w; unassign('p1has'); if verify(convert([CA, CK, CQ, CJ], set), convert(p1, set), `subset`) = true or verify(convert([DA, DK, DQ, DJ], set), convert(p1, set), `subset`) = true or verify(convert([HA, HK, HQ, HJ], set), convert(p1, set), `subset`) = true or verify(convert([SA, SK, SQ, SJ], set), convert(p1, set), `subset`) = true then p1has := 10 end if; unassign('c1'); unassign('c2'); unassign('c3'); z := {CA = C14, CJ = C11, CK = C13, CQ = C12, DA = D14, DJ = D11, DK = D13, DQ = D12, HA = H14, HJ = H11, HK = H13, HQ = H12, SA = S14, SJ = S11, SK = K13, SQ = S12}; p11 := subs(z, p1); p11N := [parse(convert(p11[1], string)[2 .. 3]), parse(convert(p11[2], string)[2 .. 3]), parse(convert(p11[3], string)[2 .. 3]), parse(convert(p11[4], string)[2 .. 3]), parse(convert(p11[5], string)[2 .. 3]), parse(convert(p11[6], string)[2 .. 3]), parse(convert(p11[7], string)[2 .. 3])]; p11NN := max(p11N); p11L := [parse(convert(p11[1], string)[1]), parse(convert(p11[3], string)[1]), parse(convert(p11[4], string)[1]), parse(convert(p11[5], string)[1]), parse(convert(p11[6], string)[1]), parse(convert(p11[7], string)[1])]; if 5 <= nops([SearchAll(C, p11L)]) then c1 := [SearchAll(C, p11L)]; c2 := [seq(p11N[c1[i]], i = 1 .. nops(c1))] elif 5 <= nops([SearchAll(D, p11L)]) then c1 := [SearchAll(D, p11L)]; c2 := [seq(p11N[c1[i]], i = 1 .. nops(c1))] elif 5 <= nops([SearchAll(H, p11L)]) then c1 := [SearchAll(H, p11L)]; c2 := [seq(p11N[c1[i]], i = 1 .. nops(c1))] elif 5 <= nops([SearchAll(S, p11L)]) then c1 := [SearchAll(S, p11L)]; c2 := [seq(p11N[c1[i]], i = 1 .. nops(c1))] end if; if assigned(c1) = true then c3 := Occurrences(1, [Occurrences(min(c2)+1, c2), Occurrences(min(c2)+2, c2), Occurrences(min(c2)+3, c2), Occurrences(min(c2)+4, c2)]) end if; if assigned(c1) = true and 4 <= c3 then p1has := 9 end if; if max([seq(Occurrences(op(p11N[x]), p11N), x = 1 .. nops(p11N))]) = 4 then p1has := 8 end if; if max([seq(Occurrences(op(p11N[x]), p11N), x = 1 .. nops(p11N))]) = 3 and Occurrences(2, [seq(Occurrences(op(p11N[x]), p11N), x = 1 .. nops(p11N))]) = 2 then p1has := 7 end if; if 5 <= max([nops([SearchAll(C, p11L)]), nops([SearchAll(D, p11L)]), nops([SearchAll(H, p11L)]), nops([SearchAll(S, p11L)])]) then p1has := 6 end if; c3 := Occurrences(1, [Occurrences(min(p11N)+1, p11N), Occurrences(min(p11N)+2, p11N), Occurrences(min(p11N)+3, p11N), Occurrences(min(p11N)+4, p11N)]); if 4 <= c3 then p1has := 5 end if; if max([seq(Occurrences(op(p11N[x]), p11N), x = 1 .. nops(p11N))]) = 3 then p1has := 4 end if; if Occurrences(2, [seq(Occurrences(op(p11N[x]), p11N), x = 1 .. nops(p11N))]) = 4 then p1has := 3 end if; if Occurrences(2, [seq(Occurrences(op(p11N[x]), p11N), x = 1 .. nops(p11N))]) = 2 then p1has := 2 end if; if assigned(p1has) = false then p1has := evalf((1/10)*max(p11N), 4) end if; return [p1has, p11NN] end proc; XX := proc () local rr; if X(p2)[1] < X(p1)[1] then rr := "Player 1 Win" elif X(p1)[1] < X(p2)[1] then rr := "Player 2 Win" elif X(p1)[1] = X(p2)[1] and X(p2)[2] < X(p1)[2] then rr := "Player 1 Win" elif X(p1)[1] = X(p2)[1] and X(p1)[2] < X(p2)[2] then rr := "Player 2 Win" elif X(p1)[1] = X(p2)[1] and X(p1)[2] = X(p2)[2] then rr := "Draw" end if; return rr end proc; Clubs := [CA, CK, CQ, CJ, seq(cat(C, i), i = 2 .. 10)]; Diamonds := [DA, DK, DQ, DJ, seq(cat(D, i), i = 2 .. 10)]; Hearts := [HA, HK, HQ, HJ, seq(cat(H, i), i = 2 .. 10)]; Spades := [SA, SK, SQ, SJ, seq(cat(S, i), i = 2 .. 10)]; Cards := [op(Clubs), op(Diamonds), op(Hearts), op(Spades)]; data := [seq(seq([Cards[i], Cards[j]], i = 1 .. 52), j = 1 .. 52)]; my := Array(1 .. nops(data), 3); for j to nops(data) do Get := data[j]; nsim := 200; cc := 0; cpu := Array(1 .. nsim, 1 .. 1); for sim to nsim do Clubs := [CA, CK, CQ, CJ, seq(cat(C, i), i = 2 .. 10)]; Diamonds := [DA, DK, DQ, DJ, seq(cat(D, i), i = 2 .. 10)]; Hearts := [HA, HK, HQ, HJ, seq(cat(H, i), i = 2 .. 10)]; Spades := [SA, SK, SQ, SJ, seq(cat(S, i), i = 2 .. 10)]; Cards := [op(Clubs), op(Diamonds), op(Hearts), op(Spades)]; p1 := [Get[1]]; Cards := subs([seq(t = NULL, `in`(t, p1))], Cards); p2 := [Shuffle(Cards)[1]]; Cards := subs([seq(t = NULL, `in`(t, p2))], Cards); p1 := [Get[1], Get[2]]; Cards := subs([seq(t = NULL, `in`(t, p1))], Cards); p2 := [op(p2), Shuffle(Cards)[1]]; Cards := subs([seq(t = NULL, `in`(t, p2))], Cards); flop := Shuffle(Cards)[1 .. 3]; Cards := subs([seq(t = NULL, `in`(t, flop))], Cards); turn := Shuffle(Cards)[1]; Cards := subs([seq(t = NULL, `in`(t, turn))], Cards); river := Shuffle(Cards)[1]; Cards := subs([seq(t = NULL, `in`(t, river))], Cards); p1 := [op(p1), op(flop), op(turn), op(river)]; p2 := [op(p2), op(flop), op(turn), op(river)]; cpu[sim, 1] := XX(); if cpu[sim, 1] = "Player 1 Win" then cc := cc+1 end if end do; if data[j][1] = data[j][2] then my[j] := [0, 0, 0] else my[j] := [data[j][], evalf(cc/nsim, 5)] end if end do; My := Matrix(convert(my, listlist)); wq := []; for i to nops(data) do if My[i, 3] = 0 then wq := [op(wq), i] end if end do; My := DeleteRow(My, wq); L := convert(My, listlist); Myy := Matrix(sort(L, proc (a, b) options operator, arrow; b[3] < a[3] end proc)); Histogram(Column(Myy, 3), title = "Pre-flop Probability Winning", titlefont = [times, roman, 16])