Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Public Structure Card
- Dim Name As String
- Dim Suit As String
- Dim Number As Integer
- Dim Available As Boolean
- Dim filePath As String
- End Structure
- Public Class GameForm
- Dim Deck(51) As Card
- Dim players(3) As Player
- Dim pot As Integer = 0
- Dim handNum As Integer = 1
- Dim playerTurn As Integer = 1
- Dim currentTurn As Integer
- Dim moneyEntered(3, 3) As Integer
- Dim potTotal As Integer
- Dim flopPlayed As Boolean = False
- Dim turnPlayed As Boolean = False
- Dim riverPlayed As Boolean = False
- Dim progression As Integer
- Dim isChecked = False
- Dim foldCount As Integer = 0
- Dim checkCount As Integer = 0
- Dim lastBetter As Integer
- Dim handOverBool As Boolean = False
- Dim conn As New System.Data.Odbc.OdbcConnection("DRIVER={MySQL ODBC 5.3 ANSI Driver};SERVER=localhost;PORT=3306;DATABASE=handdatabase;USER=root;PASSWORD=root;OPTION=3;")
- Dim rs As Odbc.OdbcDataReader
- Private Sub GameForm_Load(sender As Object, e As EventArgs) Handles MyBase.Load
- For i = 0 To 3
- players(i) = New Player
- Next
- WelcomeForm.Show()
- Dim humanHand(6) As Card
- Dim AI1Hand(6) As Card
- Dim AI2Hand(6) As Card
- Dim AI3Hand(6) As Card
- 'players(0).Name = "Mason"
- players(1).Name = "AI1"
- players(2).Name = "AI2"
- players(3).Name = "AI3"
- players(0).hand = humanHand
- players(1).hand = AI1Hand
- players(2).hand = AI2Hand
- players(3).hand = AI3Hand
- For i = 0 To 3
- players(i).Money = 100
- Next
- blankCards()
- Me.BackgroundImage = Image.FromFile("table.png")
- PotN.Text = "Pot: " & pot
- refreshMoney()
- initializeDeck()
- End Sub
- Sub refreshMoney()
- If players(0).Money < 0 Then
- humanMoney.Text = "0"
- Else
- humanMoney.Text = "Money: " & players(0).Money
- End If
- If players(1).Money < 0 Then
- AI1Money.Text = "0"
- Else
- AI1Money.Text = "Money: " & players(1).Money
- End If
- If players(2).Money < 0 Then
- AI2Money.Text = "0"
- Else
- AI2Money.Text = "Money: " & players(2).Money
- End If
- If players(3).Money < 0 Then
- AI3Money.Text = "0"
- Else
- AI3Money.Text = "Money: " & players(3).Money
- End If
- humanMoney.Refresh()
- AI1Money.Refresh()
- AI2Money.Refresh()
- AI3Money.Refresh()
- End Sub
- Private Sub GameForm_Shown(sender As Object, e As EventArgs) Handles Me.Shown
- HandTableForm.Hide()
- Me.Hide()
- WelcomeForm.Show()
- End Sub
- Sub blankCards()
- Com1.Image = Image.FromFile("blank_card.png")
- Com2.Image = Image.FromFile("blank_card.png")
- Com3.Image = Image.FromFile("blank_card.png")
- Com4.Image = Image.FromFile("blank_card.png")
- Com5.Image = Image.FromFile("blank_card.png")
- HoleCard1.Image = Image.FromFile("blank_card.png")
- HoleCard2.Image = Image.FromFile("blank_card.png")
- AI1Card1.Image = Image.FromFile("blank_card.png")
- AI1Card2.Image = Image.FromFile("blank_card.png")
- AI2Card1.Image = Image.FromFile("blank_card.png")
- AI2Card2.Image = Image.FromFile("blank_card.png")
- AI3Card1.Image = Image.FromFile("blank_card.png")
- AI3Card2.Image = Image.FromFile("blank_card.png")
- End Sub
- Sub Deal()
- handOverBool = False
- DealButton.Enabled = False
- foldCount = 0
- checkCount = 0
- potTotal = 0
- currentTurn = playerTurn
- blankCards()
- flopPlayed = False
- turnPlayed = False
- riverPlayed = False
- progression = 0
- For i = 0 To 3
- For j = 0 To 3
- moneyEntered(i, j) = 0
- Next
- players(i).hasFolded = False
- Next
- resetActions()
- HandName.Text = ""
- If players(0).Money = 0 Then
- For i = 0 To 3
- players(i).Money = 100
- refreshMoney()
- Next
- End If
- For i = 0 To 3
- players(i).currentHand = ""
- For j = 0 To 6
- players(i).hand(j).Name = ""
- players(i).hand(j).Number = 0
- players(i).hand(j).Suit = ""
- Next
- Next
- For i = 0 To 51
- Deck(i).Available = True
- Next
- Randomize()
- Dim randomNums(7) As Integer
- For i = 0 To 7
- randomNums(i) = CInt(Math.Floor((51) * Rnd()))
- If Deck(randomNums(i)).Available = False Then
- Do
- randomNums(i) = CInt(Math.Floor((51) * Rnd()))
- Loop Until Deck(randomNums(i)).Available = True
- End If
- Deck(randomNums(i)).Available = False
- Next
- Dim count = 0
- For i = 0 To 7
- players(count).hand(i Mod 2) = Deck(randomNums(i))
- If i Mod 2 = 1 And i <> 0 Then
- count += 1
- End If
- Next
- HoleCard1.Image = Image.FromFile(players(0).hand(0).filePath)
- HoleCard1.Refresh()
- HoleCard2.Image = Image.FromFile(players(0).hand(1).filePath)
- HoleCard2.Refresh()
- 'AI1Card1.Image = Image.FromFile(players(1).hand(0).filePath)
- 'AI1Card2.Image = Image.FromFile(players(1).hand(1).filePath)
- 'AI2Card1.Image = Image.FromFile(players(2).hand(0).filePath)
- 'AI2Card2.Image = Image.FromFile(players(2).hand(1).filePath)
- 'AI3Card1.Image = Image.FromFile(players(3).hand(0).filePath)
- 'AI3Card2.Image = Image.FromFile(players(3).hand(1).filePath)
- Refresh()
- 'Try
- 'Catch
- 'End Try
- Dim roundCount As Integer = 0
- BettingRound(roundCount)
- End Sub
- Sub resetActions()
- AI1Action.Text = ""
- AI2Action.Text = ""
- AI3Action.Text = ""
- HumanAction.Text = ""
- End Sub
- Sub Flop()
- resetActions()
- checkCount = 0
- For i = 0 To 3
- potTotal += moneyEntered(i, 0)
- Next
- PotN.Text = "Pot: " & potTotal
- PotN.Refresh()
- currentTurn = playerTurn
- Dim randomNums(2) As Integer
- isChecked = True
- For i = 0 To 3
- If players(i).Money = 0 Then
- players(i).hasFolded = True
- checkFoldedCards()
- End If
- Next
- For i = 0 To 2
- randomNums(i) = CInt(Math.Floor((51) * Rnd()))
- If Deck(randomNums(i)).Available = False Then
- Do
- randomNums(i) = CInt(Math.Floor((51) * Rnd()))
- Loop Until Deck(randomNums(i)).Available = True
- End If
- Deck(randomNums(i)).Available = False
- For j = 0 To 3
- players(j).hand(i + 2) = Deck(randomNums(i))
- Next
- Next
- Com1.Image = Image.FromFile(Deck(randomNums(0)).filePath)
- Com2.Image = Image.FromFile(Deck(randomNums(1)).filePath)
- Com3.Image = Image.FromFile(Deck(randomNums(2)).filePath)
- Com1.Refresh()
- Com2.Refresh()
- Com3.Refresh()
- For i = 0 To 3
- players(i).currentHand = CheckHand(players(i).hand)
- Next
- HandName.Text = "Hand: " & players(0).currentHand
- HandName.Refresh()
- flopPlayed = True
- Dim roundCount As Integer = 0
- BettingRound(roundCount)
- End Sub
- Sub Turn()
- resetActions()
- checkCount = 0
- isChecked = True
- For i = 0 To 3
- potTotal += moneyEntered(i, 1)
- Next
- PotN.Text = "Pot: " & potTotal
- PotN.Refresh()
- currentTurn = playerTurn
- For i = 0 To 3
- If players(i).Money = 0 Then
- players(i).hasFolded = True
- checkFoldedCards()
- End If
- Next
- Dim randomNum As Integer = CInt(Math.Floor((51) * Rnd()))
- If Deck(randomNum).Available = False Then
- Do
- Randomize()
- randomNum = CInt(Math.Floor((51) * Rnd()))
- Loop Until Deck(randomNum).Available = True
- End If
- Deck(randomNum).Available = False
- For i = 0 To 3
- players(i).hand(5) = Deck(randomNum)
- Next
- Com4.Image = Image.FromFile(Deck(randomNum).filePath)
- Com4.Refresh()
- For i = 0 To 3
- players(i).currentHand = CheckHand(players(i).hand)
- Next
- HandName.Text = "Hand: " & players(0).currentHand
- HandName.Refresh()
- turnPlayed = True
- Dim roundCount As Integer = 0
- BettingRound(roundCount)
- End Sub
- Sub River()
- currentTurn = playerTurn
- resetActions()
- checkCount = 0
- isChecked = True
- For i = 0 To 3
- potTotal += moneyEntered(i, 2)
- Next
- PotN.Text = "Pot: " & potTotal
- PotN.Refresh()
- For i = 0 To 3
- If players(i).Money = 0 Then
- players(i).hasFolded = True
- checkFoldedCards()
- End If
- Next
- Dim randomNum As Integer = CInt(Math.Floor((51) * Rnd()))
- If Deck(randomNum).Available = False Then
- Do
- Randomize()
- randomNum = CInt(Math.Floor((51) * Rnd()))
- Loop Until Deck(randomNum).Available = True
- End If
- Deck(randomNum).Available = False
- For i = 0 To 3
- players(i).hand(6) = Deck(randomNum)
- Next
- Com5.Image = Image.FromFile(Deck(randomNum).filePath)
- Com5.Refresh()
- 'For i = 0 To 3
- ' For j = 0 To 6
- ' MsgBox(players(i).hand(j).Name)
- ' Next
- 'Next
- For i = 0 To 3
- players(i).currentHand = CheckHand(players(i).hand)
- Next
- HandName.Text = "Hand: " & players(0).currentHand
- HandName.Refresh()
- riverPlayed = True
- Dim roundCount As Integer = 0
- BettingRound(roundCount)
- End Sub
- Sub handOverSub()
- handOverBool = True
- 'MsgBox("handOver")
- For i = 0 To 3
- potTotal += moneyEntered(i, progression)
- Next
- PotN.Text = "Pot: " & potTotal
- PotN.Refresh()
- If players(1).hasFolded = False Then
- AI1Card1.Image = Image.FromFile(players(1).hand(0).filePath)
- AI1Card2.Image = Image.FromFile(players(1).hand(1).filePath)
- End If
- If players(2).hasFolded = False Then
- AI2Card1.Image = Image.FromFile(players(2).hand(0).filePath)
- AI2Card2.Image = Image.FromFile(players(2).hand(1).filePath)
- End If
- If players(3).hasFolded = False Then
- AI3Card1.Image = Image.FromFile(players(3).hand(0).filePath)
- AI3Card2.Image = Image.FromFile(players(3).hand(1).filePath)
- End If
- Dim handArray(3) As String
- Dim handArrayNum(3) As Integer
- Dim handArrayNumSorted(3) As Integer
- For i = 0 To 3
- If players(i).hasFolded = False Then
- handArray(i) = players(i).currentHand
- End If
- Next
- For i = 0 To 3
- Select Case handArray(i)
- Case ""
- handArrayNum(i) = 0
- Case "Pair"
- handArrayNum(i) = 1
- Case "Two Pair"
- handArrayNum(i) = 2
- Case "Three Of A Kind"
- handArrayNum(i) = 3
- Case "Straight"
- handArrayNum(i) = 4
- Case "Flush"
- handArrayNum(i) = 5
- Case "Full House"
- handArrayNum(i) = 6
- Case "Four Of A Kind"
- handArrayNum(i) = 6
- End Select
- Next
- For i = 0 To 3
- handArrayNumSorted(i) = handArrayNum(i)
- Next
- For i = 0 To 3
- For j = 0 To 2
- Dim temp As Integer = handArrayNumSorted(j)
- If handArrayNumSorted(j) < handArrayNumSorted(j + 1) Then
- handArrayNumSorted(j) = handArrayNumSorted(j + 1)
- handArrayNumSorted(j + 1) = temp
- End If
- Next
- Next
- Dim winningHand As Integer = handArrayNumSorted(0)
- Dim numOfWinners As Integer = 0
- For i = 0 To 3
- If handArrayNum(i) = winningHand And players(i).hasFolded = False Then
- If i = 0 Then
- MessageBox.Show("You have won the hand!", "Congratulations!")
- Else
- MessageBox.Show("Player " & i & " has won the hand!", "Hand Over")
- End If
- numOfWinners += 1
- End If
- Next
- For i = 0 To 3
- If handArrayNum(i) = winningHand And players(i).hasFolded = False Then
- players(i).Money += Math.Floor(potTotal / numOfWinners)
- End If
- Next
- refreshMoney()
- Dim sqlString As New Odbc.OdbcCommand("SELECT HandNumber FROM handtable ORDER BY HandNumber DESC LIMIT 1", conn)
- conn.Open()
- rs = sqlString.ExecuteReader()
- Do While rs.Read()
- handNum = rs.Item("HandNumber") + 1
- Loop
- 'MsgBox(handNum)
- conn.Close()
- Dim humanMoneyEntered As Integer = 0
- Dim handWon As Boolean
- Dim moneyWon As Integer
- Dim percentage As Double
- For i = 0 To 3
- humanMoneyEntered += moneyEntered(0, i)
- Next
- If handArrayNum(0) = winningHand Then
- handWon = True
- moneyWon = Math.Floor(potTotal / numOfWinners)
- percentage = (moneyWon / humanMoneyEntered) * 100
- Else
- moneyWon = 0
- End If
- Dim cardString As String
- For i = 0 To 6
- If players(0).hand(i).Number < 11 Then
- cardString = cardString & UCase(Mid(players(0).hand(i).Number.ToString, 1, 1)) & LCase(Mid(players(0).hand(i).Suit, 1, 1))
- Else
- Select Case players(0).hand(i).Number
- Case 11
- cardString = cardString & "J" & LCase(Mid(players(0).hand(i).Suit, 1, 1))
- Case 12
- cardString = cardString & "Q" & LCase(Mid(players(0).hand(i).Suit, 1, 1))
- Case 13
- cardString = cardString & "K" & LCase(Mid(players(0).hand(i).Suit, 1, 1))
- End Select
- End If
- Next
- 'MsgBox(cardString)
- Dim sqlString2 As New Odbc.OdbcCommand("INSERT INTO HandTable VALUES('" & handNum & "','" & cardString & "','" & players(0).currentHand & "', '" & handWon & "', '" & humanMoneyEntered & "', '" & potTotal & "', '" & moneyWon & "', '" & percentage & "')", conn)
- conn.Open()
- rs = sqlString2.ExecuteReader()
- conn.Close()
- blankCards()
- HandName.Text = ""
- HandName.Refresh()
- PotN.Text = ""
- PotN.Refresh()
- playerTurn += 1
- If playerTurn = 4 Then
- playerTurn = 0
- End If
- For i = 0 To 3
- actionChanger(i, "")
- Next
- DealButton.Enabled = True
- End Sub
- Sub checkFoldedCards()
- If players(0).hasFolded = True Then
- HoleCard1.Image = Image.FromFile("folded_card.png")
- HoleCard2.Image = Image.FromFile("folded_card.png")
- HoleCard1.Refresh()
- HoleCard2.Refresh()
- End If
- If players(1).hasFolded = True Then
- AI1Card1.Image = Image.FromFile("folded_card.png")
- AI1Card2.Image = Image.FromFile("folded_card.png")
- AI1Card1.Refresh()
- AI1Card2.Refresh()
- End If
- If players(2).hasFolded = True Then
- AI2Card1.Image = Image.FromFile("folded_card.png")
- AI2Card2.Image = Image.FromFile("folded_card.png")
- AI2Card1.Refresh()
- AI2Card2.Refresh()
- End If
- If players(3).hasFolded = True Then
- AI3Card1.Image = Image.FromFile("folded_card.png")
- AI3Card2.Image = Image.FromFile("folded_card.png")
- AI3Card1.Refresh()
- AI3Card2.Refresh()
- End If
- End Sub
- Function CheckHand(ByVal hand() As Card)
- Dim handName As String
- Dim cardNos(12) As String
- Dim cardSuits(12) As String
- For i = 0 To 6
- cardNos(i) = hand(i).Number.ToString
- Next
- For i = 0 To 6
- If hand(i).Suit <> "" Then
- cardSuits(i) = hand(i).Suit
- End If
- Next
- handName = checkRep(cardNos)
- handName = checkStraight(cardNos, cardSuits, handName)
- handName = checkFlush(cardSuits, handName)
- CheckHand = handName
- 'MsgBox(handName)
- End Function
- Function checkRep(ByVal cardNos() As String)
- Dim count As Integer = 0
- Dim uniqueCards As Integer = 7
- For i = 0 To 6
- For j = 0 To 6
- If cardNos(i) = cardNos(j) And cardNos(i) <> "0" Then
- If i <> j Then
- count += 1
- End If
- End If
- Next
- Next
- For i = 0 To 6
- For j = 0 To 6
- If cardNos(i) = cardNos(j) And i <> j And cardNos(i) <> "0" Then
- 'MsgBox(cardNos(0) & cardNos(1) & cardNos(2) & cardNos(3) & cardNos(4) & cardNos(5) & cardNos(6))
- 'System.Threading.Thread.Sleep(2000)
- uniqueCards -= 1
- For z = j To 6
- cardNos(z) = cardNos(z + 1)
- Next
- End If
- Next
- Next
- 'MsgBox(count & " " & uniqueCards)
- If count = 2 Then
- checkRep = "Pair"
- ElseIf count = 4 Then
- checkRep = "Two Pair"
- ElseIf count = 6 And uniqueCards = 5 Then
- checkRep = "Three Of A Kind"
- ElseIf count = 12 And uniqueCards = 3 Then
- checkRep = "Three Of A Kind"
- ElseIf count = 6 And uniqueCards = 3 Then
- checkRep = "Three Of A Kind"
- ElseIf count = 8 And uniqueCards = -2 Then
- checkRep = "Full House"
- ElseIf count = 6 And uniqueCards = -2 Then
- checkRep = "Two Pair"
- ElseIf count = 6 And uniqueCards = 4 Then
- checkRep = "Two Pair"
- ElseIf count = 8 And uniqueCards = 4 Then
- checkRep = "Full House"
- ElseIf count = 0 Then
- checkRep = ""
- ElseIf count = 12 Then
- checkRep = "Four Of A Kind"
- ElseIf count = 14 And uniqueCards = 3 Then
- checkRep = "Four Of A Kind"
- ElseIf ((count = 18 And uniqueCards = 3) Or (count = 18 And uniqueCards = 2)) Then
- checkRep = "Four Of A Kind"
- End If
- End Function
- Function checkStraight(ByVal cardNos() As String, ByVal cardSuits() As String, ByVal handName As String)
- Dim straightCount As Integer = 0
- Dim isStraight As Boolean = False
- Dim cards(12) As Integer
- For i = 0 To 7
- cards(i) = CInt(cardNos(i))
- Next
- 'MsgBox(cards(0) & ", " & cards(1) & ", " & cards(2) & ", " & cards(3) & ", " & cards(4) & ", " & cards(5) & ", " & cards(6) & ", " & cards(7))
- For i = 1 To 7
- For j = 0 To 7
- If cards(j) > cards(j + 1) Then
- cards(12) = cards(j)
- cards(j) = cards(j + 1)
- cards(j + 1) = cards(12)
- End If
- Next
- Next
- 'MsgBox(cards(0) & ", " & cards(1) & ", " & cards(2) & ", " & cards(3) & ", " & cards(4) & ", " & cards(5) & ", " & cards(6) & ", " & cards(7))
- Dim NumOfZeroes As Integer = 0
- For i = 0 To 11
- If cards(i) = 0 Then
- NumOfZeroes += 1
- ElseIf cards(i) <> 0 Then
- Exit For
- End If
- Next
- For i = 0 To 12 - NumOfZeroes
- cards(i) = cards(i + NumOfZeroes)
- Next
- For j = 0 To 2
- straightCount = 0
- For z = 0 To 4
- If cards(j + z) = cards(j) + z Then
- straightCount += 1
- End If
- If cards(j) = 1 And cards(4 + z) = 13 And cards(3 + z) = 12 And cards(2 + z) = 11 And cards(1 + z) = 10 Then
- isStraight = True
- End If
- Next
- If straightCount = 5 Then
- isStraight = True
- End If
- Next
- If isStraight = True And (handName = "" Or handName = "Pair" Or handName = "Two Pair" Or handName = "Three Of A Kind") Then
- checkStraight = "Straight"
- Else
- checkStraight = handName
- End If
- End Function
- Function checkFlush(ByVal cardSuits() As String, ByVal handName As String)
- Dim spadeCount As Integer = 0
- Dim clubCount As Integer = 0
- Dim diamondCount As Integer = 0
- Dim heartCount As Integer = 0
- For i = 0 To 6
- Select Case cardSuits(i)
- Case "Spades"
- spadeCount += 1
- Case "Clubs"
- clubCount += 1
- Case "Diamonds"
- diamondCount += 1
- Case "Hearts"
- heartCount += 1
- End Select
- Next
- 'MsgBox("Spades: " & spadeCount & " | Clubs: " & clubCount & " | Diamonds: " & diamondCount & " | Hearts: " & heartCount)
- Dim isFlush As Boolean = False
- If (spadeCount = 5 Or clubCount = 5 Or diamondCount = 5 Or heartCount = 5) Then
- isFlush = True
- End If
- If isFlush = True And (handName <> "Full House" Or handName <> "Four Of A Kind") Then
- checkFlush = "Flush"
- Else
- checkFlush = handName
- End If
- End Function
- Sub initializeDeck()
- FileOpen(1, "Cardlist.txt", OpenMode.Input)
- Dim CardNumber As Integer = 0
- Do While Not EOF(1)
- Deck(CardNumber).filePath = LineInput(1)
- Deck(CardNumber).Available = 1
- CardNumber += 1
- Loop
- FileClose(1)
- CardNumber = 0
- For i = 0 To 51
- If i Mod 4 = 0 Then
- CardNumber += 1
- End If
- Deck(i).Number = CardNumber
- 'MsgBox(i & " " & i Mod 4 & " " & count & " " & Deck(i).Number)
- Select Case i Mod 4
- Case 0
- Deck(i).Suit = "Clubs"
- Case 1
- Deck(i).Suit = "Diamonds"
- Case 2
- Deck(i).Suit = "Hearts"
- Case 3
- Deck(i).Suit = "Spades"
- End Select
- Deck(i).Name = Deck(i).Number & " of " & Deck(i).Suit
- If Deck(i).Number = 1 Then
- Deck(i).Name = "Ace of " & Deck(i).Suit
- ElseIf Deck(i).Number = 11 Then
- Deck(i).Name = "Jack of " & Deck(i).Suit
- ElseIf Deck(i).Number = 12 Then
- Deck(i).Name = "Queen of " & Deck(i).Suit
- ElseIf Deck(i).Number = 13 Then
- Deck(i).Name = "King of " & Deck(i).Suit
- End If
- 'MsgBox(Deck(i).Name & " " & Deck(i).Available)
- Next
- End Sub
- Sub BettingRound(ByVal count As Integer)
- If players(0).hasFolded = False Then
- lastBetter = 0
- End If
- If flopPlayed = False Then
- progression = 0
- ElseIf flopPlayed = True And turnPlayed = False Then
- progression = 1
- ElseIf turnPlayed = True And riverPlayed = False Then
- progression = 2
- ElseIf riverPlayed = True Then
- progression = 3
- End If
- If moneyEntered((playerTurn + 1) Mod 4, progression) = 0 And progression = 0 Then
- actionChanger((playerTurn + 1) Mod 4, 5)
- actionChanger((playerTurn + 2) Mod 4, 10)
- moneyEntered((playerTurn + 1) Mod 4, progression) = 5
- moneyEntered((playerTurn + 2) Mod 4, progression) = 10
- players((playerTurn + 1) Mod 4).Money -= 5
- players((playerTurn + 2) Mod 4).Money -= 10
- refreshMoney()
- currentTurn = (currentTurn + 3) Mod 4
- End If
- If foldCount = 3 Then
- handOverSub()
- Exit Sub
- End If
- If currentTurn = 0 And players(0).hasFolded = False Then
- humanBet(progression, count)
- Else
- Dim count2 As Integer = 0
- 'MsgBox("t" & temp)
- While currentTurn <> 0 And foldCount <> 3
- If currentTurn > 3 Then
- currentTurn = 0
- Exit While
- End If
- 'MsgBox(currentTurn & " " & i)
- If players(currentTurn).hasFolded = True Then
- If players((currentTurn + 1) Mod 4).hasFolded = True Then
- currentTurn += 2
- Else
- currentTurn += 1
- End If
- End If
- If currentTurn > 3 Then
- currentTurn = currentTurn Mod 4
- Exit While
- End If
- If currentTurn = 4 Then
- currentTurn = 0
- Exit While
- End If
- If checkCount = 4 - foldCount Then
- Select Case progression
- Case 0
- Flop()
- Case 1
- Turn()
- Case 2
- River()
- Case 3
- handOverSub()
- End Select
- Exit Sub
- End If
- AIBet(players(currentTurn), currentTurn, progression, count)
- If currentTurn = 0 Then
- Exit Sub
- End If
- If handOverBool = True Then
- Exit Sub
- End If
- count += 1
- currentTurn += 1
- If playerTurn = 2 And progression = 0 And currentTurn = 4 Then
- Flop()
- Exit Sub
- End If
- If currentTurn = 4 Then
- currentTurn = 0
- Exit While
- End If
- If players(currentTurn).hasFolded = True Then
- If players((currentTurn + 1) Mod 4).hasFolded = True Then
- currentTurn += 2
- Else
- currentTurn += 1
- End If
- End If
- If currentTurn > 3 Then
- currentTurn = currentTurn Mod 4
- Exit While
- End If
- If moneyEntered(0, progression) = moneyEntered(1, progression) And moneyEntered(1, progression) = moneyEntered(2, progression) And moneyEntered(2, progression) = moneyEntered(3, progression) And isChecked = False And count <> 0 Then
- 'MsgBox("Progressing from Betting Round")
- Select Case progression
- Case 0
- Flop()
- Case 1
- Turn()
- Case 2
- River()
- Case 3
- handOverSub()
- End Select
- Exit Sub
- End If
- End While
- humanBet(progression, count)
- End If
- End Sub
- Sub humanBet(ByVal progression As Integer, ByVal count As Integer)
- If players(0).hasFolded = True Or players(0).Money = 0 Then
- currentTurn = 1
- BettingRound(1)
- Exit Sub
- End If
- If players(3).hasFolded = True Then
- If players(3).hasFolded = True And players(2).hasFolded = True Then
- lastBetter = 1
- Else
- lastBetter = 2
- End If
- Else
- lastBetter = 3
- End If
- 'MsgBox(lastBetter)
- If moneyEntered(0, progression) = moneyEntered(lastBetter, progression) And isChecked = False And count <> 0 Then
- Select Case progression
- Case 0
- Flop()
- Case 1
- Turn()
- Case 2
- River()
- Case 3
- handOverSub()
- End Select
- Exit Sub
- End If
- If checkCount = 4 - foldCount Then
- Select Case progression
- Case 0
- Flop()
- Case 1
- Turn()
- Case 2
- River()
- Case 3
- handOverSub()
- End Select
- Exit Sub
- End If
- FoldButton.Enabled = True
- If moneyEntered(0, progression) < moneyEntered(lastBetter, progression) Then
- CallButton.Enabled = True
- BetButton.Enabled = True
- CheckButton.Enabled = False
- isChecked = False
- ElseIf moneyEntered(0, progression) = moneyEntered(lastBetter, progression) Then
- CheckButton.Enabled = True
- CallButton.Enabled = False
- BetButton.Enabled = True
- End If
- End Sub
- Sub AIBet(ByRef player As Player, ByVal currentTurn As Integer, ByVal progression As Integer, ByVal count As Integer)
- FoldButton.Enabled = False
- BetButton.Enabled = False
- CheckButton.Enabled = False
- CallButton.Enabled = False
- lastBetter = currentTurn - 1
- If currentTurn <> 1 Then
- If players(currentTurn - 1).hasFolded = True Then
- If players(currentTurn - 2).hasFolded = True Then
- lastBetter = currentTurn - 3
- ElseIf players(currentTurn - 2).hasFolded = False Then
- lastBetter = currentTurn - 2
- End If
- Else
- lastBetter = currentTurn - 1
- End If
- ElseIf currentTurn = 1 Then
- If players(0).hasFolded = True Then
- If players(3).hasFolded = True Then
- lastBetter = 2
- ElseIf players(3).hasFolded = False Then
- lastBetter = 3
- End If
- Else
- lastBetter = 0
- End If
- End If
- If lastBetter = -1 Then
- lastBetter = 3
- End If
- 'MsgBox(lastBetter)
- 'MsgBox("Current Turn:" & currentTurn & Chr(13) & "Checked: " & isChecked & Chr(13) & "Money Entered: " & moneyEntered(currentTurn, progression) & Chr(13) & "Progression:" & progression & Chr(13) & "Last Better:" & lastBetter)
- If moneyEntered(lastBetter, progression) = moneyEntered(currentTurn, progression) And isChecked = False And count <> 0 Then
- Select Case progression
- Case 0
- Flop()
- Case 1
- Turn()
- Case 2
- River()
- Case 3
- handOverSub()
- End Select
- Exit Sub
- End If
- Threading.Thread.Sleep(1000)
- If progression = 0 And moneyEntered(currentTurn, 0) = 0 And moneyEntered(currentTurn - 1, 0) = 0 Then
- actionChanger(currentTurn, 10)
- moneyEntered(currentTurn, progression) = 10
- player.Money -= 10
- ElseIf progression = 0 Then
- actionChanger(currentTurn, (moneyEntered(currentTurn - 1, progression) - moneyEntered(currentTurn, progression)))
- Dim temp As Integer = moneyEntered(currentTurn, progression)
- moneyEntered(currentTurn, progression) = moneyEntered(currentTurn - 1, progression)
- player.Money -= (moneyEntered(currentTurn, progression) - temp)
- End If
- If progression <> 0 And players(currentTurn).hasFolded = False And players(currentTurn).Money > 0 Then
- player.handStrength = players(currentTurn).getHandStrength(player.currentHand, progression)
- Randomize()
- Dim bluffingInt As Integer = CInt(Math.Floor(4 * Rnd()))
- Dim bluffing As Boolean = False
- ' MsgBox("BI: " & bluffingInt)
- If bluffingInt = 0 Then
- bluffing = True
- End If
- 'MsgBox("CurrentTurn: " & currentTurn & Chr(13) & "Hand Strength: " & player.handStrength & Chr(13) & "BI: " & bluffingInt)
- Select Case player.handStrength
- Case "Very Weak"
- If isChecked = True And bluffing = False Then
- checkCount += 1
- actionChanger(currentTurn, "Check")
- ElseIf isChecked = True And bluffing = True Then
- moneyEntered(currentTurn, progression) += Math.Floor(player.Money / 15)
- actionChanger(currentTurn, Math.Floor(player.Money / 15))
- player.Money -= Math.Floor(player.Money / 15)
- isChecked = False
- ElseIf isChecked = False And bluffing = True And (moneyEntered(lastBetter, progression) - moneyEntered(currentTurn, progression)) <= Math.Floor(player.Money / 15) Then
- actionChanger(currentTurn, (moneyEntered(lastBetter, progression) - moneyEntered(currentTurn, progression)))
- player.Money -= (moneyEntered(lastBetter, progression) - moneyEntered(currentTurn, progression))
- moneyEntered(currentTurn, progression) = moneyEntered(lastBetter, progression)
- ElseIf isChecked = False Then
- player.hasFolded = True
- foldCount += 1
- actionChanger(currentTurn, "Fold")
- End If
- Case "Weak"
- If isChecked = True And bluffing = False Then
- checkCount += 1
- actionChanger(currentTurn, "Check")
- ElseIf isChecked = True And bluffing = True Then
- moneyEntered(currentTurn, progression) += Math.Floor(player.Money / 10)
- actionChanger(currentTurn, Math.Floor(player.Money / 10))
- player.Money -= Math.Floor(player.Money / 10)
- isChecked = False
- ElseIf isChecked = False And (moneyEntered(lastBetter, progression) - moneyEntered(currentTurn, progression)) <= Math.Floor(player.Money / 10) Then
- actionChanger(currentTurn, moneyEntered(lastBetter, progression) - moneyEntered(currentTurn, progression))
- player.Money -= (moneyEntered(lastBetter, progression) - moneyEntered(currentTurn, progression))
- moneyEntered(currentTurn, progression) = moneyEntered(lastBetter, progression)
- ElseIf isChecked = False Then
- player.hasFolded = True
- foldCount += 1
- actionChanger(currentTurn, "Fold")
- End If
- Case "Average"
- If isChecked = True And bluffing = False Then
- moneyEntered(currentTurn, progression) += 10
- player.Money -= 10
- isChecked = False
- actionChanger(currentTurn, 10)
- ElseIf isChecked = True And bluffing = True Then
- moneyEntered(currentTurn, progression) += Math.Floor(player.Money / 8)
- actionChanger(currentTurn, Math.Floor(player.Money / 8))
- player.Money -= Math.Floor(player.Money / 8)
- isChecked = False
- ElseIf isChecked = False And (moneyEntered(lastBetter, progression) - moneyEntered(currentTurn, progression)) <= Math.Floor(player.Money / 6) Then
- actionChanger(currentTurn, moneyEntered(lastBetter, progression) - moneyEntered(currentTurn, progression))
- player.Money -= (moneyEntered(lastBetter, progression) - moneyEntered(currentTurn, progression))
- moneyEntered(currentTurn, progression) = moneyEntered(lastBetter, progression)
- ElseIf isChecked = False Then
- player.hasFolded = True
- foldCount += 1
- actionChanger(currentTurn, "Fold")
- End If
- Case "Strong"
- If isChecked = True Then
- moneyEntered(currentTurn, progression) += Math.Floor(player.Money / 6)
- actionChanger(currentTurn, Math.Floor(player.Money / 6))
- player.Money -= Math.Floor(player.Money / 6)
- isChecked = False
- ElseIf isChecked = False And (moneyEntered(lastBetter, progression) - moneyEntered(currentTurn, progression)) <= Math.Floor(player.Money / 4) Then
- actionChanger(currentTurn, moneyEntered(lastBetter, progression) - moneyEntered(currentTurn, progression))
- player.Money -= (moneyEntered(lastBetter, progression) - moneyEntered(currentTurn, progression))
- moneyEntered(currentTurn, progression) = moneyEntered(lastBetter, progression)
- ElseIf isChecked = False Then
- player.hasFolded = True
- foldCount += 1
- actionChanger(currentTurn, "Fold")
- End If
- Case "Very Strong"
- If isChecked = True Then
- actionChanger(currentTurn, Math.Floor(player.Money / 2))
- moneyEntered(currentTurn, progression) += Math.Floor(player.Money / 2)
- player.Money -= Math.Floor(player.Money / 2)
- isChecked = False
- ElseIf isChecked = False Then
- actionChanger(currentTurn, moneyEntered(lastBetter, progression) - moneyEntered(currentTurn, progression))
- player.Money -= (moneyEntered(lastBetter, progression) - moneyEntered(currentTurn, progression))
- moneyEntered(currentTurn, progression) = (moneyEntered(lastBetter, progression))
- End If
- End Select
- refreshMoney()
- checkFoldedCards()
- End If
- If foldCount = 3 Then
- handOverSub()
- Exit Sub
- End If
- refreshMoney()
- If isChecked = False Then
- CheckButton.Enabled = False
- End If
- 'If currentTurn = 1 and progression > 0Then
- ' System.Threading.Thread.Sleep(20000)
- 'End If
- End Sub
- Sub actionChanger(ByVal currentTurnSub As Integer, ByVal action As String)
- Select Case currentTurnSub
- Case 1
- AI1Action.Text = action
- AI1Action.Refresh()
- Case 2
- AI2Action.Text = action
- AI2Action.Refresh()
- Case 3
- AI3Action.Text = action
- AI3Action.Refresh()
- Case 0
- HumanAction.Text = action
- HumanAction.Refresh()
- End Select
- End Sub
- Private Sub CallButton_Click(sender As Object, e As EventArgs) Handles CallButton.Click
- Dim lastBetter As Integer = 0
- 'MsgBox(currentTurn)
- If currentTurn = 0 Then
- Dim temp As Integer = moneyEntered(0, progression)
- If players(3).hasFolded = True Then
- If players(2).hasFolded = True Then
- lastBetter = 1
- Else
- lastBetter = 2
- End If
- Else
- lastBetter = 3
- End If
- 'MsgBox(moneyEntered(lastBetter, progression) & " " & temp & " " & players(0).Money)
- 'MsgBox((moneyEntered(lastBetter, progression) - temp))
- If (moneyEntered(lastBetter, progression) - temp) >= players(0).Money Then
- MsgBox("now")
- moneyEntered(0, progression) = players(0).Money
- actionChanger(0, players(0).Money)
- players(0).Money = 0
- Else
- moneyEntered(0, progression) = moneyEntered(lastBetter, progression)
- actionChanger(0, (moneyEntered(0, progression) - temp))
- players(0).Money -= (moneyEntered(0, progression) - temp)
- End If
- refreshMoney()
- currentTurn = 1
- BettingRound(1)
- End If
- End Sub
- Private Sub DealButton_Click(sender As Object, e As EventArgs) Handles DealButton.Click
- Deal()
- End Sub
- Private Sub CheckButton_Click(sender As Object, e As EventArgs) Handles CheckButton.Click
- currentTurn += 1
- checkCount += 1
- isChecked = True
- actionChanger(0, "Check")
- BettingRound(1)
- End Sub
- Private Sub BetButton_Click(sender As Object, e As EventArgs) Handles BetButton.Click
- If BetAmount.Text <> "" And IsNumeric(BetAmount.Text) = True Then
- If BetAmount.Text > 0 Then
- isChecked = False
- checkCount = 0
- If (players(0).Money - Convert.ToInt32(BetAmount.Text)) >= 0 Then
- actionChanger(0, BetAmount.Text)
- moneyEntered(0, progression) += Convert.ToInt32(BetAmount.Text)
- players(0).Money -= Convert.ToInt32(BetAmount.Text)
- refreshMoney()
- currentTurn += 1
- BettingRound(1)
- End If
- End If
- End If
- End Sub
- Private Sub FoldButton_Click(sender As Object, e As EventArgs) Handles FoldButton.Click
- players(0).hasFolded = True
- checkFoldedCards()
- currentTurn += 1
- foldCount += 1
- actionChanger(0, "Fold")
- BettingRound(1)
- End Sub
- Private Sub HandTableButton_Click(sender As Object, e As EventArgs) Handles HandTableButton.Click
- HandTableForm.Show()
- Dim sqlString3 As New Odbc.OdbcCommand("SELECT * FROM handtable ORDER BY HandNumber ASC", conn)
- conn.Open()
- rs = sqlString3.ExecuteReader()
- Do While rs.Read()
- Dim handWon As String
- If rs.Item("MoneyWon") > 0 Then
- handWon = "Yes"
- Else
- handWon = "No"
- End If
- HandTableForm.HandTableControl.Rows.Add(rs.Item("HandNumber"), rs.Item("Cards"), rs.Item("Hand"), handWon, rs.Item("MoneyEntered"), rs.Item("PotSize"), rs.Item("MoneyWon"), rs.Item("PercentageReturned"))
- Loop
- conn.Close()
- End Sub
- End Class
- Public Class Player
- Public Name As String
- Public Money As Integer
- Public hand() As Card
- Public currentHand As String
- Public handStrength As String
- Public hasFolded As Boolean
- Public Function getHandStrength(ByRef currentHand As String, ByRef progression As Integer)
- Dim factor1 As Integer
- Dim factor2 As Integer
- Select Case progression
- Case 1
- factor1 = 3
- Case 2
- factor1 = 9
- Case 3
- factor1 = 27
- End Select
- Select Case currentHand
- Case ""
- factor2 = 2
- Case "Pair"
- factor2 = 4
- Case "Two Pair"
- factor2 = 8
- Case "Three Of A Kind"
- factor2 = 16
- Case "Straight"
- factor2 = 32
- Case "Flush"
- factor2 = 64
- Case "Full House"
- factor2 = 128
- Case "Four Of A Kind"
- factor2 = 256
- End Select
- Select Case factor1 * factor2
- Case 6
- getHandStrength = "Weak"
- Case 12
- getHandStrength = "Average"
- Case 24
- getHandStrength = "Strong"
- Case 48
- getHandStrength = "Very Strong"
- Case 96
- getHandStrength = "Very Strong"
- Case 192
- getHandStrength = "Very Strong"
- Case 384
- getHandStrength = "Very Strong"
- Case 768
- getHandStrength = "Very Strong"
- Case 18
- getHandStrength = "Very Weak"
- Case 36
- getHandStrength = "Weak"
- Case 72
- getHandStrength = "Strong"
- Case 144
- getHandStrength = "Strong"
- Case 288
- getHandStrength = "Very Strong"
- Case 576
- getHandStrength = "Very Strong"
- Case 1152
- getHandStrength = "Very Strong"
- Case 2304
- getHandStrength = "Very Strong"
- Case 54
- getHandStrength = "Very Weak"
- Case 108
- getHandStrength = "Weak"
- Case 216
- getHandStrength = "Average"
- Case 432
- getHandStrength = "Strong"
- Case 864
- getHandStrength = "Strong"
- Case 1728
- getHandStrength = "Very Strong"
- Case 3456
- getHandStrength = "Very Strong"
- Case 6912
- getHandStrength = "Very Strong"
- End Select
- End Function
- End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement