93 lines
2.1 KiB
Plaintext
93 lines
2.1 KiB
Plaintext
Dim deckCards(52)
|
|
Dim holdCards(1, 1)
|
|
Print "The Sorted Deck"
|
|
Call sortDeck
|
|
Call dealDeck
|
|
Print: Print
|
|
Print "The Shuffled Deck"
|
|
Call shuffleDeck
|
|
Call dealDeck
|
|
Print: Print
|
|
nPlayers = 4
|
|
nCards = 5
|
|
ct = 0
|
|
Redim holdCards(nPlayers, nCards)
|
|
Print "Dealing ";nCards;" cards to ";nPlayers;" players"
|
|
For i = 1 to nPlayers
|
|
Print "Player #";i,,
|
|
Next i
|
|
Print
|
|
For i = 1 to nCards
|
|
For j = 1 to nPlayers
|
|
ct = ct + 1
|
|
holdCards(j, i) = deckCards(ct)
|
|
card = deckCards(ct)
|
|
value = value(card)
|
|
suit$ = suit$(card)
|
|
pip$ = pip$(value)
|
|
Print card;": ";pip$;" of ";suit$,
|
|
Next j
|
|
Print
|
|
Next i
|
|
Print: Print
|
|
Print "The cards in memory / array"
|
|
For i = 1 to nPlayers
|
|
Print "Player #";i;" is holding"
|
|
For j = 1 to nCards
|
|
card = holdCards(i, j)
|
|
value = value(card)
|
|
suit$ = suit$(card)
|
|
pip$ = pip$(value)
|
|
Print card;": ";pip$;" of ";suit$
|
|
Next j
|
|
Print
|
|
Next i
|
|
|
|
End
|
|
|
|
Sub dealDeck
|
|
For i = 1 to 52
|
|
card = deckCards(i)
|
|
value = value(card)
|
|
suit$ = suit$(card)
|
|
pip$ = pip$(value)
|
|
Print i, card, value, pip$;" of ";suit$
|
|
Next i
|
|
End Sub
|
|
|
|
Sub sortDeck
|
|
For i = 1 to 52
|
|
deckCards(i) = i
|
|
Next i
|
|
End Sub
|
|
|
|
Sub shuffleDeck
|
|
For i = 52 to 1 Step -1
|
|
x = Int(Rnd(1) * i) + 1
|
|
temp = deckCards(x)
|
|
deckCards(x) = deckCards(i)
|
|
deckCards(i) = temp
|
|
Next i
|
|
End Sub
|
|
|
|
Function suit$(deckValue)
|
|
cardSuit$ = "Spades Hearts Clubs Diamonds"
|
|
suit = Int(deckValue / 13)
|
|
If deckValue Mod 13 = 0 Then
|
|
suit = suit - 1
|
|
End If
|
|
suit$ = Word$(cardSuit$, suit + 1)
|
|
End Function
|
|
|
|
Function value(deckValue)
|
|
value = deckValue Mod 13
|
|
If value = 0 Then
|
|
value = 13
|
|
End If
|
|
End Function
|
|
|
|
Function pip$(faceValue)
|
|
pipLabel$ = "Ace Deuce Three Four Five Six Seven Eight Nine Ten Jack Queen King"
|
|
pip$ = Word$(pipLabel$, faceValue)
|
|
End Function
|