The VB.net code below calculates the probability a specific pre-flop hand will win given a number of players in Texas Hold’em.
To make the code below into an executable desktop application on Windows follow these steps:
1. If you don’t have “Visual Studio Express of Windows Desktop” you can download it for free from http://www.visualstudio.com/downloads/download-visual-studio-vs#d-express-web.
2. Create a new project that is a “Windows Form Application”, name it Deal (or choose any name you want).
3. In the “Solution Explorer” (box on the upper right side of the application) click on “Form1.vb” to select it then click on it again to rename it. Change the name to dealHands.vb. You will get the message “You are renaming a file…….”. Click “Yes”.
4. In the “Solution Explorer” click on the “Show AllFiles” icon (hover over each icon to find which one it is).
5. In the “Solution Explorer” expand “dealHands.vb” by clicking on the arrow pointing to it.
6. In the “Solution Explorer” right click on “dealHands.vb” and choose “View Code”.
7. In the “dealHands.vb” code window (big box on the left side that occupies most of the page) select all the code shown (should only be 2 lines, ctrl-A will select it) and insert the “dealHands.vb” code below.
8. In the “Solution Explorer” right click on “dealHands.Designer.vb” and choose “View Code”.
9. In the “dealHands.Designer.vb” code window select all the code shown and insert the “dealHands.Designer.vb” code below.
10.To compile and run the application click the green arrow at the top next to the word “Start” and you have a running Windows application.
dealHands.vb
Imports System.Threading
Public Class dealHands
Public Const ACE As Integer = 12
Public Const DEUCE As Integer = 0
Public Const THREE As Integer = 1
Public Const FOUR As Integer = 2
Public Const FIVE As Integer = 3
Public Const SIX As Integer = 4
Public Const SEVEN As Integer = 5
Public Const EIGHT As Integer = 6
Public Const NINE As Integer = 7
Public Const TEN As Integer = 8
Public Const JACK As Integer = 9
Public Const QUEEN As Integer = 10
Public Const KING As Integer = 11
Public Const HANDTYPE As Long = 10000000000
Public Const FIRSTKICKER As Integer = 100000000
Public Const SECONDKICKER As Integer = 1000000
Public Const THIRDKICKER As Integer = 10000
Public Const FOURTHKICKER As Integer = 100
Public Const FIFTHKICKER As Integer = 1
Public Const SFLUSH As Integer = 9
Public Const QUADS As Integer = 8
Public Const BOAT As Integer = 7
Public Const FLUSH As Integer = 6
Public Const STRAIGHT As Integer = 5
Public Const TRIPS As Integer = 4
Public Const TWOPAIR As Integer = 3
Public Const ONEPAIR As Integer = 2
Public Const HIGHCARD As Integer = 1
Public Const UNKNOWN As Integer = 0
Public cardRank() As String = {"2", "3", "4", "5", "6", "7", "8", "9", "T", "J", "Q", "K", "A"}
Public deck() As String = {"2c", "2d", "2h", "2s", _
"3c", "3d", "3h", "3s", _
"4c", "4d", "4h", "4s", _
"5c", "5d", "5h", "5s", _
"6c", "6d", "6h", "6s", _
"7c", "7d", "7h", "7s", _
"8c", "8d", "8h", "8s", _
"9c", "9d", "9h", "9s", _
"Tc", "Td", "Th", "Ts", _
"Jc", "Jd", "Jh", "Js", _
"Qc", "Qd", "Qh", "Qs", _
"Kc", "Kd", "Kh", "Ks", _
"Ac", "Ad", "Ah", "As"}
Public shuffDeck(51) As Short
Public cardIndex As Short
Public noMatch As Boolean
Public randHold As Short
Public dealtCardIndex As Short
Public Shared suitedHandsDealt(1213) As Integer
Public Shared suitedHandsWon(1213) As Integer
Public Shared unsuitedHandsDealt(1213) As Integer
Public Shared unsuitedHandsWon(1213) As Integer
Public flop(4) As Short
Public isSuited As Boolean
Public handValue(9) As Long
Public handIsSuited(9) As Boolean
Public handCards(9, 6) As Short
Public handKey(9) As Short
Public playerIndex As Short
Public winningHand As Long
Public hold As Short
Public sortedCards(6) As Short
Public cardCount(12) As Short
Public highCardUsed As Short
Public highPair As Short
Public lowPair As Short
Public quadsUsed As Short
Public highTrips As Short
Public pair As Short
Public suits(3) As Short
Public flushSuit As Short
Public kicker1 As Short
Public kicker2 As Short
Public kicker3 As Short
Public holdCard As Short
Public handIndex As Short
Public Shared handCounter As Long
Public sw As New Stopwatch
Public Shared running As Boolean = False
Public row As Short
Public card1 As Short
Public card2 As Short
Public elapsedTime As String
Public ts As TimeSpan
Public dealThread As System.Threading.Thread
Public handsToBePlayed As Long
Public Delegate Sub updateDelagate()
'Public gotHighCard As Boolean = False
'Public gotPair As Boolean = False
'Public gotTwoPair As Boolean = False
'Public gotTrips As Boolean = False
'Public gotStraight As Boolean = False
'Public gotFlush As Boolean = False
'Public gotBoat As Boolean = False
'Public gotQuads As Boolean = False
'Public gotSFlush As Boolean = False
'Public debugHandCards(9, 6) As Short
Private Sub dealHands_Load(sender As Object, e As EventArgs) Handles MyBase.Load
End Sub
Private Sub runStop_Click(sender As Object, e As EventArgs) Handles runStop.Click
If runStop.Text = "Run" Then
runStop.Text = "Stop"
running = True
sw.Start()
handsToBePlayed = handsToPlay.Text
dealThread = New System.Threading.Thread(AddressOf deal)
dealThread.Start()
Else
doneWithRun()
End If
End Sub
Private Sub getDeck()
Randomize()
shuffDeck(0) = CInt(Int(52 * Rnd())) ' first card is easy to deal just a random number
' After the first card we need to check that the card has not been dealt already
For Me.cardIndex = 1 To 51
While True
noMatch = True
randHold = CInt(Int(52 * Rnd()))
For Me.dealtCardIndex = 0 To (Me.cardIndex - 1)
If shuffDeck(Me.dealtCardIndex) = randHold Then
noMatch = False
Exit For
End If
Next
If noMatch Then
shuffDeck(Me.cardIndex) = randHold
Exit While
End If
End While
Next
End Sub
Private Sub playersPerHand_GotFocus(sender As Object, e As EventArgs) Handles playersPerHand.GotFocus
If running Then
suitedHands.Focus()
MsgBox("Must stop before changing Players Per Hand", MsgBoxStyle.Exclamation, "Error")
Exit Sub
End If
If handCounter > 0 Then
suitedHands.Focus()
If MsgBox("Already running with a Players per Hand. Do you want reset all counts " + _
"and the timer and enter a new Players per Hand?", MsgBoxStyle.YesNo, "Reset?") = MsgBoxResult.Yes Then
handCounter = 0
sw.Reset()
unsuitedHands.Rows.Clear()
suitedHands.Rows.Clear()
For i = 0 To 1212
unsuitedHandsDealt(i) = 0
suitedHandsDealt(i) = 0
unsuitedHandsWon(i) = 0
suitedHandsWon(i) = 0
Next
showTimeAndCount()
playersPerHand.Focus()
End If
End If
End Sub
Private Sub playersPerHand_Leave(sender As Object, e As EventArgs) Handles playersPerHand.Leave
If Not IsNumeric(playersPerHand.Text) Then
MsgBox("Players per hand must be a number between 2 and 10!", MsgBoxStyle.Exclamation, "Invalid Players Per Hand")
playersPerHand.Text = 10
playersPerHand.Focus()
End If
If playersPerHand.Text < 2 Or playersPerHand.Text > 10 Then
MsgBox("Players per hand must be a number between 2 and 10!", MsgBoxStyle.Exclamation, "Invalid Players Per Hand")
playersPerHand.Text = 10
playersPerHand.Focus()
End If
End Sub
Private Sub handsToPlay_GotFocus(sender As Object, e As EventArgs) Handles handsToPlay.GotFocus
If running Then
suitedHands.Focus()
MsgBox("Must stop before changing Hands to Play", MsgBoxStyle.Exclamation, "Error")
Exit Sub
End If
If handCounter > 0 Then
suitedHands.Focus()
If MsgBox("Already running with a Hands to play. Do you want reset all counts " + _
"and the timer and enter a new Players per Hand?", MsgBoxStyle.YesNo, "Reset?") = MsgBoxResult.Yes Then
handCounter = 0
sw.Reset()
unsuitedHands.Rows.Clear()
suitedHands.Rows.Clear()
For i = 0 To 1212
unsuitedHandsDealt(i) = 0
suitedHandsDealt(i) = 0
unsuitedHandsWon(i) = 0
suitedHandsWon(i) = 0
Next
showTimeAndCount()
handsToPlay.Focus()
End If
End If
End Sub
Private Sub handsToPlay_Leave(sender As Object, e As EventArgs) Handles handsToPlay.Leave
If Not IsNumeric(handsToPlay.Text) Then
MsgBox("Players per hand must be a number between 1000 and 10000000000!", MsgBoxStyle.Exclamation, "Invalid Hands To Play")
handsToPlay.Text = 10000000
handsToPlay.Focus()
End If
If handsToPlay.Text < 1000 Or handsToPlay.Text > 10000000000 Then
MsgBox("Players per hand must be a number between 1000 and 10000000000!", MsgBoxStyle.Exclamation, "Invalid Hands To Play")
handsToPlay.Text = 10000000
handsToPlay.Focus()
End If
End Sub
Protected Sub deal()
Dim showRunning As updateDelagate = AddressOf showTimeAndCount
For handsPlayed As Long = 1 To handsToBePlayed
If running Then
getDeck()
Dim cardNo As Short = 0
For Me.cardIndex = 0 To 1
For Me.playerIndex = 0 To (playersPerHand.Text - 1)
handCards(playerIndex, cardIndex) = shuffDeck(cardNo)
cardNo = cardNo + 1
Next
Next
cardNo = cardNo + 1 'burn - the burns probably don't affect the outcome but it follows the way the game is played
flop(0) = shuffDeck(cardNo)
cardNo = cardNo + 1
flop(1) = shuffDeck(cardNo)
cardNo = cardNo + 1
flop(2) = shuffDeck(cardNo)
cardNo = cardNo + 2 ' 1 for burn
flop(3) = shuffDeck(cardNo)
cardNo = cardNo + 2 ' 1 for burn
flop(4) = shuffDeck(cardNo)
For Me.playerIndex = 0 To (playersPerHand.Text - 1)
For Me.cardIndex = 2 To 6
'Add the board cards to each players hand to be used in valuing the hand
handCards(playerIndex, cardIndex) = flop(cardIndex - 2)
Next
Next
'For Me.playerIndex = 0 To (playersPerHand.Text - 1)
'For Me.cardIndex = 0 To 6
'debugHandCards(playerIndex, cardIndex) = handCards(playerIndex, cardIndex)
'Next
'Next
winningHand = 0
For Me.playerIndex = 0 To (playersPerHand.Text - 1)
handIsSuited(playerIndex) = False
card1 = handCards(playerIndex, 0)
card2 = handCards(playerIndex, 1)
'getHandValue computes value for each hand this will be
'used to compute the winning hand.
'getHandValue may change the order of the cards to calculate
'the proper value so I need to store the players cards
'before we calculate value
getHandValue(playerIndex)
If (card1 Mod 4) = (card2 Mod 4) Then
handIsSuited(playerIndex) = True
End If
'cards are identified by their position in a sorted deck
'by doing a modulus operation on the card number you get
'the suit (we only care if the players cards are suited not
'what suit they are) by dividing by 4 we get the value of the
'card. For example at index 4 is the THREE of CLUBS, at index 5
'is the THREE of DIAMONDS ..... by doing an integer divide by
'4 gets us a result of 1 regardless of the suit. And 1 is the
'index for a THREE.
card1 = card1 \ 4
card2 = card2 \ 4
'Once we've removed suit from the card value we want the relativly
'higher ranked card to always be the first card (does not matter
'for pairs
If card1 < card2 Then
hold = card1
card1 = card2
card2 = hold
End If
handKey(playerIndex) = (card1 * 100) + card2
If handValue(playerIndex) > winningHand Then
winningHand = handValue(playerIndex)
End If
Next
'For Me.playerIndex = 0 To (playersPerHand.Text - 1)
'Console.Write("Player " + playerIndex.ToString + " ")
'For Me.cardIndex = 0 To 6
'Console.Write(deck(debugHandCards(playerIndex, cardIndex)).ToString + " ")
'Next
'Console.WriteLine(handValue(playerIndex).ToString)
'Next
'Console.WriteLine("Winning hand is " + winningHand.ToString)
For Me.playerIndex = 0 To (playersPerHand.Text - 1)
If (handValue(playerIndex) <> 0) Then
If (handIsSuited(playerIndex)) Then
suitedHandsDealt(handKey(playerIndex)) = suitedHandsDealt(handKey(playerIndex)) + 1
Else
unsuitedHandsDealt(handKey(playerIndex)) = unsuitedHandsDealt(handKey(playerIndex)) + 1
End If
End If
If (handValue(playerIndex) = winningHand) Then
If (handIsSuited(playerIndex)) Then
suitedHandsWon(handKey(playerIndex)) = suitedHandsWon(handKey(playerIndex)) + 1
Else
unsuitedHandsWon(handKey(playerIndex)) = unsuitedHandsWon(handKey(playerIndex)) + 1
End If
End If
Next
handCounter = handCounter + 1
If handCounter Mod 10000 = 0 Then
Me.Invoke(showRunning)
End If
Else
Exit For
End If
Next
Dim updateUI As updateDelagate = AddressOf doneWithRun
Me.Invoke(updateUI)
End Sub
Private Sub getHandValue(playerIndex As Short)
handValue(playerIndex) = UNKNOWN
'Makes sense to check for a flush first, if a flush exists within the seven cards
'the only higher possible hand is a straight flush which is easy to check for
'using the same code that will check for a straight
isThereAFlush(playerIndex)
If handValue(playerIndex) = UNKNOWN Then
If Not isThereQuads(playerIndex) Then
If Not isThereABoat(playerIndex) Then
If Not isThereAStraight(playerIndex) Then
If Not isThereTrips(playerIndex) Then
If Not isThereTwoPairs(playerIndex) Then
If Not isThereAPair(playerIndex) Then
For i = 0 To 6
sortedCards(i) = handCards(playerIndex, i) \ 4
Next
sortCards()
handValue(playerIndex) = (HANDTYPE * HIGHCARD) + (FIRSTKICKER * sortedCards(0)) + _
(SECONDKICKER * sortedCards(1)) + (THIRDKICKER * sortedCards(2)) + _
(FOURTHKICKER * sortedCards(3)) + (FIFTHKICKER * sortedCards(4))
'If Not gotHighCard Then
'Console.WriteLine("Got high card")
'gotHighCard = True
'End If
End If
End If
End If
End If
End If
End If
End If
End Sub
Private Function isThereQuads(playerIndex As Short) As Boolean
loadCardCount(playerIndex)
For i As Short = 12 To 0 Step -1
If cardCount(i) = 4 Then
'We have quads
'FIRSTKICKER is what you have 4 of
'no need for a second kicker because 2 players can't
'have the same quads
handValue(playerIndex) = (HANDTYPE * QUADS) + FIRSTKICKER * i
'If Not gotQuads Then
'Console.WriteLine("Got quads")
'gotQuads = True
'End If
Return True
End If
Next
Return False
End Function
Private Function isThereABoat(playerIndex As Short) As Boolean
loadCardCount(playerIndex)
highTrips = -1
highPair = -1
For i As Short = 12 To 0 Step -1
If cardCount(i) = 3 Then
highTrips = i
Exit For
End If
Next
If highTrips > -1 Then
For i As Short = 12 To 0 Step -1
If i <> highTrips Then
If (cardCount(i) > 1) Then ' Could have 2 trips in which case second trips count as a pair
highPair = i
handValue(playerIndex) = (HANDTYPE * BOAT) + (FIRSTKICKER * highTrips) + (SECONDKICKER * highPair)
'If Not gotBoat Then
' Console.WriteLine("Got boat")
' gotBoat = True
'End If
Return True
End If
End If
Next
End If
Return False
End Function
Private Function isThereAFlush(playerIndex As Short) As Boolean
ReDim suits(3)
flushSuit = -1
For Me.cardIndex = 0 To 6
suits(handCards(playerIndex, cardIndex) Mod 4) = suits(handCards(playerIndex, cardIndex) Mod 4) + 1
Next
For i As Short = 0 To 3
If suits(i) > 4 Then
flushSuit = i
Exit For
End If
Next
If flushSuit <> -1 Then
'OK we have a flush is it a straight Flush?
'first lets remove the unsuited cards so we check for a straight
For Me.cardIndex = 0 To 6
If (handCards(playerIndex, cardIndex) Mod 4) = flushSuit Then
sortedCards(cardIndex) = handCards(playerIndex, cardIndex) \ 4
Else
sortedCards(cardIndex) = -1
handCards(playerIndex, cardIndex) = -1
End If
Next
If isThereAStraight(playerIndex) Then
' Wow a Straight Flush!
handValue(playerIndex) = (HANDTYPE * SFLUSH) + (FIRSTKICKER * highCardUsed) 'highCardUsed comes from isThereAStraight
'If Not gotSFlush Then
'Console.WriteLine("Got Sflush")
'gotSFlush = True
'End If
Return True
Else
sortCards()
handValue(playerIndex) = (HANDTYPE * FLUSH) + (FIRSTKICKER * sortedCards(0)) + (SECONDKICKER * sortedCards(1)) + _
(THIRDKICKER * sortedCards(2)) + (FOURTHKICKER * sortedCards(3)) + (FIFTHKICKER * sortedCards(4))
'If Not gotFlush Then
'Console.WriteLine("Got flush")
'gotFlush = True
'End If
Return True
End If
End If
Return False
End Function
Private Function isThereAStraight(playerIndex) As Boolean
loadCardCount(playerIndex)
highCardUsed = -1
If cardCount(FIVE) > 0 And cardCount(FOUR) > 0 And cardCount(THREE) > 0 And cardCount(DEUCE) > 0 And cardCount(ACE) > 0 Then
highCardUsed = FIVE
End If
If cardCount(SIX) > 0 And cardCount(FIVE) > 0 And cardCount(FOUR) > 0 And cardCount(THREE) > 0 And cardCount(DEUCE) > 0 Then
highCardUsed = SIX
End If
If cardCount(SEVEN) > 0 And cardCount(SIX) > 0 And cardCount(FIVE) > 0 And cardCount(FOUR) > 0 And cardCount(THREE) > 0 Then
highCardUsed = SEVEN
End If
If cardCount(EIGHT) > 0 And cardCount(SEVEN) > 0 And cardCount(SIX) > 0 And cardCount(FIVE) > 0 And cardCount(FOUR) > 0 Then
highCardUsed = EIGHT
End If
If cardCount(NINE) > 0 And cardCount(EIGHT) > 0 And cardCount(SEVEN) > 0 And cardCount(SIX) > 0 And cardCount(FIVE) > 0 Then
highCardUsed = NINE
End If
If cardCount(TEN) > 0 And cardCount(NINE) > 0 And cardCount(EIGHT) > 0 And cardCount(SEVEN) > 0 And cardCount(SIX) > 0 Then
highCardUsed = TEN
End If
If cardCount(JACK) > 0 And cardCount(TEN) > 0 And cardCount(NINE) > 0 And cardCount(EIGHT) > 0 And cardCount(SEVEN) > 0 Then
highCardUsed = JACK
End If
If cardCount(QUEEN) > 0 And cardCount(JACK) > 0 And cardCount(TEN) > 0 And cardCount(NINE) > 0 And cardCount(EIGHT) > 0 Then
highCardUsed = QUEEN
End If
If cardCount(KING) > 0 And cardCount(QUEEN) > 0 And cardCount(JACK) > 0 And cardCount(TEN) > 0 And cardCount(NINE) > 0 Then
highCardUsed = KING
End If
If cardCount(ACE) > 0 And cardCount(KING) > 0 And cardCount(QUEEN) > 0 And cardCount(JACK) > 0 And cardCount(TEN) > 0 Then
highCardUsed = ACE
End If
If highCardUsed > -1 Then
'If Not gotStraight Then
'Console.WriteLine("Got Straight")
'gotStraight = True
'End If
handValue(playerIndex) = (HANDTYPE * STRAIGHT) + (FIRSTKICKER * HIGHCARD)
Return True
End If
Return False
End Function
Private Function isThereTrips(playerIndex As Short) As Boolean
loadCardCount(playerIndex)
highTrips = -1
kicker1 = -1
kicker2 = -1
For i As Short = 12 To 0 Step -1
If cardCount(i) = 3 Then
highTrips = i
Exit For
End If
Next
If highTrips > -1 Then
For i As Short = 12 To 0 Step -1
If i <> highTrips Then
If cardCount(i) > 0 Then
If kicker1 = 0 Then
kicker1 = i
Else
kicker2 = i
handValue(playerIndex) = (HANDTYPE * TRIPS) + (FIRSTKICKER * highTrips) + _
(SECONDKICKER * kicker1) + (THIRDKICKER * kicker2)
'If Not gotTrips Then
'Console.WriteLine("Got trips")
'gotTrips = True
'end If
Return True
End If
End If
End If
Next
End If
Return False
End Function
Private Function isThereTwoPairs(playerIndex As Short) As Boolean
loadCardCount(playerIndex)
highPair = -1
lowPair = -1
kicker1 = -1
For i As Short = 12 To 0 Step -1
If cardCount(i) = 2 Then
highPair = i
Exit For
End If
Next
If highPair > -1 Then
For i = 12 To 0 Step -1
If i <> highPair Then
If cardCount(i) = 2 Then
lowPair = i
Exit For
End If
End If
Next
End If
If highPair > -1 And lowPair > -1 Then
For i = 12 To 0 Step -1
If i <> highPair And i <> lowPair Then
If cardCount(i) > 0 Then
kicker1 = i
handValue(playerIndex) = (HANDTYPE * TWOPAIR) + (FIRSTKICKER * highPair) + (SECONDKICKER * lowPair) + _
(THIRDKICKER * kicker1)
'If Not gotTwoPair Then
' Console.WriteLine("Got 2 pair")
'gotTwoPair = True
'End If
Return True
End If
End If
Next
End If
Return False
End Function
Private Function isThereAPair(playerIndex As Short) As Boolean
loadCardCount(playerIndex)
pair = -1
kicker1 = -1
kicker2 = -1
kicker3 = -1
For i As Short = 12 To 0 Step -1
If cardCount(i) = 2 Then
pair = i
Exit For
End If
Next
If pair > -1 Then
For i = 12 To 0 Step -1
If i <> pair Then
If cardCount(i) > 0 Then
If kicker1 = -1 Then
kicker1 = i
Else
If kicker2 = -1 Then
kicker2 = i
Else
kicker3 = i
handValue(playerIndex) = (HANDTYPE * ONEPAIR) + (FIRSTKICKER * pair) + (SECONDKICKER * kicker1) + _
(THIRDKICKER * kicker2) + (FOURTHKICKER * kicker3)
'If Not gotPair Then
'Console.WriteLine("Got pair")
'gotPair = True
'End If
Return True
End If
End If
End If
End If
Next
End If
Return False
End Function
Private Sub loadCardCount(playerIndex As Short)
ReDim cardCount(12)
For Me.cardIndex = 0 To 6
If handCards(playerIndex, cardIndex) <> -1 Then
cardCount(handCards(playerIndex, cardIndex) \ 4) = cardCount(handCards(playerIndex, cardIndex) \ 4) + 1
End If
Next
End Sub
Private Sub sortCards()
For i As Short = 0 To 5
For i2 As Short = 0 To 5
Dim i3 As Short = i2 + 1
If sortedCards(i2) < sortedCards(i3) Then
holdCard = sortedCards(i2)
sortedCards(i2) = sortedCards(i3)
sortedCards(i3) = holdCard
End If
Next
Next
End Sub
Private Sub populateGrids()
unsuitedHands.Rows.Clear()
suitedHands.Rows.Clear()
row = 0
For i = 0 To 1212
If unsuitedHandsDealt(i) > 0 Then
card1 = i \ 100
card2 = i - (card1 * 100)
unsuitedHands.Rows.Add()
unsuitedHands.Rows.Item(row).Cells(0).Value = cardRank(card1) + cardRank(card2)
unsuitedHands.Rows.Item(row).Cells(1).Value = unsuitedHandsDealt(i)
unsuitedHands.Rows.Item(row).Cells(2).Value = unsuitedHandsWon(i)
unsuitedHands.Rows.Item(row).Cells(3).Value = (unsuitedHandsWon(i) / unsuitedHandsDealt(i)) * 100
row = row + 1
End If
Next
row = 0
For i = 0 To 1212
If suitedHandsDealt(i) > 0 Then
card1 = i \ 100
card2 = i - (card1 * 100)
suitedHands.Rows.Add()
suitedHands.Rows.Item(row).Cells(0).Value = cardRank(card1) + cardRank(card2)
suitedHands.Rows.Item(row).Cells(1).Value = suitedHandsDealt(i)
suitedHands.Rows.Item(row).Cells(2).Value = suitedHandsWon(i)
suitedHands.Rows.Item(row).Cells(3).Value = (suitedHandsWon(i) / suitedHandsDealt(i)) * 100
row = row + 1
End If
Next
sw.Stop()
ts = sw.Elapsed
elapsedTime = String.Format("{0:00}:{1:00}:{2:00}.{3:00}", ts.Hours, ts.Minutes, ts.Seconds, ts.Milliseconds / 10)
runTime.Text = "Run Time " + elapsedTime
runTime.Visible = True
handsPlayed.Text = String.Format("Hands played is {0:#,#}", handCounter)
handsPlayed.Visible = True
End Sub
Public Sub doneWithRun()
running = False
populateGrids()
runStop.Text = "Run"
End Sub
Public Sub showTimeAndCount()
ts = sw.Elapsed
elapsedTime = String.Format("{0:00}:{1:00}:{2:00}.{3:00}", ts.Hours, ts.Minutes, ts.Seconds, ts.Milliseconds / 10)
runTime.Text = "Run Time " + elapsedTime
runTime.Visible = True
handsPlayed.Text = String.Format("Hands played is {0:#,#}", handCounter)
handsPlayed.Visible = True
End Sub
End Class
dealHands.Designer.vb
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Partial Class dealHands
Inherits System.Windows.Forms.Form
'Form overrides dispose to clean up the component list.
<System.Diagnostics.DebuggerNonUserCode()> _
Protected Overrides Sub Dispose(ByVal disposing As Boolean)
Try
If disposing AndAlso components IsNot Nothing Then
components.Dispose()
End If
Finally
MyBase.Dispose(disposing)
End Try
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
<System.Diagnostics.DebuggerStepThrough()> _
Private Sub InitializeComponent()
Dim DataGridViewCellStyle1 As System.Windows.Forms.DataGridViewCellStyle = New System.Windows.Forms.DataGridViewCellStyle()
Dim DataGridViewCellStyle2 As System.Windows.Forms.DataGridViewCellStyle = New System.Windows.Forms.DataGridViewCellStyle()
Dim DataGridViewCellStyle3 As System.Windows.Forms.DataGridViewCellStyle = New System.Windows.Forms.DataGridViewCellStyle()
Dim DataGridViewCellStyle4 As System.Windows.Forms.DataGridViewCellStyle = New System.Windows.Forms.DataGridViewCellStyle()
Dim DataGridViewCellStyle5 As System.Windows.Forms.DataGridViewCellStyle = New System.Windows.Forms.DataGridViewCellStyle()
Dim DataGridViewCellStyle6 As System.Windows.Forms.DataGridViewCellStyle = New System.Windows.Forms.DataGridViewCellStyle()
Dim DataGridViewCellStyle7 As System.Windows.Forms.DataGridViewCellStyle = New System.Windows.Forms.DataGridViewCellStyle()
Dim DataGridViewCellStyle8 As System.Windows.Forms.DataGridViewCellStyle = New System.Windows.Forms.DataGridViewCellStyle()
Me.Label1 = New System.Windows.Forms.Label()
Me.playersPerHand = New System.Windows.Forms.TextBox()
Me.Label2 = New System.Windows.Forms.Label()
Me.handsToPlay = New System.Windows.Forms.TextBox()
Me.runStop = New System.Windows.Forms.Button()
Me.suitedHands = New System.Windows.Forms.DataGridView()
Me.suitedHand = New System.Windows.Forms.DataGridViewTextBoxColumn()
Me.suitedTimesDealt = New System.Windows.Forms.DataGridViewTextBoxColumn()
Me.suitedTimesWon = New System.Windows.Forms.DataGridViewTextBoxColumn()
Me.suitedWinPct = New System.Windows.Forms.DataGridViewTextBoxColumn()
Me.unsuitedHands = New System.Windows.Forms.DataGridView()
Me.unsuitedHand = New System.Windows.Forms.DataGridViewTextBoxColumn()
Me.unsuitedTimesDealt = New System.Windows.Forms.DataGridViewTextBoxColumn()
Me.unsuitedTimesWon = New System.Windows.Forms.DataGridViewTextBoxColumn()
Me.unsuitedWinPct = New System.Windows.Forms.DataGridViewTextBoxColumn()
Me.Label3 = New System.Windows.Forms.Label()
Me.Label4 = New System.Windows.Forms.Label()
Me.runTime = New System.Windows.Forms.Label()
Me.handsPlayed = New System.Windows.Forms.Label()
CType(Me.suitedHands, System.ComponentModel.ISupportInitialize).BeginInit()
CType(Me.unsuitedHands, System.ComponentModel.ISupportInitialize).BeginInit()
Me.SuspendLayout()
'
'Label1
'
Me.Label1.AutoSize = True
Me.Label1.Location = New System.Drawing.Point(23, 23)
Me.Label1.Name = "Label1"
Me.Label1.Size = New System.Drawing.Size(89, 13)
Me.Label1.TabIndex = 0
Me.Label1.Text = "Players Per Hand"
'
'playersPerHand
'
Me.playersPerHand.Location = New System.Drawing.Point(193, 19)
Me.playersPerHand.MaxLength = 2
Me.playersPerHand.Name = "playersPerHand"
Me.playersPerHand.Size = New System.Drawing.Size(25, 20)
Me.playersPerHand.TabIndex = 1
Me.playersPerHand.Text = "10"
Me.playersPerHand.TextAlign = System.Windows.Forms.HorizontalAlignment.Right
'
'Label2
'
Me.Label2.AutoSize = True
Me.Label2.Location = New System.Drawing.Point(23, 49)
Me.Label2.Name = "Label2"
Me.Label2.Size = New System.Drawing.Size(77, 13)
Me.Label2.TabIndex = 2
Me.Label2.Text = "Hands To Play"
'
'handsToPlay
'
Me.handsToPlay.Location = New System.Drawing.Point(118, 45)
Me.handsToPlay.MaxLength = 11
Me.handsToPlay.Name = "handsToPlay"
Me.handsToPlay.Size = New System.Drawing.Size(100, 20)
Me.handsToPlay.TabIndex = 3
Me.handsToPlay.Text = "10000000"
Me.handsToPlay.TextAlign = System.Windows.Forms.HorizontalAlignment.Right
'
'runStop
'
Me.runStop.BackColor = System.Drawing.SystemColors.Control
Me.runStop.Font = New System.Drawing.Font("Arial", 12.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.runStop.Location = New System.Drawing.Point(275, 19)
Me.runStop.Name = "runStop"
Me.runStop.Size = New System.Drawing.Size(138, 43)
Me.runStop.TabIndex = 4
Me.runStop.Text = "Run"
Me.runStop.UseVisualStyleBackColor = False
'
'suitedHands
'
Me.suitedHands.AllowUserToAddRows = False
Me.suitedHands.AllowUserToDeleteRows = False
Me.suitedHands.AllowUserToOrderColumns = True
Me.suitedHands.AllowUserToResizeColumns = False
Me.suitedHands.AllowUserToResizeRows = False
Me.suitedHands.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize
Me.suitedHands.Columns.AddRange(New System.Windows.Forms.DataGridViewColumn() {Me.suitedHand, Me.suitedTimesDealt, Me.suitedTimesWon, Me.suitedWinPct})
Me.suitedHands.EditMode = System.Windows.Forms.DataGridViewEditMode.EditProgrammatically
Me.suitedHands.Location = New System.Drawing.Point(20, 104)
Me.suitedHands.Name = "suitedHands"
Me.suitedHands.ReadOnly = True
Me.suitedHands.Size = New System.Drawing.Size(354, 375)
Me.suitedHands.TabIndex = 5
'
'suitedHand
'
Me.suitedHand.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.AllCells
DataGridViewCellStyle1.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleLeft
DataGridViewCellStyle1.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
DataGridViewCellStyle1.NullValue = Nothing
Me.suitedHand.DefaultCellStyle = DataGridViewCellStyle1
Me.suitedHand.HeaderText = "Hand"
Me.suitedHand.MaxInputLength = 2
Me.suitedHand.Name = "suitedHand"
Me.suitedHand.ReadOnly = True
Me.suitedHand.Resizable = System.Windows.Forms.DataGridViewTriState.[False]
Me.suitedHand.Width = 58
'
'suitedTimesDealt
'
Me.suitedTimesDealt.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.AllCells
DataGridViewCellStyle2.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleRight
DataGridViewCellStyle2.Format = "N0"
DataGridViewCellStyle2.NullValue = Nothing
Me.suitedTimesDealt.DefaultCellStyle = DataGridViewCellStyle2
Me.suitedTimesDealt.HeaderText = "Times Dealt"
Me.suitedTimesDealt.Name = "suitedTimesDealt"
Me.suitedTimesDealt.ReadOnly = True
Me.suitedTimesDealt.Width = 88
'
'suitedTimesWon
'
Me.suitedTimesWon.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.AllCells
DataGridViewCellStyle3.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleRight
DataGridViewCellStyle3.Format = "N0"
DataGridViewCellStyle3.NullValue = Nothing
Me.suitedTimesWon.DefaultCellStyle = DataGridViewCellStyle3
Me.suitedTimesWon.HeaderText = "Times Won"
Me.suitedTimesWon.Name = "suitedTimesWon"
Me.suitedTimesWon.ReadOnly = True
Me.suitedTimesWon.Width = 86
'
'suitedWinPct
'
Me.suitedWinPct.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.AllCells
DataGridViewCellStyle4.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleRight
DataGridViewCellStyle4.Format = "N2"
DataGridViewCellStyle4.NullValue = Nothing
Me.suitedWinPct.DefaultCellStyle = DataGridViewCellStyle4
Me.suitedWinPct.HeaderText = "Win %"
Me.suitedWinPct.MaxInputLength = 6
Me.suitedWinPct.Name = "suitedWinPct"
Me.suitedWinPct.ReadOnly = True
Me.suitedWinPct.Width = 62
'
'unsuitedHands
'
Me.unsuitedHands.AllowUserToAddRows = False
Me.unsuitedHands.AllowUserToDeleteRows = False
Me.unsuitedHands.AllowUserToResizeColumns = False
Me.unsuitedHands.AllowUserToResizeRows = False
Me.unsuitedHands.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize
Me.unsuitedHands.Columns.AddRange(New System.Windows.Forms.DataGridViewColumn() {Me.unsuitedHand, Me.unsuitedTimesDealt, Me.unsuitedTimesWon, Me.unsuitedWinPct})
Me.unsuitedHands.EditMode = System.Windows.Forms.DataGridViewEditMode.EditProgrammatically
Me.unsuitedHands.Location = New System.Drawing.Point(398, 104)
Me.unsuitedHands.Name = "unsuitedHands"
Me.unsuitedHands.ReadOnly = True
Me.unsuitedHands.Size = New System.Drawing.Size(354, 375)
Me.unsuitedHands.TabIndex = 6
'
'unsuitedHand
'
Me.unsuitedHand.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.AllCells
DataGridViewCellStyle5.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleLeft
DataGridViewCellStyle5.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.unsuitedHand.DefaultCellStyle = DataGridViewCellStyle5
Me.unsuitedHand.HeaderText = "Hand"
Me.unsuitedHand.MaxInputLength = 2
Me.unsuitedHand.Name = "unsuitedHand"
Me.unsuitedHand.ReadOnly = True
Me.unsuitedHand.Resizable = System.Windows.Forms.DataGridViewTriState.[False]
Me.unsuitedHand.Width = 58
'
'unsuitedTimesDealt
'
Me.unsuitedTimesDealt.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.AllCells
DataGridViewCellStyle6.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleRight
DataGridViewCellStyle6.Format = "N0"
DataGridViewCellStyle6.NullValue = Nothing
Me.unsuitedTimesDealt.DefaultCellStyle = DataGridViewCellStyle6
Me.unsuitedTimesDealt.HeaderText = "Times Dealt"
Me.unsuitedTimesDealt.MaxInputLength = 11
Me.unsuitedTimesDealt.Name = "unsuitedTimesDealt"
Me.unsuitedTimesDealt.ReadOnly = True
Me.unsuitedTimesDealt.Resizable = System.Windows.Forms.DataGridViewTriState.[False]
Me.unsuitedTimesDealt.Width = 88
'
'unsuitedTimesWon
'
Me.unsuitedTimesWon.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.AllCells
DataGridViewCellStyle7.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleRight
DataGridViewCellStyle7.Format = "N0"
DataGridViewCellStyle7.NullValue = Nothing
Me.unsuitedTimesWon.DefaultCellStyle = DataGridViewCellStyle7
Me.unsuitedTimesWon.HeaderText = "Times Won"
Me.unsuitedTimesWon.MaxInputLength = 11
Me.unsuitedTimesWon.Name = "unsuitedTimesWon"
Me.unsuitedTimesWon.ReadOnly = True
Me.unsuitedTimesWon.Resizable = System.Windows.Forms.DataGridViewTriState.[False]
Me.unsuitedTimesWon.Width = 86
'
'unsuitedWinPct
'
Me.unsuitedWinPct.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.AllCells
DataGridViewCellStyle8.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleRight
DataGridViewCellStyle8.Format = "N2"
DataGridViewCellStyle8.NullValue = Nothing
Me.unsuitedWinPct.DefaultCellStyle = DataGridViewCellStyle8
Me.unsuitedWinPct.HeaderText = "Win %"
Me.unsuitedWinPct.MaxInputLength = 6
Me.unsuitedWinPct.Name = "unsuitedWinPct"
Me.unsuitedWinPct.ReadOnly = True
Me.unsuitedWinPct.Resizable = System.Windows.Forms.DataGridViewTriState.[False]
Me.unsuitedWinPct.Width = 62
'
'Label3
'
Me.Label3.AutoSize = True
Me.Label3.Font = New System.Drawing.Font("Arial", 11.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.Label3.Location = New System.Drawing.Point(146, 83)
Me.Label3.Name = "Label3"
Me.Label3.Size = New System.Drawing.Size(103, 18)
Me.Label3.TabIndex = 7
Me.Label3.Text = "Suited Hands"
'
'Label4
'
Me.Label4.AutoSize = True
Me.Label4.Font = New System.Drawing.Font("Arial", 11.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.Label4.Location = New System.Drawing.Point(515, 83)
Me.Label4.Name = "Label4"
Me.Label4.Size = New System.Drawing.Size(121, 18)
Me.Label4.TabIndex = 8
Me.Label4.Text = "Unsuited Hands"
'
'runTime
'
Me.runTime.AutoSize = True
Me.runTime.Location = New System.Drawing.Point(482, 19)
Me.runTime.Name = "runTime"
Me.runTime.Size = New System.Drawing.Size(45, 13)
Me.runTime.TabIndex = 9
Me.runTime.Text = "runTime"
Me.runTime.Visible = False
'
'handsPlayed
'
Me.handsPlayed.AutoSize = True
Me.handsPlayed.Location = New System.Drawing.Point(482, 49)
Me.handsPlayed.Name = "handsPlayed"
Me.handsPlayed.Size = New System.Drawing.Size(68, 13)
Me.handsPlayed.TabIndex = 10
Me.handsPlayed.Text = "handsPlayed"
Me.handsPlayed.Visible = False
'
'dealHands
'
Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
Me.AutoScroll = True
Me.BackColor = System.Drawing.SystemColors.ControlLightLight
Me.ClientSize = New System.Drawing.Size(775, 499)
Me.Controls.Add(Me.handsPlayed)
Me.Controls.Add(Me.runTime)
Me.Controls.Add(Me.Label4)
Me.Controls.Add(Me.Label3)
Me.Controls.Add(Me.unsuitedHands)
Me.Controls.Add(Me.suitedHands)
Me.Controls.Add(Me.runStop)
Me.Controls.Add(Me.handsToPlay)
Me.Controls.Add(Me.Label2)
Me.Controls.Add(Me.playersPerHand)
Me.Controls.Add(Me.Label1)
Me.Name = "dealHands"
Me.Text = "Texas Holdem Hand Calculator"
CType(Me.suitedHands, System.ComponentModel.ISupportInitialize).EndInit()
CType(Me.unsuitedHands, System.ComponentModel.ISupportInitialize).EndInit()
Me.ResumeLayout(False)
Me.PerformLayout()
End Sub
Friend WithEvents Label1 As System.Windows.Forms.Label
Friend WithEvents playersPerHand As System.Windows.Forms.TextBox
Friend WithEvents Label2 As System.Windows.Forms.Label
Friend WithEvents handsToPlay As System.Windows.Forms.TextBox
Friend WithEvents runStop As System.Windows.Forms.Button
Friend WithEvents suitedHands As System.Windows.Forms.DataGridView
Friend WithEvents unsuitedHands As System.Windows.Forms.DataGridView
Friend WithEvents Label3 As System.Windows.Forms.Label
Friend WithEvents Label4 As System.Windows.Forms.Label
Friend WithEvents hand As System.Windows.Forms.DataGridViewTextBoxColumn
Friend WithEvents winPct As System.Windows.Forms.DataGridViewTextBoxColumn
Friend WithEvents unsuitedHand As System.Windows.Forms.DataGridViewTextBoxColumn
Friend WithEvents unsuitedTimesDealt As System.Windows.Forms.DataGridViewTextBoxColumn
Friend WithEvents unsuitedTimesWon As System.Windows.Forms.DataGridViewTextBoxColumn
Friend WithEvents unsuitedWinPct As System.Windows.Forms.DataGridViewTextBoxColumn
Friend WithEvents suitedHand As System.Windows.Forms.DataGridViewTextBoxColumn
Friend WithEvents suitedTimesDealt As System.Windows.Forms.DataGridViewTextBoxColumn
Friend WithEvents suitedTimesWon As System.Windows.Forms.DataGridViewTextBoxColumn
Friend WithEvents suitedWinPct As System.Windows.Forms.DataGridViewTextBoxColumn
Friend WithEvents runTime As System.Windows.Forms.Label
Friend WithEvents handsPlayed As System.Windows.Forms.Label
End Class