Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Option Explicit
- Sub handGood()
- ':TODO: Add decks, 0 for infinite
- Dim player As Integer 'Player hand total
- Dim bank As Integer 'Bank Hand total
- Dim cards As Integer 'Card Counter
- Dim card As Integer 'Card Value 0-51
- Dim cardRank As Integer 'Card rank 1 - 13
- Dim cardSuit As Integer 'Card suit 0 - 3
- Dim blk8 As Long 'Count of black eights in winning hands
- Dim has8 As Integer 'Which hand has black 8 1 = Player, 2 = Bank, 3 = Both
- Dim pwin As Long 'Player Win Count
- Dim bwin As Long 'Banker Win Count
- Dim ties As Long 'Tie count
- Dim trials As Long 'Trials to run
- Dim bBDraw As Boolean 'Should the bank draw a card?
- Randomize
- For trials = 1 To 100000000
- has8 = 0 'Reset
- player = 0
- bank = 0
- bBDraw = False
- 'Deal 4 cards, card 1 & 2 to the player, 3 & 4 to the banker
- For cards = 1 To 4
- 'Draw a random card, 0 - 52
- card = Int((51 + 1) * Rnd)
- cardRank = (card Mod 13) + 1
- cardSuit = Int(card / 13)
- 'Check for black 8. Suits are 0-3, so we'll say if it's suit 0 or 1
- If cardRank = 8 And cardSuit < 2 Then
- If cards < 3 Then 'Player card
- has8 = 1
- ElseIf has8 = 1 And cards > 2 Then 'Banker card and player already has a black 8
- has8 = 3
- Else 'Just banker, player didn't get a black 8
- has8 = 2
- End If
- End If
- If cards < 3 Then 'Player
- If cardRank < 10 Then 'Only bother adding if the card is a 9 or less
- player = (player + cardRank) Mod 10 'Mod 10 to get bacc total
- End If
- Else 'Banker, same idea as player
- If cardRank < 10 Then
- bank = (bank + cardRank) Mod 10
- End If
- End If
- Next cards
- 'Player draw
- If player >= 8 Or bank >= 8 Then
- 'Natural, do nothing :LAZY CODING:
- ElseIf player <= 5 Then
- 'Player draws when total < 6.
- card = Int((51 - 0 + 1) * Rnd + 0)
- cardRank = (card Mod 13) + 1
- cardSuit = Int(card / 13)
- If cardRank < 10 Then
- player = (player + cardRank) Mod 10
- End If
- 'Is the card drawn for the player a black 8?
- If cardRank = 8 And cardSuit < 2 Then
- If has8 = 0 Then
- has8 = 1
- ElseIf has8 = 2 Then
- has8 = 3
- End If
- End If
- 'Since the player drew, we need to use banker third card rules
- 'Note that the variable "card" still contains the player's 3rd card
- Select Case bank
- Case Is < 3
- 'Always draw for total of 0, 1, 2, regardless of player 3rd card
- bBDraw = True
- Case 3
- If cardRank <> 8 Then
- 'Draw against anything but 8
- bBDraw = True
- End If
- Case 4
- If cardRank >= 2 And cardRank <= 7 Then
- 'Draw against 2-7
- bBDraw = True
- End If
- Case 5
- If cardRank >= 4 And cardRank <= 7 Then
- 'Draw against 4-7
- bBDraw = True
- End If
- Case 6
- If cardRank >= 6 And cardRank <= 7 Then
- 'Draw against 6-7
- bBDraw = True
- End If
- End Select
- ElseIf bank <= 5 Then
- 'No player draw; banker draws according to player rules
- If bank <= 5 Then
- bBDraw = True
- End If
- End If
- 'Draw for banker if necessary
- If bBDraw Then
- card = Int((51 - 0 + 1) * Rnd + 0)
- cardRank = (card Mod 13) + 1
- cardSuit = Int(card / 13)
- If cardRank < 10 Then
- bank = (bank + cardRank) Mod 10
- End If
- 'Did the bank draw a black 8?
- If cardRank = 8 And cardSuit < 2 Then
- If has8 = 0 Then
- has8 = 2
- ElseIf has8 = 1 Then
- has8 = 3
- End If
- End If
- End If
- 'Compare bank and player
- If bank > player Then
- bwin = bwin + 1
- If has8 = 2 Or has8 = 3 Then
- blk8 = blk8 + 1
- End If
- ElseIf player > bank Then
- pwin = pwin + 1
- If has8 = 1 Or has8 = 3 Then
- blk8 = blk8 + 1
- End If
- Else
- ties = ties + 1
- End If
- Next trials
- 'Show results
- Debug.Print "Player Wins: " & pwin & " Banker Wins: " & bwin & " Ties: " & ties
- Debug.Print "Black 8's in Winning Hands: " & blk8
- End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement