Advertisement
Guest User

Black 8 Bacc 100 Million Sim

a guest
Feb 24th, 2012
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. Option Explicit
  3.  
  4. Sub handGood()
  5.     ':TODO: Add decks, 0 for infinite
  6.    Dim player As Integer   'Player hand total
  7.    Dim bank As Integer     'Bank Hand total
  8.    Dim cards As Integer    'Card Counter
  9.    Dim card As Integer     'Card Value 0-51
  10.    Dim cardRank As Integer 'Card rank 1 - 13
  11.    Dim cardSuit As Integer 'Card suit 0 - 3
  12.    Dim blk8 As Long        'Count of black eights in winning hands
  13.    Dim has8 As Integer     'Which hand has black 8 1 = Player, 2 = Bank, 3 = Both
  14.    Dim pwin As Long        'Player Win Count
  15.    Dim bwin As Long        'Banker Win Count
  16.    Dim ties As Long        'Tie count
  17.    Dim trials As Long      'Trials to run
  18.    Dim bBDraw As Boolean   'Should the bank draw a card?
  19.    
  20.     Randomize
  21.    
  22.     For trials = 1 To 100000000
  23.         has8 = 0 'Reset
  24.        player = 0
  25.         bank = 0
  26.         bBDraw = False
  27.        
  28.         'Deal 4 cards, card 1 & 2 to the player, 3 & 4 to the banker
  29.        For cards = 1 To 4
  30.             'Draw a random card, 0 - 52
  31.            card = Int((51 + 1) * Rnd)
  32.             cardRank = (card Mod 13) + 1
  33.             cardSuit = Int(card / 13)
  34.            
  35.             'Check for black 8.  Suits are 0-3, so we'll say if it's suit 0 or 1
  36.            If cardRank = 8 And cardSuit < 2 Then
  37.                 If cards < 3 Then 'Player card
  38.                    has8 = 1
  39.                 ElseIf has8 = 1 And cards > 2 Then 'Banker card and player already has a black 8
  40.                    has8 = 3
  41.                 Else 'Just banker, player didn't get a black 8
  42.                    has8 = 2
  43.                 End If
  44.             End If
  45.            
  46.             If cards < 3 Then 'Player
  47.                If cardRank < 10 Then 'Only bother adding if the card is a 9 or less
  48.                    player = (player + cardRank) Mod 10 'Mod 10 to get bacc total
  49.                End If
  50.             Else 'Banker, same idea as player
  51.                If cardRank < 10 Then
  52.                     bank = (bank + cardRank) Mod 10
  53.                 End If
  54.             End If
  55.         Next cards
  56.        
  57.         'Player draw
  58.        If player >= 8 Or bank >= 8 Then
  59.             'Natural, do nothing :LAZY CODING:
  60.        ElseIf player <= 5 Then
  61.             'Player draws when total < 6.
  62.            card = Int((51 - 0 + 1) * Rnd + 0)
  63.             cardRank = (card Mod 13) + 1
  64.             cardSuit = Int(card / 13)
  65.             If cardRank < 10 Then
  66.                 player = (player + cardRank) Mod 10
  67.             End If
  68.            
  69.             'Is the card drawn for the player a black 8?
  70.            If cardRank = 8 And cardSuit < 2 Then
  71.                 If has8 = 0 Then
  72.                     has8 = 1
  73.                 ElseIf has8 = 2 Then
  74.                     has8 = 3
  75.                 End If
  76.             End If
  77.            
  78.             'Since the player drew, we need to use banker third card rules
  79.            'Note that the variable "card" still contains the player's 3rd card
  80.            Select Case bank
  81.                 Case Is < 3
  82.                     'Always draw for total of 0, 1, 2, regardless of player 3rd card
  83.                    bBDraw = True
  84.                 Case 3
  85.                     If cardRank <> 8 Then
  86.                         'Draw against anything but 8
  87.                        bBDraw = True
  88.                     End If
  89.                 Case 4
  90.                     If cardRank >= 2 And cardRank <= 7 Then
  91.                         'Draw against 2-7
  92.                        bBDraw = True
  93.                     End If
  94.                 Case 5
  95.                     If cardRank >= 4 And cardRank <= 7 Then
  96.                         'Draw against 4-7
  97.                        bBDraw = True
  98.                     End If
  99.                 Case 6
  100.                     If cardRank >= 6 And cardRank <= 7 Then
  101.                         'Draw against 6-7
  102.                        bBDraw = True
  103.                     End If
  104.             End Select
  105.         ElseIf bank <= 5 Then
  106.             'No player draw; banker draws according to player rules
  107.            If bank <= 5 Then
  108.                 bBDraw = True
  109.             End If
  110.         End If
  111.        
  112.         'Draw for banker if necessary
  113.        If bBDraw Then
  114.             card = Int((51 - 0 + 1) * Rnd + 0)
  115.             cardRank = (card Mod 13) + 1
  116.             cardSuit = Int(card / 13)
  117.             If cardRank < 10 Then
  118.                 bank = (bank + cardRank) Mod 10
  119.             End If
  120.            
  121.             'Did the bank draw a black 8?
  122.            If cardRank = 8 And cardSuit < 2 Then
  123.                 If has8 = 0 Then
  124.                     has8 = 2
  125.                 ElseIf has8 = 1 Then
  126.                     has8 = 3
  127.                 End If
  128.             End If
  129.         End If
  130.        
  131.         'Compare bank and player
  132.        If bank > player Then
  133.             bwin = bwin + 1
  134.             If has8 = 2 Or has8 = 3 Then
  135.                 blk8 = blk8 + 1
  136.             End If
  137.         ElseIf player > bank Then
  138.             pwin = pwin + 1
  139.             If has8 = 1 Or has8 = 3 Then
  140.                 blk8 = blk8 + 1
  141.             End If
  142.         Else
  143.             ties = ties + 1
  144.         End If
  145.     Next trials
  146.    
  147.     'Show results
  148.    Debug.Print "Player Wins: " & pwin & " Banker Wins: " & bwin & " Ties: " & ties
  149.     Debug.Print "Black 8's in Winning Hands: " & blk8
  150. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement