Advertisement
Guest User

BlackJack_Shuffle_DealCard

a guest
Dec 11th, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.11 KB | None | 0 0
  1. ' Shuffle deck of Cards with simple one-pass algorithm
  2. Public Sub Shuffle()
  3. ' after shuffling, dealing should start at deck(0)
  4. currentCard = 0 ' reinitialize currentCard
  5.  
  6. ' for each Card, pick another random Card and swap them
  7. For first = 0 To deck.GetUpperBound(0)
  8. ' select a random number between 0 and 51
  9. Dim second As Integer = randomNumbers.Next(NUMBER_OF_CARDS)
  10.  
  11. ' swap current Card with randomly selected Card
  12. Dim temp As Card = deck(first) ' store copy of deck(first)
  13. deck(first) = deck(second) ' move deck(second) to deck(first)
  14. deck(second) - temp ' move original deck(first) to deck(second)
  15. Next
  16. End Sub ' Shuffle
  17.  
  18. ' deal one card
  19. Public Function DealCard() As Card
  20. ' determine whether Cards remain to be dealt
  21. If current Card <= deck.GetUpperBound(0) Then
  22. Dim last Card As Integer = currentCard ' store current card number
  23. currentCard += 1 ' increment current card number
  24. Return deck(lastCard)
  25. Else
  26. Return Nothing ' no more cards to deal
  27. End If
  28. End Function ' Deal Card
  29. End Class ' DeckOfCards
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement