Donuts
Donuts
  • Threads: 24
  • Posts: 171
Joined: Oct 17, 2014
September 10th, 2015 at 12:53:08 PM permalink
Hi all,

I was hoping I could get some help debugging some code I've written to play out Wizard's Mississippi Stud Basic Strategy.
The code loops through all 311,875,200 permutations of possible hands, implements BS, and records the results.

However, I'm ending with an EV of -89% compared to wizards -4.91%.

Wizard's Link: https://wizardofodds.com/games/mississippi-stud/

I've checked my pay table, and multiple versions of all hand types and get the correct results at the individual hand level, but for some reason when the whole sim runs I get an extremely negative expectation. Not asking for a deep dive since that would take too long, but if anyone sees an obvious reason why I might be getting terribly incorrect results let me know.

Code:

Public Shoe As Variant
Public FourthStreetArray As Variant
Public FifthStreetArray As Variant
Public Finalhand As Variant
Public Bet As Long
Public Win As Long
Public Hands As Long

Public P1 As String
Public P2 As String
Public R1 As String
Public R2 As String
Public R3 As String

Public P1num As Integer
Public p2num As Integer
Public r1num As Integer
Public r2num As Integer
Public r3num As Integer

Public p1suit As String
Public p2suit As String
Public r1suit As String
Public r2suit As String
Public r3suit As String

Public p1val As Integer
Public p2val As Integer
Public r1val As Integer
Public r2val As Integer
Public r3val As Integer

Sub Main()

Dim rounds As Long
Dim holecardpercent As Integer
Dim unit As Integer

Win = 0
Hands = 0



Call Createshoe
'Call ShuffleArrayInPlace(Shoe)


'Loop All Hands
For v = 0 To 51
P1 = Shoe(v, 0)

For w = 0 To 51
If Shoe(w, 0) <> P1 Then
P2 = Shoe(w, 0)


For x = 0 To 51
If Shoe(x, 0) <> P1 And Shoe(x, 0) <> P2 Then
R1 = Shoe(x, 0)


For y = 0 To 51
If Shoe(y, 0) <> P1 And Shoe(y, 0) <> P2 And Shoe(y, 0) <> R1 Then
R2 = Shoe(y, 0)



For Z = 0 To 51
If Shoe(Z, 0) <> P1 And Shoe(Z, 0) <> P2 And Shoe(Z, 0) <> R1 And Shoe(Z, 0) <> R2 Then
R3 = Shoe(Z, 0)
End If

If P1 <> "" And P2 <> "" And R1 <> "" And R2 <> "" And R3 <> "" Then


Bet = 1
Hands = Hands + 1
'Debug.Print Win
'Debug.Print Hands - 1
Call Dealhands

'Reset Values

'Debug.Print " Trial "
'Debug.Print "---------------------"
'Debug.Print "Play Hand: "; P1; ", "; P2; ", "; R1; ", "; R2; ", "; R3
'Debug.Print "Result (units): "; Bet
'Debug.Print "Total Results (units): "; Win
'Debug.Print "Total Hands: "; Hands
'Debug.Print "---------------------"



End If
R3 = ""
Next Z

End If
R2 = ""
Next y

End If
R1 = ""
Next x

End If
P2 = ""
Next w

Next v

Debug.Print Win
Debug.Print Hands
'Debug.Print Win / Hands

End Sub

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Create Shoe '
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Sub Createshoe()


'Create cards And shoe
Suit = Array("C", "D", "H", "S")
num = Array("2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14")
pointval = Array("0", "0", "0", "0", "1", "1", "1", "1", "1", "2", "2", "2", "2")

'Populate Shoe
ReDim Shoe(0 To 51, 0 To 1) As Variant
For i = 0 To 3
For j = 0 To 12
Shoe(13 * i + j, 0) = num(j) & Suit(i)
Shoe(13 * i + j, 1) = pointval(j)
Next j
Next i


'Worksheets("Sheet1").Range("B1:ba2") = WorksheetFunction.Transpose(Shoe)

End Sub

Sub Dealhands()

'Deal Hand

'Force

'Shoe(0, 0) = "3d"
'Shoe(0, 1) = 0

'Shoe(1, 0) = "14d"
'Shoe(1, 1) = 2

'Shoe(2, 0) = "4d"
'Shoe(2, 1) = 0

'Shoe(3, 0) = "14S"
'Shoe(3, 1) = 2

'Shoe(4, 0) = "14D"
'Shoe(4, 1) = 2


'P1 = Shoe(0, 0)
'P2 = Shoe(1, 0)
'R1 = Shoe(2, 0)
'R2 = Shoe(3, 0)
'R3 = Shoe(4, 0)


P1num = Left(P1, Len(P1) - 1)
p1suit = Right(P1, 1)
p1val = Shoe(0, 1)

p2num = Left(P2, Len(P2) - 1)
p2suit = Right(P2, 1)
p2val = Shoe(1, 1)

r1num = Left(R1, Len(R1) - 1)
r1suit = Right(R1, 1)
r1val = Shoe(2, 1)

r2num = Left(R2, Len(R2) - 1)
r2suit = Right(R2, 1)
r2val = Shoe(3, 1)

r3num = Left(R3, Len(R3) - 1)
r3suit = Right(R3, 1)
r3val = Shoe(4, 1)


'Debug.Print P1; ", "; P1num; ", "; p1suit; ", "; p1val
'Debug.Print P2; ", "; p2num; ", "; p2suit; ", "; p2val
'Debug.Print R1; ", "; r1num; ", "; r1suit; ", "; r1val
'Debug.Print R2; ", "; r2num; ", "; r2suit; ", "; r2val
'Debug.Print R3; ", "; r3num; ", "; r3suit; ", "; r3val

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' No Hole Basic '
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

'>>>>>>>Third Street

'Check Pair (3x)
If P1num = p2num Then
Bet = Bet + 3
Else
'Check High Cards (1x)
If p1val + p2val >= 2 Then
Bet = Bet + 1
Else
'Check Outliers (1x)
If ((P1num = 5 And p2num = 6) Or (P1num = 6 And p2num = 5)) And p1suit = p2suit Then
Bet = Bet + 1
Else
'Fold
If p1val + p2val < 2 Then
Bet = -Bet
Win = Win + Bet
Exit Sub 'Fold
End If
End If
End If
End If




'>>>>>>>Fourth Street

'Find Pair Cards
pair = -1
If P1num = p2num Then
pair = p1val + p2val
Else
If P1num = r1num Then
pair = p1val + r1val
Else
If p2num = r1num Then
pair = p2val + r1val
Else
End If
End If
End If




'Check High Pair (3x)
If pair > 0 Then
Bet = Bet + 3
Else
'Royal Flush Draw (3x)
If p1suit = p2suit And p1suit = r1suit And Application.WorksheetFunction.Min(P1num, p2num, r1num) > 9 Then
Bet = Bet + 3
Else

'Straight Flush (No Gaps) (3x)
If p1suit = p2suit And p1suit = r1suit _
And Application.WorksheetFunction.Max(P1num, p2num, r1num) - Application.WorksheetFunction.Min(P1num, p2num, r1num) < 3 _
And Application.WorksheetFunction.Min(P1num, p2num, r1num) > 4 Then
Bet = Bet + 3
Else


'Check Straight Flush (One Gap + High Card) (3x)
If p1suit = p2suit And p1suit = r1suit _
And Application.WorksheetFunction.Max(P1num, p2num, r1num) - Application.WorksheetFunction.Min(P1num, p2num, r1num) < 4 _
And (p1val = 2 Or p2val = 2 Or r1val = 2) Then
Bet = Bet + 3
Else

'Straight Flush (Ace Low) (One Gap + High Card) (3x)
If p1suit = p2suit And p1suit = r1suit _
And (P1num = 14 Or p2num = 14 Or r1num = 14) _
And P1num <> 5 And p2num <> 5 And r1num <> 5 _
And P1num + p2num + r1num <= 21 Then
Bet = Bet + 3
Else

'Check Straight Flush (Two Gaps) (3x)
If p1suit = p2suit And p1suit = r1suit _
And Application.WorksheetFunction.Max(P1num, p2num, r1num) - Application.WorksheetFunction.Min(P1num, p2num, r1num) < 5 _
And ((p1val = 2 And p2val = 2) Or (p1val And r1val = 2) Or (p2val And r1val = 2)) Then 'At least two high cards
Bet = Bet + 3
Else

'Check Flush (1x)
If p1suit = p2suit And p1suit = r1suit Then
Bet = Bet + 1
Else

'Check Low Pair (1x)
If pair = 0 Then
Bet = Bet + 1
Else

'Check Value Hand (3+ Points) (1x)
If p1val + p2val + r1val >= 3 Then
Bet = Bet + 1
Else

'Check Straight (No Gap) (1x)
If Application.WorksheetFunction.Max(P1num, p2num, r1num) - Application.WorksheetFunction.Min(P1num, p2num, r1num) < 3 _
And Application.WorksheetFunction.Min(P1num, p2num, r1num) > 3 _
And pair = -1 Then
Bet = Bet + 1
Else

'Check Straight (One Gap) (1x)
If Application.WorksheetFunction.Max(P1num, p2num, r1num) - Application.WorksheetFunction.Min(P1num, p2num, r1num) < 4 _
And ((p1val > 0 And p2val > 0) Or (p1val > 0 And r1val > 0) Or (p2val > 0 And r1val > 0)) _
And pair = -1 Then
Bet = Bet + 1
Else
'Fold
Bet = -1 * Bet
Win = Win + Bet
Exit Sub

End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If

'>>>>>>>Fifth Street
'Find Pair Cards
pair = -1
If P1num = p2num Then
pair = p1val + p2val
Else
If P1num = r1num Then
pair = p1val + r1val
Else
If P1num = r2num Then
pair = p1val + r2val
Else
If p2num = r1num Then
pair = p2val + r1val
Else
If p2num = r2num Then
pair = p2val + r2val
Else
If r1num = r2num Then
pair = r1val + r2val
Else
End If
End If
End If
End If
End If
End If

'Find Two Pair
twopair = -1
If P1num = p2num And r1num = r2num Then
twopair = 1
Else
If P1num = r1num And p2num = r2num Then
twopair = 1
Else
If P1num = r2num And p2num = r1num Then
twopair = 1

End If
End If
End If

'Find Three of a Kind
toak = -1
If P1num = p2num And P1num = r1num Then
toak = 1
Else
If P1num = r1num And P1num = r2num Then
toak = 1
Else
If P1num = p2num And P1num = r2num Then
toak = 1
Else
If p2num = r1num And p2num = r2num Then
toak = 1
Else
End If
End If
End If
End If




'Check Made Hands (Mid Pair, High Pair, Two Pair, Three of a Kind) (3x)
If pair > 0 Or twopair = 1 Or toak = 1 Then
Bet = Bet + 3
Else

'Royal Flush Draw (3x)
If p1suit = p2suit And p1suit = r1suit And p1suit = r2suit And Application.WorksheetFunction.Min(P1num, p2num, r1num, r2num) > 9 Then
Bet = Bet + 3
Else

'Flush (3x)
If p1suit = p2suit And p1suit = r1suit And p1suit = r2suit Then
Bet = Bet + 3
Else

'Straight (8 High or Better No Gap) (3x)
If Application.WorksheetFunction.Max(P1num, p2num, r1num, r2num) - Application.WorksheetFunction.Min(P1num, p2num, r1num, r2num) < 4 _
And Application.WorksheetFunction.Max(P1num, p2num, r1num) >= 8 _
And pair = -1 And twopair = -1 And toak = -1 Then
Bet = Bet + 3
Else

'Other Straights (1x)
If Application.WorksheetFunction.Max(P1num, p2num, r1num, r2num) - Application.WorksheetFunction.Min(P1num, p2num, r1num, r2num) < 5 _
And pair = -1 And twopair = -1 And toak = -1 Then
Bet = Bet + 1
Else

'Other Straights (Ace low)(1x)
If (P1num = 14 Or p2num = 14 Or r1num = 14 Or r2num = 14) And _
p1val + p2val + r1val + r2val = 2 And _
pair = -1 And twopair = -1 And toak = -1 Then
Bet = Bet + 1
Else


'Low Pair (1x)
If pair = 0 And twopair = -1 And toak = -1 Then
Bet = Bet + 1
Else

'Four Points+ (1x)
If (p1val + p2val + r1val + r2val) > 3 Then
Bet = Bet + 1
Else

'Three Mids and Previous 3x raise (1x)
If ((p1val = 1 And p2val = 1 And r1val = 1) Or (p1val = 1 And r1val = 1 And r2val = 1) Or (p1val = 1 And p2val = 1 And r2val = 1) Or (p2val = 1 And r1val = 1 And r2val = 1)) _
And Bet > 3 Then
Bet = Bet + 1
Else

'Fold
Bet = -1 * Bet
Win = Win + Bet
Exit Sub

End If
End If
End If
End If
End If
End If
End If
End If
End If


Call Payouts


End Sub

Sub Payouts()

'Find Pair Cards
pair = -1
If P1num = p2num Then
pair = p1val + p2val
Else
If P1num = r1num Then
pair = p1val + r1val
Else
If P1num = r2num Then
pair = p1val + r2val
Else
If P1num = r3num Then
pair = p1val + r3val
Else
If p2num = r1num Then
pair = p2val + r1val
Else
If p2num = r2num Then
pair = p2val + r2val
Else
If p2num = r3num Then
pair = p2val + r3val
Else
If r1num = r2num Then
pair = r1val + r2val
Else
If r1num = r3num Then
pair = r1val + r3val
Else
If r2num = r3num Then
pair = r2val + r3val
Else
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If

'Find Two Pair
twopair = -1

If P1num = p2num And r1num = r2num Then
twopair = 1
Else
If P1num = p2num And r1num = r3num Then
twopair = 1
Else
If P1num = p2num And r1num = r3num Then
twopair = 1
Else
If P1num = r1num And p2num = r2num Then
twopair = 1
Else
If P1num = r1num And p2num = r3num Then
twopair = 1
Else
If P1num = r1num And r2num = r3num Then
twopair = 1
Else
If P1num = r2num And p2num = r1num Then
twopair = 1
Else
If P1num = r2num And p2num = r3num Then
twopair = 1
Else
If P1num = r2num And r1num = r3num Then
twopair = 1
Else
If p2num = r1num And r2num = r3num Then
twopair = 1
Else
If p2num = r2num And r1num = r3num Then
twopair = 1
Else
If p2num = r3num And r1num = r2num Then
twopair = 1
Else



End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If

'Find Three of a Kind
toak = -1
If P1num = p2num And p2num = r1num Then
toak = 1
Else
If P1num = p2num And p2num = r2num Then
toak = 1
Else
If P1num = p2num And p2num = r3num Then
toak = 1
Else
If P1num = r1num And r1num = r2num Then
toak = 1
Else
If P1num = r1num And r1num = r3num Then
toak = 1
Else
If P1num = r2num And r2num = r3num Then
toak = 1
Else
If p2num = r1num And r1num = r2num Then
toak = 1
Else
If p2num = r1num And r1num = r3num Then
toak = 1
Else
If p2num = r2num And r2num = r3num Then
toak = 1
Else
If r1num = r2num And r2num = r3num Then
toak = 1
Else

End If
End If
End If
End If
End If
End If
End If
End If
End If
End If


'Find Four of a Kind
foak = -1
If P1num = p2num And P1num = r1num And P1num = r2num Then
foak = 1
Else
If P1num = p2num And P1num = r1num And P1num = r3num Then
foak = 1
Else
If P1num = p2num And P1num = r2num And P1num = r3num Then
foak = 1
Else
If P1num = r1num And P1num = r2num And P1num = r3num Then
foak = 1
Else
If p2num = r1num And p2num = r2num And p2num = r3num Then
foak = 1
Else
End If
End If
End If
End If
End If





'Royal Flush
If p1suit = p2suit And p1suit = r1suit And p1suit = r2suit And p1suit = r3suit And Application.WorksheetFunction.Min(P1num, p2num, r1num, r2num, r3num) > 9 Then
Bet = Bet * 500
Else
'Straight Flush
If p1suit = p2suit And p1suit = r1suit And p1suit = r2suit And p1suit = r3suit _
And Application.WorksheetFunction.Max(P1num, p2num, r1num, r2num, r3num) - Application.WorksheetFunction.Min(P1num, p2num, r1num, r2num, r3num) = 4 Then
Bet = Bet * 100
Else

'Straight Flush (Ace Low)
If p1suit = p2suit And p1suit = r1suit And p1suit = r2suit And p1suit = r3suit _
And (P1num = 14 Or p2num = 14 Or r1num = 14 Or r2num = 14 Or r3num = 14) And _
p1val + p2val + r1val + r2val + r3val = 2 Then
Bet = Bet * 100
Else

'Four of a Kind
If foak = 1 Then
Bet = Bet * 40
Else

'Full House
If twopair = 1 And toak = 1 Then
Bet = Bet * 10
Else

'Flush
If p1suit = p2suit And p1suit = r1suit And p1suit = r2suit And p1suit = r3suit Then
Bet = Bet * 6
Else

'Straight
If Application.WorksheetFunction.Max(P1num, p2num, r1num, r2num, r3num) - Application.WorksheetFunction.Min(P1num, p2num, r1num, r2num, r3num) = 4 _
And pair = -1 Then
Bet = Bet * 4
Else

'Straight (Ace Low)
If (P1num = 14 Or p2num = 14 Or r1num = 14 Or r2num = 14 Or r3num = 14) And _
p1val + p2val + r1val + r2val + r3val = 2 Then
Bet = Bet * 4
Else

'Three of a Kind
If toak = 1 Then
Bet = Bet * 3
Else

'Two Pair
If twopair = 1 Then
Bet = Bet * 2
Else

'Jacks or Better
If pair = 4 Then
Bet = Bet
Else

'Mid Pair
If pair = 2 Then
Bet = 0
Else
'Loss
Bet = -1 * Bet

End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If



Win = Win + Bet





End Sub

MathExtremist
MathExtremist
  • Threads: 88
  • Posts: 6526
Joined: Aug 31, 2010
September 10th, 2015 at 1:12:25 PM permalink
Well not to be too blunt, but your first bug is writing it in VB. There are well-tested poker evaluation libraries in many other languages, you should absolutely not have to write your own.

If you're stuck with VB, the first thing I'd check is whether your evaluation code yields the right distribution of hands overall. Your denominator is twice as large as it should be -- it's not 311,875,200, it's 52c2*50*49*48 = 155,937,600 combinations. You did say permutations, but are you actually weighting things properly? That might account for it.

To really deep-dive your analysis, do an outcome-by-outcome evaluation and compare it to Mike's EV table. His first line is ante+1+1+1, loss = 43,594,056 combinations. How many do you have for that same event?
"In my own case, when it seemed to me after a long illness that death was close at hand, I found no little solace in playing constantly at dice." -- Girolamo Cardano, 1563
Donuts
Donuts
  • Threads: 24
  • Posts: 171
Joined: Oct 17, 2014
September 10th, 2015 at 2:06:45 PM permalink
Yeah VB sucks - I'm in the process of learning Java and C++ but I'm not proficient enough to write anything complex yet.

Good call on reducing the combinations. I was just going 52*51*50*49*48 not accounting for the interchangeability of the first two cards. The results would be the same though since I'm pulling total win/loss over total hands played. as my final EV number. Each hand would just get played twice instead of once.

I'll try that thanks.
beachbumbabs
beachbumbabs
  • Threads: 101
  • Posts: 14268
Joined: May 21, 2013
September 10th, 2015 at 2:34:36 PM permalink
In "find twopair" with 5 cards (5th street), you have a typo:

If P1num = p2num And r1num = r2num Then
twopair = 1
Else
If P1num = p2num And r1num = r3num Then
twopair = 1
Else
If P1num = p2num And r1num = r3num Then
twopair = 1

The second line is duplicated by the third, and the case of ...And r2num = r3num is skipped instead.

In that same subroutine, you also are missing all 3 cases of If P1num = r3num And...

No idea if those will fix the whole EV difference, but it was fun to look at your work. I'm pretty much a beginner, and not familiar with your min/max functions, so haven't parsed out just how they help determine straights and gaps. Thanks for sharing!
If the House lost every hand, they wouldn't deal the game.
Donuts
Donuts
  • Threads: 24
  • Posts: 171
Joined: Oct 17, 2014
September 10th, 2015 at 3:58:09 PM permalink
Quote: beachbumbabs

In "find twopair" with 5 cards (5th street), you have a typo:

If P1num = p2num And r1num = r2num Then
twopair = 1
Else
If P1num = p2num And r1num = r3num Then
twopair = 1
Else
If P1num = p2num And r1num = r3num Then
twopair = 1

The second line is duplicated by the third, and the case of ...And r2num = r3num is skipped instead.

In that same subroutine, you also are missing all 3 cases of If P1num = r3num And...

No idea if those will fix the whole EV difference, but it was fun to look at your work. I'm pretty much a beginner, and not familiar with your min/max functions, so haven't parsed out just how they help determine straights and gaps. Thanks for sharing!



Thanks for this - I'm sure its a contributing factor.

I also found I wasn't assigning the card values properly from my array (low-0,mid-1,high-2)


P1num = Left(P1, Len(P1) - 1)
p1suit = Right(P1, 1)
p1val = Shoe(0, 1)

p2num = Left(P2, Len(P2) - 1)
p2suit = Right(P2, 1)
p2val = Shoe(1, 1)

r1num = Left(R1, Len(R1) - 1)
r1suit = Right(R1, 1)
r1val = Shoe(2, 1)

r2num = Left(R2, Len(R2) - 1)
r2suit = Right(R2, 1)
r2val = Shoe(3, 1)

r3num = Left(R3, Len(R3) - 1)
r3suit = Right(R3, 1)
r3val = Shoe(4, 1)

The Xval = shoe(x,1) lines needed to be moved up to the hand loops and the x needed to be changed to the variables v-z within those loops.
Donuts
Donuts
  • Threads: 24
  • Posts: 171
Joined: Oct 17, 2014
September 10th, 2015 at 5:39:32 PM permalink
Now getting an EV of -4.58% with a hand count of 155937600 so I'm getting close.

Straights with an Ace as the low card are valid and pay out right?

Current code below:


Public Shoe As Variant
Public FourthStreetArray As Variant
Public FifthStreetArray As Variant
Public Finalhand As Variant
Public bet As Long
Public Win As Long
Public Hands As Long

'losses
'Public bet_1_0_0_Loss As Long

Public P1 As String
Public P2 As String
Public R1 As String
Public R2 As String
Public R3 As String

Public P1num As Integer
Public p2num As Integer
Public r1num As Integer
Public r2num As Integer
Public r3num As Integer

Public p1suit As String
Public p2suit As String
Public r1suit As String
Public r2suit As String
Public r3suit As String

Public p1val As Integer
Public p2val As Integer
Public r1val As Integer
Public r2val As Integer
Public r3val As Integer

Sub Main()

Dim rounds As Long
Dim holecardpercent As Integer
Dim unit As Integer

Application.ScreenUpdating = False
Application.Calculation = xlManual


Call Createshoe
'Call ShuffleArrayInPlace(Shoe)


'Loop All Hands
For v = 0 To 51
P1 = Shoe(v, 0)
p1val = Shoe(v, 1)

For w = 0 To 51
If w > v Then
P2 = Shoe(w, 0)
p2val = Shoe(w, 1)


For x = 0 To 51
If Shoe(x, 0) <> P1 And Shoe(x, 0) <> P2 Then
R1 = Shoe(x, 0)
r1val = Shoe(x, 1)


For y = 0 To 51
If Shoe(y, 0) <> P1 And Shoe(y, 0) <> P2 And Shoe(y, 0) <> R1 Then
R2 = Shoe(y, 0)
r2val = Shoe(y, 1)



For Z = 0 To 51
If Shoe(Z, 0) <> P1 And Shoe(Z, 0) <> P2 And Shoe(Z, 0) <> R1 And Shoe(Z, 0) <> R2 Then
R3 = Shoe(Z, 0)
r3val = Shoe(Z, 1)
End If

If P1 <> "" And P2 <> "" And R1 <> "" And R2 <> "" And R3 <> "" Then


bet = 1
Hands = Hands + 1
Call Dealhands

'Reset Values

'Debug.Print " Trial "
'Debug.Print "---------------------"
'Debug.Print "Play Hand: "; P1; ", "; P2; ", "; R1; ", "; R2; ", "; R3
'Debug.Print "Result (units): "; bet
'Debug.Print "Total Results (units): "; Win
'Debug.Print "Total Hands: "; Hands
'Debug.Print "---------------------"



End If
R3 = ""
Next Z

End If
R2 = ""
Next y

End If
R1 = ""
Next x

End If
P2 = ""
Next w

Next v

Debug.Print Win
Debug.Print Hands
'Debug.Print bet_1_0_0_Loss

Application.ScreenUpdating = True
Application.Calculation = xlAutomatic


End Sub

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Create Shoe '
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Sub Createshoe()


'Create cards And shoe
Suit = Array("C", "D", "H", "S")
num = Array("2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14")
pointval = Array("0", "0", "0", "0", "1", "1", "1", "1", "1", "2", "2", "2", "2")

'Populate Shoe
ReDim Shoe(0 To 51, 0 To 1) As Variant
For i = 0 To 3
For j = 0 To 12
Shoe(13 * i + j, 0) = num(j) & Suit(i)
Shoe(13 * i + j, 1) = pointval(j)
Next j
Next i


'Worksheets("Sheet1").Range("B1:ba2") = WorksheetFunction.Transpose(Shoe)

End Sub



Sub Dealhands()

'Deal Hand

'Force

'Shoe(0, 0) = "3d"
'Shoe(0, 1) = 0

'Shoe(1, 0) = "14d"
'Shoe(1, 1) = 2

'Shoe(2, 0) = "4d"
'Shoe(2, 1) = 0

'Shoe(3, 0) = "14S"
'Shoe(3, 1) = 2

'Shoe(4, 0) = "14D"
'Shoe(4, 1) = 2


'P1 = Shoe(0, 0)
'P2 = Shoe(1, 0)
'R1 = Shoe(2, 0)
'R2 = Shoe(3, 0)
'R3 = Shoe(4, 0)


P1num = Left(P1, Len(P1) - 1)
p1suit = Right(P1, 1)

p2num = Left(P2, Len(P2) - 1)
p2suit = Right(P2, 1)

r1num = Left(R1, Len(R1) - 1)
r1suit = Right(R1, 1)

r2num = Left(R2, Len(R2) - 1)
r2suit = Right(R2, 1)

r3num = Left(R3, Len(R3) - 1)
r3suit = Right(R3, 1)



'Debug.Print P1; ", "; P1num; ", "; p1suit; ", "; p1val
'Debug.Print P2; ", "; p2num; ", "; p2suit; ", "; p2val
'Debug.Print R1; ", "; r1num; ", "; r1suit; ", "; r1val
'Debug.Print R2; ", "; r2num; ", "; r2suit; ", "; r2val
'Debug.Print R3; ", "; r3num; ", "; r3suit; ", "; r3val

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' No Hole Basic '
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

'>>>>>>>Third Street

'Check Pair (3x)
If P1num = p2num Then
bet = bet + 3
a = 3
Else
'Check High Cards (1x)
If p1val + p2val >= 2 Then
bet = bet + 1
a = 1
Else
'Check Outliers (1x)
If ((P1num = 5 And p2num = 6) Or (P1num = 6 And p2num = 5)) And p1suit = p2suit Then
bet = bet + 1
a = 1
Else
'Fold
If p1val + p2val < 2 Then
bet = -bet
Win = Win + bet
'bet_1_0_0_Loss = bet_1_0_0_Loss + 1
Exit Sub 'Fold
End If
End If
End If
End If




'>>>>>>>Fourth Street

'Find Pair Cards
pair = -1
If P1num = p2num Then
pair = p1val + p2val
Else
If P1num = r1num Then
pair = p1val + r1val
Else
If p2num = r1num Then
pair = p2val + r1val
Else
End If
End If
End If




'Check High Pair (3x)
If pair > 0 Then
bet = bet + 3
Else
'Royal Flush Draw (3x)
If p1suit = p2suit And p1suit = r1suit And Application.WorksheetFunction.Min(P1num, p2num, r1num) > 9 Then
bet = bet + 3
Else

'Straight Flush (No Gaps) (3x)
If p1suit = p2suit And p1suit = r1suit _
And Application.WorksheetFunction.Max(P1num, p2num, r1num) - Application.WorksheetFunction.Min(P1num, p2num, r1num) < 3 _
And Application.WorksheetFunction.Min(P1num, p2num, r1num) > 4 Then
bet = bet + 3
Else


'Check Straight Flush (One Gap + High Card) (3x)
If p1suit = p2suit And p1suit = r1suit _
And Application.WorksheetFunction.Max(P1num, p2num, r1num) - Application.WorksheetFunction.Min(P1num, p2num, r1num) < 4 _
And (p1val = 2 Or p2val = 2 Or r1val = 2) Then
bet = bet + 3
Else

'Straight Flush (Ace Low) (One Gap + High Card) (3x)
If p1suit = p2suit And p1suit = r1suit _
And (P1num = 14 Or p2num = 14 Or r1num = 14) _
And P1num <> 5 And p2num <> 5 And r1num <> 5 _
And P1num + p2num + r1num <= 21 Then
bet = bet + 3
Else

'Check Straight Flush (Two Gaps) (3x)
If p1suit = p2suit And p1suit = r1suit _
And Application.WorksheetFunction.Max(P1num, p2num, r1num) - Application.WorksheetFunction.Min(P1num, p2num, r1num) < 5 _
And ((p1val = 2 And p2val = 2) Or (p1val And r1val = 2) Or (p2val And r1val = 2)) Then 'At least two high cards
bet = bet + 3
Else

'Check Flush (1x)
If p1suit = p2suit And p1suit = r1suit Then
bet = bet + 1
Else

'Check Low Pair (1x)
If pair = 0 Then
bet = bet + 1
Else

'Check Value Hand (3+ Points) (1x)
If p1val + p2val + r1val >= 3 Then
bet = bet + 1
Else

'Check Straight (No Gap) (1x)
If Application.WorksheetFunction.Max(P1num, p2num, r1num) - Application.WorksheetFunction.Min(P1num, p2num, r1num) < 3 _
And Application.WorksheetFunction.Min(P1num, p2num, r1num) > 3 _
And pair = -1 Then
bet = bet + 1
Else

'Check Straight (One Gap) (1x)
If Application.WorksheetFunction.Max(P1num, p2num, r1num) - Application.WorksheetFunction.Min(P1num, p2num, r1num) < 4 _
And ((p1val > 0 And p2val > 0) Or (p1val > 0 And r1val > 0) Or (p2val > 0 And r1val > 0)) _
And pair = -1 Then
bet = bet + 1
Else
'Fold
bet = -1 * bet
Win = Win + bet
Exit Sub

End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If

'>>>>>>>Fifth Street
'Find Pair Cards
pair = -1
If P1num = p2num Then
pair = p1val + p2val
Else
If P1num = r1num Then
pair = p1val + r1val
Else
If P1num = r2num Then
pair = p1val + r2val
Else
If p2num = r1num Then
pair = p2val + r1val
Else
If p2num = r2num Then
pair = p2val + r2val
Else
If r1num = r2num Then
pair = r1val + r2val
Else
End If
End If
End If
End If
End If
End If

'Find Two Pair
Twopair = -1
If P1num = p2num And r1num = r2num Then
Twopair = 1
Else
If P1num = r1num And p2num = r2num Then
Twopair = 1
Else
If P1num = r2num And p2num = r1num Then
Twopair = 1

End If
End If
End If

'Find Three of a Kind
toak = -1
If P1num = p2num And P1num = r1num Then
toak = 1
Else
If P1num = r1num And P1num = r2num Then
toak = 1
Else
If P1num = p2num And P1num = r2num Then
toak = 1
Else
If p2num = r1num And p2num = r2num Then
toak = 1
Else
End If
End If
End If
End If




'Check Made Hands (Mid Pair, High Pair, Two Pair, Three of a Kind) (3x)
If pair > 0 Or Twopair = 1 Or toak = 1 Then
bet = bet + 3
Else

'Royal Flush Draw (3x)
If p1suit = p2suit And p1suit = r1suit And p1suit = r2suit And Application.WorksheetFunction.Min(P1num, p2num, r1num, r2num) > 9 Then
bet = bet + 3
Else

'Flush (3x)
If p1suit = p2suit And p1suit = r1suit And p1suit = r2suit Then
bet = bet + 3
Else

'Straight (8 High or Better No Gap) (3x)
If Application.WorksheetFunction.Max(P1num, p2num, r1num, r2num) - Application.WorksheetFunction.Min(P1num, p2num, r1num, r2num) < 4 _
And Application.WorksheetFunction.Max(P1num, p2num, r1num) >= 8 _
And pair = -1 And Twopair = -1 And toak = -1 Then
bet = bet + 3
Else

'Other Straights (1x)
If Application.WorksheetFunction.Max(P1num, p2num, r1num, r2num) - Application.WorksheetFunction.Min(P1num, p2num, r1num, r2num) < 5 _
And pair = -1 And Twopair = -1 And toak = -1 Then
bet = bet + 1
Else

'Other Straights (Ace low)(1x)
If (P1num = 14 Or p2num = 14 Or r1num = 14 Or r2num = 14) And _
p1val + p2val + r1val + r2val = 2 And _
pair = -1 And Twopair = -1 And toak = -1 Then
bet = bet + 1
Else


'Low Pair (1x)
If pair = 0 And Twopair = -1 And toak = -1 Then
bet = bet + 1
Else

'Four Points+ (1x)
If (p1val + p2val + r1val + r2val) > 3 Then
bet = bet + 1
Else

'Three Mids and Previous 3x raise (1x)
If ((p1val = 1 And p2val = 1 And r1val = 1) Or (p1val = 1 And r1val = 1 And r2val = 1) Or (p1val = 1 And p2val = 1 And r2val = 1) Or (p2val = 1 And r1val = 1 And r2val = 1)) _
And bet > 3 Then
bet = bet + 1
Else

'Fold
bet = -1 * bet
Win = Win + bet
Exit Sub

End If
End If
End If
End If
End If
End If
End If
End If
End If


Call Payouts




''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Flop Hole Basic '
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
End Sub

Sub Payouts()

'Find Pair Cards
pair = -1
If P1num = p2num Then
pair = p1val + p2val
Else
If P1num = r1num Then
pair = p1val + r1val
Else
If P1num = r2num Then
pair = p1val + r2val
Else
If P1num = r3num Then
pair = p1val + r3val
Else
If p2num = r1num Then
pair = p2val + r1val
Else
If p2num = r2num Then
pair = p2val + r2val
Else
If p2num = r3num Then
pair = p2val + r3val
Else
If r1num = r2num Then
pair = r1val + r2val
Else
If r1num = r3num Then
pair = r1val + r3val
Else
If r2num = r3num Then
pair = r2val + r3val
Else
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If

'Find Two Pair
Twopair = -1

If P1num = p2num And r1num = r2num Then
Twopair = 1
Else
If P1num = p2num And r1num = r3num Then
Twopair = 1
Else
If P1num = p2num And r2num = r3num Then
Twopair = 1
Else
If P1num = r1num And p2num = r2num Then
Twopair = 1
Else
If P1num = r1num And p2num = r3num Then
Twopair = 1
Else
If P1num = r1num And r2num = r3num Then
Twopair = 1
Else
If P1num = r2num And p2num = r1num Then
Twopair = 1
Else
If P1num = r2num And p2num = r3num Then
Twopair = 1
Else
If P1num = r2num And r1num = r3num Then
Twopair = 1
Else
If p2num = r1num And r2num = r3num Then
Twopair = 1
Else
If p2num = r2num And r1num = r3num Then
Twopair = 1
Else
If p2num = r3num And r1num = r2num Then
Twopair = 1
Else
If P1num = r3num And p2num = r1num Then
Twopair = 1
Else
If P1num = r3num And p2num = r2num Then
Twopair = 1
Else
If P1num = r3num And r1num = r2num Then
Twopair = 1





End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If

'Find Three of a Kind
toak = -1
If P1num = p2num And p2num = r1num Then
toak = 1
Else
If P1num = p2num And p2num = r2num Then
toak = 1
Else
If P1num = p2num And p2num = r3num Then
toak = 1
Else
If P1num = r1num And r1num = r2num Then
toak = 1
Else
If P1num = r1num And r1num = r3num Then
toak = 1
Else
If P1num = r2num And r2num = r3num Then
toak = 1
Else
If p2num = r1num And r1num = r2num Then
toak = 1
Else
If p2num = r1num And r1num = r3num Then
toak = 1
Else
If p2num = r2num And r2num = r3num Then
toak = 1
Else
If r1num = r2num And r2num = r3num Then
toak = 1
Else

End If
End If
End If
End If
End If
End If
End If
End If
End If
End If


'Find Four of a Kind
foak = -1
If P1num = p2num And P1num = r1num And P1num = r2num Then
foak = 1
Else
If P1num = p2num And P1num = r1num And P1num = r3num Then
foak = 1
Else
If P1num = p2num And P1num = r2num And P1num = r3num Then
foak = 1
Else
If P1num = r1num And P1num = r2num And P1num = r3num Then
foak = 1
Else
If p2num = r1num And p2num = r2num And p2num = r3num Then
foak = 1
Else
End If
End If
End If
End If
End If





'Royal Flush
If p1suit = p2suit And p1suit = r1suit And p1suit = r2suit And p1suit = r3suit And Application.WorksheetFunction.Min(P1num, p2num, r1num, r2num, r3num) > 9 Then
bet = bet * 500
Else
'Straight Flush
If p1suit = p2suit And p1suit = r1suit And p1suit = r2suit And p1suit = r3suit _
And Application.WorksheetFunction.Max(P1num, p2num, r1num, r2num, r3num) - Application.WorksheetFunction.Min(P1num, p2num, r1num, r2num, r3num) = 4 Then
bet = bet * 100
Else

'Straight Flush (Ace Low)
If p1suit = p2suit And p1suit = r1suit And p1suit = r2suit And p1suit = r3suit _
And (P1num = 14 Or p2num = 14 Or r1num = 14 Or r2num = 14 Or r3num = 14) And _
p1val + p2val + r1val + r2val + r3val = 2 Then
bet = bet * 100
Else

'Four of a Kind
If foak = 1 Then
bet = bet * 40
Else

'Full House
If Twopair = 1 And toak = 1 Then
bet = bet * 10
Else

'Flush
If p1suit = p2suit And p1suit = r1suit And p1suit = r2suit And p1suit = r3suit Then
bet = bet * 6
Else

'Straight
If Application.WorksheetFunction.Max(P1num, p2num, r1num, r2num, r3num) - Application.WorksheetFunction.Min(P1num, p2num, r1num, r2num, r3num) = 4 _
And pair = -1 Then
bet = bet * 4
Else

'Straight (Ace Low)
If (P1num = 14 Or p2num = 14 Or r1num = 14 Or r2num = 14 Or r3num = 14) And _
p1val + p2val + r1val + r2val + r3val = 2 Then
bet = bet * 4
Else

'Three of a Kind
If toak = 1 Then
bet = bet * 3
Else

'Two Pair
If Twopair = 1 Then
bet = bet * 2
Else

'Jacks or Better
If pair = 4 Then
bet = bet
Else

'Mid Pair
If pair = 2 Then
bet = 0
Else
'Loss
bet = -1 * bet

End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If



Win = Win + bet


End Sub


ThatDonGuy
ThatDonGuy
  • Threads: 122
  • Posts: 6679
Joined: Jun 22, 2011
September 10th, 2015 at 7:05:14 PM permalink
Your code would be a little more readable if you would use ElseIf rather than a stack of Else...If statements. Also, the word "Or" is your friend in boolean expressions.
Donuts
Donuts
  • Threads: 24
  • Posts: 171
Joined: Oct 17, 2014
September 10th, 2015 at 7:59:11 PM permalink
Quote: ThatDonGuy

Your code would be a little more readable if you would use ElseIf rather than a stack of Else...If statements. Also, the word "Or" is your friend in boolean expressions.



Forgot about elseif. :<

I used "or" quite a bit - are these specific places I should modify the code?
ThatDonGuy
ThatDonGuy
  • Threads: 122
  • Posts: 6679
Joined: Jun 22, 2011
September 11th, 2015 at 8:35:51 AM permalink
Found one:
When you have 3 cards (the "fourth street" block), if you have three of a kind of 2s-5s, you should bet 3x, but your code treats it as a "low pair" with a 1x bet.

Also, I wouldn't count A34 suited as "straight flush, one gap, and one high card" as there is only one way to make it (2 and 5) rather than two ways with any other "one-gap" straight that's not Ace-high.

Another one: I see this in the Fourth Street Straight Flush (Two Gaps + Two High Cards) section:
(p1val = 2 And p2val = 2) Or (p1val And r1val = 2) Or (p2val And r1val = 2)

I am not familiar enough with VB to know how something like "(p1val And r1val = 2)" is treated (I would expect the compiler to throw an error).
I assume it should be:
(p1val = 2 And p2val = 2) Or (p1val = 2 And r1val = 2) Or (p2val = 2 And r1val = 2)


Here's where you could have used "Or":
toak = -1
If P1num = p2num And P1num = r1num Then
toak = 1
Else
If P1num = r1num And P1num = r2num Then
toak = 1
Else
If P1num = p2num And P1num = r2num Then
toak = 1
Else
If p2num = r1num And p2num = r2num Then
toak = 1
Else
End If
End If
End If
End If

can be:
toak = -1
If (P1num = p2num And P1num = r1num) _
Or (P1num = r1num And P1num = r2num) _
Or (If P1num = p2num And P1num = r2num) _
Or (p2num = r1num And p2num = r2num) Then
toak = 1
End If
Donuts
Donuts
  • Threads: 24
  • Posts: 171
Joined: Oct 17, 2014
September 11th, 2015 at 10:42:44 AM permalink
Quote: ThatDonGuy

Found one:
When you have 3 cards (the "fourth street" block), if you have three of a kind of 2s-5s, you should bet 3x, but your code treats it as a "low pair" with a 1x bet.

Also, I wouldn't count A34 suited as "straight flush, one gap, and one high card" as there is only one way to make it (2 and 5) rather than two ways with any other "one-gap" straight that's not Ace-high.

Another one: I see this in the Fourth Street Straight Flush (Two Gaps + Two High Cards) section:

(p1val = 2 And p2val = 2) Or (p1val And r1val = 2) Or (p2val And r1val = 2)

I am not familiar enough with VB to know how something like "(p1val And r1val = 2)" is treated (I would expect the compiler to throw an error).
I assume it should be:
(p1val = 2 And p2val = 2) Or (p1val = 2 And r1val = 2) Or (p2val = 2 And r1val = 2)


Here's where you could have used "Or":
toak = -1
If P1num = p2num And P1num = r1num Then
toak = 1
Else
If P1num = r1num And P1num = r2num Then
toak = 1
Else
If P1num = p2num And P1num = r2num Then
toak = 1
Else
If p2num = r1num And p2num = r2num Then
toak = 1
Else
End If
End If
End If
End If

can be:
toak = -1
If (P1num = p2num And P1num = r1num) _
Or (P1num = r1num And P1num = r2num) _
Or (If P1num = p2num And P1num = r2num) _
Or (p2num = r1num And p2num = r2num) Then
toak = 1
End If




Thanks - definitely good stuff.
  • Jump to: