Playing cards: Difference between revisions

Added BBC BASIC
(Added BBC BASIC)
Line 207:
AS 2S 3S 4S 5S 6S 7S 8S 9S TS JS QS KS AH 2H 3H 4H 5H 6H 7H 8H 9H TH JH QH KH AC
2C 3C 4C 5C 6C 7C 8C 9C TC JC QC KC AD 2D 3D 4D 5D 6D 7D 8D 9D TD JD QD KD
 
=={{header|BBC BASIC}}==
{{works with|BBC BASIC for Windows}}
<lang bbcbasic> DIM Deck{ncards%, card&(51)}, Suit$(3), Rank$(12)
Suit$() = "Clubs", "Diamonds", "Hearts", "Spades"
Rank$() = "Ace", "Two", "Three", "Four", "Five", "Six", "Seven", \
\ "Eight", "Nine", "Ten", "Jack", "Queen", "King"
PRINT "Creating a new deck..."
PROCnewdeck(deck1{})
PRINT "Shuffling the deck..."
PROCshuffle(deck1{})
PRINT "The first few cards are:"
FOR card% = 1 TO 8
PRINT FNcardname(deck1.card&(card%))
NEXT
PRINT "Dealing three cards from the deck:"
FOR card% = 1 TO 3
PRINT FNcardname(FNdeal(deck1{}))
NEXT
PRINT "Number of cards remaining in the deck = " ; deck1.ncards%
END
REM Make a new deck:
DEF PROCnewdeck(RETURN deck{})
LOCAL N%
DIM deck{} = Deck{}
FOR N% = 0 TO 51
deck.card&(N%) = N%
deck.ncards% += 1
NEXT
ENDPROC
REM Shuffle a deck:
DEF PROCshuffle(deck{})
LOCAL N%
FOR N% = 51 TO 1 STEP -1
SWAP deck.card&(N%), deck.card&(RND(N%)-1)
NEXT
ENDPROC
REM Deal from the 'bottom' of the deck:
DEF FNdeal(deck{})
IF deck.ncards% = 0 THEN ERROR 100, "Deck is empty"
deck.ncards% -= 1
= deck.card&(deck.ncards%)
REM Return the name of a card:
DEF FNcardname(card&)
= Rank$(card& >> 2) + " of " + Suit$(card& AND 3)</lang>
Output:
<pre>Creating a new deck...
Shuffling the deck...
The first few cards are:
King of Spades
Four of Diamonds
Six of Spades
Four of Clubs
Six of Diamonds
Jack of Clubs
Nine of Clubs
Ace of Clubs
Dealing three cards from the deck:
Three of Spades
Three of Diamonds
Four of Hearts
Number of cards remaining in the deck = 49</pre>
 
=={{header|C}}==